Skip to content

Instantly share code, notes, and snippets.

@larskuhtz
Last active August 18, 2022 09:55
Show Gist options
  • Save larskuhtz/424c20f1a723a637dd43093d7c1d5ed6 to your computer and use it in GitHub Desktop.
Save larskuhtz/424c20f1a723a637dd43093d7c1d5ed6 to your computer and use it in GitHub Desktop.
jq config file for working with Kadena chainweb payloads
# ############################################################################ #
# Base64 URL without padding
def base64dUrl: .
| gsub("(?<x>[-_])"; if .x == "-" then "+" else "/" end)
| "\(.)==="
| @base64d
;
def fromjson64: .
| base64dUrl
| fromjson
;
# ############################################################################ #
# Chainweb Debugging tools
def pWo: .
| .minerData = (.minerData | fromjson64)
| .coinbase = (.coinbase | fromjson64)
| .transactions =
[ .transactions[]
|
{ tx: (.[0] | fromjson64 | .cmd = (.cmd | fromjson))
, result: (.[1] | fromjson64)
}
]
;
# ############################################################################ #
# RocksDb Paylaods
#
# keys: ["transactionsHash","minerData","transaction"]
# pk: "transactionsHash"
#
def blockTransactions2json: .
| .transactionsHash = .transactionHash
| del(.transactionHash)
| .minerData = (.minerData | fromjson64)
| .transaction = [.transaction[] | fromjson64]
;
def blockTransactionsCmd2json: .
| .transactionsHash = .transactionHash
| del(.transactionHash)
| .minerData = (.minerData | fromjson64)
| .transaction = [.transaction[] | fromjson64]
| .transaction =
[ .transaction[]
| .cmd = (.cmd | fromjson)
]
;
#
# keys: ["coinbaseOutput","outputs","outputsHash"]
# pk: "outputsHash"
#
def blockOutputs2json: .
| .coinbaseOutput = (.coinbaseOutput | fromjson64)
| .outputs = [.outputs[] | fromjson64]
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment