Skip to content

Commit

Permalink
Document PaimaParser.Json() helper (#46)
Browse files Browse the repository at this point in the history
* Use PaimaParser.Json helper where it's useful

* Add Json() to the description of PaimaParser

* Whitespace
  • Loading branch information
SpaceManiac authored Jun 13, 2024
1 parent 96a5cc5 commit ea80539
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
3 changes: 2 additions & 1 deletion docs/home/200-read-write-L2-state/1-base-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const createdLobby: ParserRecord<CreatedLobbyInput> = {
};
```

Note Paima comes with a `PaimaParser`utility that includes many of the common parsing utility functions you need
Note Paima comes with a `PaimaParser` utility that includes many of the common parsing utility functions you need:
```typescript showLineNumbers
// alternate-color-start
ArrayParser(iter: { perItemParser: ParserCommandExec })
Expand All @@ -80,6 +80,7 @@ RegexParser(regex: RegExp)
HexParser()
WalletAddress()
EnumParser(values: readonly string[], transform?: (value: string) => string)
Json()
// alternate-color-end
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Note: this primitive only gets triggered a single time per transaction (even if
extensions:
- name: "CardanoTransfer"
type: cardano-transfer
credential: 8200581c55edc34de172a4a3ba9cac51f041187c84478d68e788dd6cf6f0b3d9
credential: 8200581c55edc34de172a4a3ba9cac51f041187c84478d68e788dd6cf6f0b3d9
startSlot: 12472120
stopSlot: 12500000
scheduledPrefix: ct
Expand Down Expand Up @@ -49,9 +49,7 @@ const cardanoTransfer: ParserRecord<CardanoTransfer> = {
inputCredentials: PaimaParser.ArrayParser({
item: PaimaParser.RegexParser(/[a-f0-9]*/),
}),
outputs: (keyName: string, input: string) => {
return JSON.parse(input);
},
outputs: PaimaParser.Json(),
};
interface CardanoTransfer {
Expand Down Expand Up @@ -85,4 +83,4 @@ Therefore, although we provide access to the list of `inputCredentials`, if poss

Additionally, in cases where there are multiple outputs in the same transaction that trigger this primitive, we only trigger this primitive once. It is up to the app if it wants to aggregate multiple output values as a single payment, or keep them separated (possibly with a metadata hint about which address gets credited how much).

Also be careful: it's possible the credential you track appears neither in the input or the output. This happens because this primitive triggers whenever the transaction contains the credential as a witness, but witnesses are not limited to just inputs and are used for other features (ex: certificates) and as well as may be entirely extraneous (you can add more witnesses than actually needed).
Also be careful: it's possible the credential you track appears neither in the input or the output. This happens because this primitive triggers whenever the transaction contains the credential as a witness, but witnesses are not limited to just inputs and are used for other features (ex: certificates) and as well as may be entirely extraneous (you can add more witnesses than actually needed).
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

Tracks all the instances of a mint or burn of set of policy IDs.

If you're looking to track these assets after they've been minted, use the [delayed state](./20-delayed-state.md) primitive.
If you're looking to track these assets after they've been minted, use the [delayed state](./20-delayed-state.md) primitive.

### Example

```yaml
extensions:
- name: "CARDANO-MINT-BURN"
type: cardano-mint-burn
policyIds:
policyIds:
- "0fc891fb7368d3b7c7b88815c203fda0d6862b0f1d797222672e91fe"
- "0fc891fb7368d3b7c7b88815c203fda0d6862b0f1d797222672e91ff"
startSlot: 722300
stopSlot: 733216
scheduledPrefix: cmb
network: CardanoNetworkConfigEntryName
```
```
### Meaning
Expand All @@ -39,9 +39,7 @@ It can be parsed with a rule of the form:
const cardanoMint: ParserRecord<CardanoMint> = {
txId: PaimaParser.NCharsParser(0, 64),
metadata: PaimaParser.OptionalParser(null, PaimaParser.RegexParser(/[a-f0-9]*/)),
assets: (keyName: string, input: string) => {
return JSON.parse(input);
},
assets: PaimaParser.Json(),
};
interface AssetAmount {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,11 @@ minaGenericAction = mga|data

```ts
const minaGenericEvent: ParserRecord<MinaGenericEvent> = {
data: (keyName: string, input: string) => {
return JSON.parse(input);
},
data: PaimaParser.Json(),
};

const minaGenericAction: ParserRecord<MinaGenericAction> = {
data: (keyName: string, input: string) => {
return JSON.parse(input);
},
data: PaimaParser.Json(),
};
```

0 comments on commit ea80539

Please sign in to comment.