diff --git a/abi-tolk/mapper.go b/abi-tolk/mapper.go new file mode 100644 index 00000000..2e6dc547 --- /dev/null +++ b/abi-tolk/mapper.go @@ -0,0 +1,19 @@ +package abi_tolk + +import ( + "github.com/tonkeeper/tongo/abi" + "github.com/tonkeeper/tongo/tolk/parser" + + _ "embed" +) + +//go:embed schemas/jetton_minter.json +var jettonMinterABI []byte + +//go:embed schemas/jetton_wallet.json +var jettonWalletABI []byte + +var InterfaceToABI = map[abi.ContractInterface]parser.ABI{ + abi.JettonMaster: parser.MustParseABI(jettonMinterABI), + abi.JettonWallet: parser.MustParseABI(jettonWalletABI), +} diff --git a/abi-tolk/schemas/jetton_minter.json b/abi-tolk/schemas/jetton_minter.json new file mode 100644 index 00000000..e3e83505 --- /dev/null +++ b/abi-tolk/schemas/jetton_minter.json @@ -0,0 +1,642 @@ +{ + "contractName": "JettonMinter", + "namespace": "ton.tep74", + "declarations": [ + { + "kind": "Struct", + "name": "WalletStorage", + "fields": [ + { + "name": "jettonBalance", + "ty": { + "kind": "coins" + } + }, + { + "name": "ownerAddress", + "ty": { + "kind": "address" + } + }, + { + "name": "minterAddress", + "ty": { + "kind": "address" + } + } + ] + }, + { + "kind": "Struct", + "name": "MinterStorage", + "fields": [ + { + "name": "totalSupply", + "ty": { + "kind": "coins" + } + }, + { + "name": "adminAddress", + "ty": { + "kind": "address" + } + }, + { + "name": "content", + "ty": { + "kind": "cell" + } + }, + { + "name": "jettonWalletCode", + "ty": { + "kind": "cell" + } + } + ] + }, + { + "kind": "Alias", + "name": "ForwardPayloadRemainder", + "targetTy": { + "kind": "remaining" + } + }, + { + "kind": "Struct", + "name": "AskToTransfer", + "prefix": { + "prefixStr": "0x0f8a7ea5", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "transferRecipient", + "ty": { + "kind": "address" + } + }, + { + "name": "sendExcessesTo", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "customPayload", + "isPayload": true, + "ty": { + "kind": "nullable", + "inner": { + "kind": "cell" + } + } + }, + { + "name": "forwardTonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "forwardPayload", + "isPayload": true, + "ty": { + "kind": "AliasRef", + "aliasName": "ForwardPayloadRemainder" + } + } + ] + }, + { + "kind": "Struct", + "name": "TransferNotificationForRecipient", + "prefix": { + "prefixStr": "0x7362d09c", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "transferInitiator", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "forwardPayload", + "isPayload": true, + "ty": { + "kind": "AliasRef", + "aliasName": "ForwardPayloadRemainder" + } + } + ] + }, + { + "kind": "Struct", + "name": "InternalTransferStep", + "prefix": { + "prefixStr": "0x178d4519", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "transferInitiator", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "sendExcessesTo", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "forwardTonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "forwardPayload", + "isPayload": true, + "ty": { + "kind": "AliasRef", + "aliasName": "ForwardPayloadRemainder" + } + } + ] + }, + { + "kind": "Struct", + "name": "ReturnExcessesBack", + "prefix": { + "prefixStr": "0xd53276db", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + } + ] + }, + { + "kind": "Struct", + "name": "AskToBurn", + "prefix": { + "prefixStr": "0x595f07bc", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "sendExcessesTo", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "customPayload", + "ty": { + "kind": "nullable", + "inner": { + "kind": "cell" + } + } + } + ] + }, + { + "kind": "Struct", + "name": "BurnNotificationForMinter", + "prefix": { + "prefixStr": "0x7bdd97de", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "burnInitiator", + "ty": { + "kind": "address" + } + }, + { + "name": "sendExcessesTo", + "ty": { + "kind": "addressOpt" + } + } + ] + }, + { + "kind": "Struct", + "name": "RequestWalletAddress", + "prefix": { + "prefixStr": "0x2c76b973", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "ownerAddress", + "ty": { + "kind": "address" + } + }, + { + "name": "includeOwnerAddress", + "ty": { + "kind": "bool" + } + } + ] + }, + { + "kind": "Struct", + "name": "ResponseWalletAddress", + "prefix": { + "prefixStr": "0xd1735400", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonWalletAddress", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "ownerAddress", + "ty": { + "kind": "nullable", + "inner": { + "kind": "cellOf", + "inner": { + "kind": "address" + } + } + } + } + ] + }, + { + "kind": "Struct", + "name": "MintNewJettons", + "prefix": { + "prefixStr": "0x00000015", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "mintRecipient", + "ty": { + "kind": "address" + } + }, + { + "name": "tonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "internalTransferMsg", + "ty": { + "kind": "cellOf", + "inner": { + "kind": "StructRef", + "structName": "InternalTransferStep" + } + } + } + ] + }, + { + "kind": "Struct", + "name": "ChangeMinterAdmin", + "prefix": { + "prefixStr": "0x00000003", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "newAdminAddress", + "ty": { + "kind": "address" + } + } + ] + }, + { + "kind": "Struct", + "name": "ChangeMinterContent", + "prefix": { + "prefixStr": "0x00000004", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "newContent", + "ty": { + "kind": "cell" + } + } + ] + }, + { + "kind": "Alias", + "name": "AllowedMessageToMinter", + "targetTy": { + "kind": "union", + "variants": [ + { + "variantTy": { + "kind": "StructRef", + "structName": "MintNewJettons" + }, + "prefixStr": "0x00000015", + "prefixLen": 32 + }, + { + "variantTy": { + "kind": "StructRef", + "structName": "BurnNotificationForMinter" + }, + "prefixStr": "0x7bdd97de", + "prefixLen": 32 + }, + { + "variantTy": { + "kind": "StructRef", + "structName": "RequestWalletAddress" + }, + "prefixStr": "0x2c76b973", + "prefixLen": 32 + }, + { + "variantTy": { + "kind": "StructRef", + "structName": "ChangeMinterAdmin" + }, + "prefixStr": "0x00000003", + "prefixLen": 32 + }, + { + "variantTy": { + "kind": "StructRef", + "structName": "ChangeMinterContent" + }, + "prefixStr": "0x00000004", + "prefixLen": 32 + } + ] + } + }, + { + "kind": "Struct", + "name": "JettonDataReply", + "fields": [ + { + "name": "totalSupply", + "ty": { + "kind": "int" + } + }, + { + "name": "mintable", + "ty": { + "kind": "bool" + } + }, + { + "name": "adminAddress", + "ty": { + "kind": "address" + } + }, + { + "name": "jettonContent", + "ty": { + "kind": "cell" + } + }, + { + "name": "jettonWalletCode", + "ty": { + "kind": "cell" + } + } + ] + } + ], + "incomingMessages": [ + { + "bodyTy": { + "kind": "StructRef", + "structName": "MintNewJettons" + } + }, + { + "bodyTy": { + "kind": "StructRef", + "structName": "BurnNotificationForMinter" + } + }, + { + "bodyTy": { + "kind": "StructRef", + "structName": "RequestWalletAddress" + } + }, + { + "bodyTy": { + "kind": "StructRef", + "structName": "ChangeMinterAdmin" + } + }, + { + "bodyTy": { + "kind": "StructRef", + "structName": "ChangeMinterContent" + } + } + ], + "outgoingMessages": [ + { + "bodyTy": { + "kind": "StructRef", + "structName": "ReturnExcessesBack" + } + }, + { + "bodyTy": { + "kind": "StructRef", + "structName": "ResponseWalletAddress" + } + }, + { + "bodyTy": { + "kind": "StructRef", + "structName": "InternalTransferStep" + } + } + ], + "emittedEvents": [], + "storage": { + "storageTy": { + "kind": "StructRef", + "structName": "MinterStorage" + } + }, + "getMethods": [ + { + "tvmMethodId": 106029, + "name": "get_jetton_data", + "parameters": [], + "returnTy": { + "kind": "StructRef", + "structName": "JettonDataReply" + } + }, + { + "tvmMethodId": 103289, + "name": "get_wallet_address", + "parameters": [ + { + "name": "ownerAddress", + "ty": { + "kind": "address" + } + } + ], + "returnTy": { + "kind": "address" + } + } + ], + "thrownErrors": [ + { + "constName": "ERR_NOT_FROM_ADMIN", + "errCode": 73 + }, + { + "constName": "ERR_UNAUTHORIZED_BURN", + "errCode": 74 + }, + { + "constName": "ERR_NOT_ENOUGH_AMOUNT_TO_RESPOND", + "errCode": 75 + }, + { + "constName": "", + "errCode": 65535 + } + ], + "compilerName": "tolk", + "compilerVersion": "1.2.0", + "codeBoc64": "te6ccgECDAEAAioAART/APSkE/S88sgLAQIBYgIDAvjQ+JHyQCDXLCPe7L70jmMx7UTQAdM/+gD6SPpQMAT6ACDUMddM+JL4KMjPhCAW+lIV+lLJAcjPhNDMzPkWyM+KAEDL/89QE8cF8uBKWKHIAfoCzsntVCFukVvgyM+FCBL6UoIQ1TJ2288Ljss/yYBC+wDg1ywhY7XLnOMCBAUCA3pgCgsA5jH4l/iTcPg6ggiYloCgvPLgS9M/+kjXCgCVIMj6UsmRbeJtIvpEMMAAjigw7UTQ1DHXTPgoyM+EIBT6UhP6UslYyM+E0MzM+RbIz4oAQMv/z1ABkTLi+JLIz4WI+lKCENFzVADPC44Tyz/6VPQAyYBA+wAE+onXJ45rMe1E0PoAIPpI1DHXTPiSWMcF8uBJA9M/MfpI+gDXTCDQ1ywgvGoozPK/0z8x+gAwFaDIAfoCE87J7VT4KMjPhCAS+lL6UsnIz4mIAVMUyM+E0MzM+RbPC/9Y+gKBAI3PC3ATzBLMzMlx+wDg1ywgAAAAHOMCidcnBgcICQAIAAAAFQBCMe1E0PoA+kj4kljHBfLgSQLTPzH6SDDIWPoC+lLOye1UAAgAAAAEAFiOITHtRND6APpI1DH4kiLHBfLgSQPXTMhQA/oC+lLMzsntVOAwhA8BxwDy9ABRrbz2omhqGOumfBRkZ8IQCf0pCX0pZIDkZ8JoZmZ8i2RnxQAgZf/nqEAAH68W9qJofQB9JGprpj+qkEA=" +} \ No newline at end of file diff --git a/abi-tolk/schemas/jetton_wallet.json b/abi-tolk/schemas/jetton_wallet.json new file mode 100644 index 00000000..36224cb9 --- /dev/null +++ b/abi-tolk/schemas/jetton_wallet.json @@ -0,0 +1,636 @@ +{ + "contractName": "JettonWallet", + "declarations": [ + { + "kind": "Struct", + "name": "WalletStorage", + "fields": [ + { + "name": "jettonBalance", + "ty": { + "kind": "coins" + } + }, + { + "name": "ownerAddress", + "ty": { + "kind": "address" + } + }, + { + "name": "minterAddress", + "ty": { + "kind": "address" + } + } + ] + }, + { + "kind": "Struct", + "name": "MinterStorage", + "fields": [ + { + "name": "totalSupply", + "ty": { + "kind": "coins" + } + }, + { + "name": "adminAddress", + "ty": { + "kind": "address" + } + }, + { + "name": "content", + "ty": { + "kind": "cell" + } + }, + { + "name": "jettonWalletCode", + "ty": { + "kind": "cell" + } + } + ] + }, + { + "kind": "Alias", + "name": "ForwardPayloadRemainder", + "targetTy": { + "kind": "remaining" + } + }, + { + "kind": "Struct", + "name": "AskToTransfer", + "prefix": { + "prefixStr": "0x0f8a7ea5", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "transferRecipient", + "ty": { + "kind": "address" + } + }, + { + "name": "sendExcessesTo", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "customPayload", + "isPayload": true, + "ty": { + "kind": "nullable", + "inner": { + "kind": "cell" + } + } + }, + { + "name": "forwardTonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "forwardPayload", + "isPayload": true, + "ty": { + "kind": "AliasRef", + "aliasName": "ForwardPayloadRemainder" + } + } + ] + }, + { + "kind": "Struct", + "name": "TransferNotificationForRecipient", + "prefix": { + "prefixStr": "0x7362d09c", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "transferInitiator", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "forwardPayload", + "isPayload": true, + "ty": { + "kind": "AliasRef", + "aliasName": "ForwardPayloadRemainder" + } + } + ] + }, + { + "kind": "Struct", + "name": "InternalTransferStep", + "prefix": { + "prefixStr": "0x178d4519", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "transferInitiator", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "sendExcessesTo", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "forwardTonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "forwardPayload", + "isPayload": true, + "ty": { + "kind": "AliasRef", + "aliasName": "ForwardPayloadRemainder" + } + } + ] + }, + { + "kind": "Struct", + "name": "ReturnExcessesBack", + "prefix": { + "prefixStr": "0xd53276db", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + } + ] + }, + { + "kind": "Struct", + "name": "AskToBurn", + "prefix": { + "prefixStr": "0x595f07bc", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "sendExcessesTo", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "customPayload", + "isPayload": true, + "ty": { + "kind": "nullable", + "inner": { + "kind": "cell" + } + } + } + ] + }, + { + "kind": "Struct", + "name": "BurnNotificationForMinter", + "prefix": { + "prefixStr": "0x7bdd97de", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "burnInitiator", + "ty": { + "kind": "address" + } + }, + { + "name": "sendExcessesTo", + "ty": { + "kind": "addressOpt" + } + } + ] + }, + { + "kind": "Struct", + "name": "RequestWalletAddress", + "prefix": { + "prefixStr": "0x2c76b973", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "ownerAddress", + "ty": { + "kind": "address" + } + }, + { + "name": "includeOwnerAddress", + "ty": { + "kind": "bool" + } + } + ] + }, + { + "kind": "Struct", + "name": "ResponseWalletAddress", + "prefix": { + "prefixStr": "0xd1735400", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "jettonWalletAddress", + "ty": { + "kind": "addressOpt" + } + }, + { + "name": "ownerAddress", + "ty": { + "kind": "nullable", + "inner": { + "kind": "cellOf", + "inner": { + "kind": "address" + } + } + } + } + ] + }, + { + "kind": "Struct", + "name": "MintNewJettons", + "prefix": { + "prefixStr": "0x00000015", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "mintRecipient", + "ty": { + "kind": "address" + } + }, + { + "name": "tonAmount", + "ty": { + "kind": "coins" + } + }, + { + "name": "internalTransferMsg", + "ty": { + "kind": "cellOf", + "inner": { + "kind": "StructRef", + "structName": "InternalTransferStep" + } + } + } + ] + }, + { + "kind": "Struct", + "name": "ChangeMinterAdmin", + "prefix": { + "prefixStr": "0x00000003", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "newAdminAddress", + "ty": { + "kind": "address" + } + } + ] + }, + { + "kind": "Struct", + "name": "ChangeMinterContent", + "prefix": { + "prefixStr": "0x00000004", + "prefixLen": 32 + }, + "fields": [ + { + "name": "queryId", + "ty": { + "kind": "uintN", + "n": 64 + } + }, + { + "name": "newContent", + "ty": { + "kind": "cell" + } + } + ] + }, + { + "kind": "Alias", + "name": "AllowedMessageToWallet", + "targetTy": { + "kind": "union", + "variants": [ + { + "variantTy": { + "kind": "StructRef", + "structName": "AskToTransfer" + }, + "prefixStr": "0x0f8a7ea5", + "prefixLen": 32 + }, + { + "variantTy": { + "kind": "StructRef", + "structName": "AskToBurn" + }, + "prefixStr": "0x595f07bc", + "prefixLen": 32 + }, + { + "variantTy": { + "kind": "StructRef", + "structName": "InternalTransferStep" + }, + "prefixStr": "0x178d4519", + "prefixLen": 32 + } + ] + } + }, + { + "kind": "Alias", + "name": "BounceOpToHandle", + "targetTy": { + "kind": "union", + "variants": [ + { + "variantTy": { + "kind": "StructRef", + "structName": "InternalTransferStep" + }, + "prefixStr": "0x178d4519", + "prefixLen": 32 + }, + { + "variantTy": { + "kind": "StructRef", + "structName": "BurnNotificationForMinter" + }, + "prefixStr": "0x7bdd97de", + "prefixLen": 32 + } + ] + } + }, + { + "kind": "Struct", + "name": "JettonWalletDataReply", + "fields": [ + { + "name": "jettonBalance", + "ty": { + "kind": "coins" + } + }, + { + "name": "ownerAddress", + "ty": { + "kind": "address" + } + }, + { + "name": "minterAddress", + "ty": { + "kind": "address" + } + }, + { + "name": "jettonWalletCode", + "ty": { + "kind": "cell" + } + } + ] + } + ], + "incomingMessages": [ + { + "bodyTy": { + "kind": "StructRef", + "structName": "AskToTransfer" + } + }, + { + "bodyTy": { + "kind": "StructRef", + "structName": "AskToBurn" + } + }, + { + "bodyTy": { + "kind": "StructRef", + "structName": "InternalTransferStep" + } + } + ], + "outgoingMessages": [ + { + "bodyTy": { + "kind": "StructRef", + "structName": "TransferNotificationForRecipient" + } + }, + { + "bodyTy": { + "kind": "StructRef", + "structName": "ReturnExcessesBack" + } + }, + { + "bodyTy": { + "kind": "StructRef", + "structName": "InternalTransferStep" + } + }, + { + "bodyTy": { + "kind": "StructRef", + "structName": "BurnNotificationForMinter" + } + } + ], + "emittedEvents": [], + "storage": { + "storageTy": { + "kind": "StructRef", + "structName": "WalletStorage" + } + }, + "getMethods": [ + { + "tvmMethodId": 97026, + "name": "get_wallet_data", + "parameters": [], + "returnTy": { + "kind": "StructRef", + "structName": "JettonWalletDataReply" + } + } + ], + "thrownErrors": [ + { + "constName": "ERR_WRONG_WORKCHAIN", + "errCode": 333 + }, + { + "constName": "ERR_NOT_FROM_OWNER", + "errCode": 705 + }, + { + "constName": "ERR_NOT_ENOUGH_BALANCE", + "errCode": 706 + }, + { + "constName": "ERR_INVALID_WALLET", + "errCode": 707 + }, + { + "constName": "ERR_INVALID_PAYLOAD", + "errCode": 708 + }, + { + "constName": "ERR_NOT_ENOUGH_TON", + "errCode": 709 + }, + { + "constName": "", + "errCode": 65535 + } + ], + "compilerName": "tolk", + "compilerVersion": "1.2.0", + "codeBoc64": "te6ccgECCwEAAlEAART/APSkE/S88sgLAQIBYgIDA7zQ+JGONNMfMdcsILxqKMyW0z8x+gAwjhHXLCPe7L70kvI/4dM/MfoAMOLtRND6AAKgyAH6As7J7VTgINcsILxqKMzjAtcsIHxT9SzjAtcsIsr4PeTjAjCEDwHHAPL0BAUGAB2g9gXaiaH0AfSR9JBh8FUD+DHtRNAB0z/6APpQ+lD6AAb6ACD6SPpIMPiSIccFkTCOJviS+CooyM+EIPpSE/pSyVjIz4TQzMz5FsjPigBAy//PUMcF8uLD4lEmoMgB+gLOye1U+Jf4J28QIaGCCJiWgGa2CKGCCOThwKChIpQ3W2wh4w0gbrMjwgCw4w8HCAkB/jHTP/oA+kj6UPQB+gAg10ny4sQj+kQw8tFN7UTQ+gAg+kj6SDD4kiLHBfLiwVM4vvLiwlE4ocgB+gISzsntVCNyceME+Jf4k3D4OhKoJaCCCmJaAKC88uLF+CrIz4QgF/pSEvpSycjPkF41FGYYyz9QBvoCFfpUEvpUAfoCEs4KAKAx7UTQ+gAg+kj6SDD4kiLHBfLiwQTTP/oA+lAwU1G+8uLCUVGhyAH6AhTOye1UyM+R73Zfess/WPoC+lL6VMnIz4WIEvpScc8LbszJgFD7AABk+JNw+DojoKHIz5HNi0JyJ88LP1AG+gIU+lQWzsnIz4UIE/pSUAX6AnHPC2rMyXH7AAIAMMjPhQj6Ulj6AoIQ1TJ2288Liss/yXL7AAAEXwMARMnIz4mIAV3Iz4TQzMz5Fs8L/4EAjc8LdBLMEszMyYBA+wA=" +} \ No newline at end of file diff --git a/examples/tolk/payload-unmarshal/abi/jetton_wallet.json b/examples/tolk/payload-unmarshal/abi/jetton_wallet.json index 56311fca..31b3058d 100644 --- a/examples/tolk/payload-unmarshal/abi/jetton_wallet.json +++ b/examples/tolk/payload-unmarshal/abi/jetton_wallet.json @@ -1,6 +1,13 @@ { "contractName": "Jetton", "declarations": [ + { + "kind": "Alias", + "name": "ForwardPayloadRemainder", + "targetTy": { + "kind": "remaining" + } + }, { "kind": "Struct", "name": "Transfer", @@ -53,7 +60,8 @@ "name": "forwardPayload", "isPayload": true, "ty": { - "kind": "remaining" + "kind": "AliasRef", + "aliasName": "ForwardPayloadRemainder" } } ] diff --git a/examples/tolk/payload-unmarshal/output.json b/examples/tolk/payload-unmarshal/output.json index 9eeab089..5b30d089 100755 --- a/examples/tolk/payload-unmarshal/output.json +++ b/examples/tolk/payload-unmarshal/output.json @@ -1,145 +1,36 @@ { - "sumType": "struct", - "struct": { - "prefix": { - "len": 32, - "prefix": 260734629 - }, - "fields": { - "queryId": { - "sumType": "smallUint", - "smallUint": 16905987934073985 - }, - "amount": { - "sumType": "coins", - "coins": "-1107819" - }, - "destination": { - "sumType": "internalAddress", - "internalAddress": "0:ece806e21e58ce4dfd20bfc3a73df1b38412902d372869a485057608ca7f1747" - }, - "responseDestination": { - "sumType": "internalAddress", - "internalAddress": "0:ffffef1e2edf12ecdc8433e9fd90e5ffccb7d4f38db11a4d3886878c5724c4dd" - }, + "queryId": 16905987934073985, + "amount": "-1107819", + "destination": "0:ece806e21e58ce4dfd20bfc3a73df1b38412902d372869a485057608ca7f1747", + "responseDestination": "0:ffffef1e2edf12ecdc8433e9fd90e5ffccb7d4f38db11a4d3886878c5724c4dd", + "customPayload": { + "isExists": false + }, + "forwardAmount": "393000000", + "forwardPayload": { + "next": { + "queryId": 16905987934073985, + "amount": "-1107811", + "destination": "0:ff3c99e6610b0cde378c00038e896a73d5746b47b1bfe6dc7d66e53a9d84642c", + "responseDestination": "0:ffffef1e2edf12ecdc8433e9fd90e5ffccb7d4f38db11a4d3886878c5724c4dd", "customPayload": { - "sumType": "optionalValue", - "optionalValue": { - "isExists": false - } - }, - "forwardAmount": { - "sumType": "coins", - "coins": "393000000" + "isExists": false }, + "forwardAmount": "202500000", "forwardPayload": { - "sumType": "struct", - "struct": { - "prefix": { - "len": 32, - "prefix": 1323938054 - }, - "fields": { - "next": { - "sumType": "struct", - "struct": { - "prefix": { - "len": 32, - "prefix": 260734629 - }, - "fields": { - "queryId": { - "sumType": "smallUint", - "smallUint": 16905987934073985 - }, - "amount": { - "sumType": "coins", - "coins": "-1107811" - }, - "destination": { - "sumType": "internalAddress", - "internalAddress": "0:ff3c99e6610b0cde378c00038e896a73d5746b47b1bfe6dc7d66e53a9d84642c" - }, - "responseDestination": { - "sumType": "internalAddress", - "internalAddress": "0:ffffef1e2edf12ecdc8433e9fd90e5ffccb7d4f38db11a4d3886878c5724c4dd" - }, - "customPayload": { - "sumType": "optionalValue", - "optionalValue": { - "isExists": false - } - }, - "forwardAmount": { - "sumType": "coins", - "coins": "202500000" - }, - "forwardPayload": { - "sumType": "struct", - "struct": { - "prefix": { - "len": 32, - "prefix": 3237998096 - }, - "fields": { - "step": { - "sumType": "struct", - "struct": { - "fields": { - "poolAddressHash": { - "sumType": "bigUint", - "bigUint": "88789260033367713967225486461025260896651147011656566896934426357962362325226" - }, - "minOutputAmount": { - "sumType": "coins", - "coins": "12091900000" - }, - "next": { - "sumType": "optionalValue", - "optionalValue": { - "isExists": false - } - } - } - } - }, - "params": { - "sumType": "refValue", - "refValue": { - "sumType": "struct", - "struct": { - "fields": { - "deadline": { - "sumType": "smallUint", - "smallUint": 1772189925 - }, - "recipient": { - "sumType": "internalAddress", - "internalAddress": "0:ffffef1e2edf12ecdc8433e9fd90e5ffccb7d4f38db11a4d3886878c5724c4dd" - }, - "referral": { - "sumType": "optionalAddress", - "optionalAddress": { - "sumType": "internalAddress", - "internalAddress": "0:085c1bc2c8561d4d35dd8e035e739bf2fbd4e39eab30fe527e445272036e4caf" - } - }, - "notificationData": { - "sumType": "optionalValue", - "optionalValue": { - "isExists": false - } - } - } - } - } - } - } - } - } - } - } - } + "step": { + "poolAddressHash": "88789260033367713967225486461025260896651147011656566896934426357962362325226", + "minOutputAmount": "12091900000", + "next": { + "isExists": false + } + }, + "params": { + "deadline": 1772189925, + "recipient": "0:ffffef1e2edf12ecdc8433e9fd90e5ffccb7d4f38db11a4d3886878c5724c4dd", + "referral": "0:085c1bc2c8561d4d35dd8e035e739bf2fbd4e39eab30fe527e445272036e4caf", + "notificationData": { + "isExists": false } } } diff --git a/examples/tolk/simple-unmarshal/output.json b/examples/tolk/simple-unmarshal/output.json index b0a10c01..06ff8146 100755 --- a/examples/tolk/simple-unmarshal/output.json +++ b/examples/tolk/simple-unmarshal/output.json @@ -1,41 +1,11 @@ { - "sumType": "struct", - "struct": { - "prefix": { - "len": 32, - "prefix": 260734629 - }, - "fields": { - "queryId": { - "sumType": "smallUint", - "smallUint": 13784990908781977040 - }, - "amount": { - "sumType": "coins", - "coins": "1594225" - }, - "destination": { - "sumType": "internalAddress", - "internalAddress": "0:92e1411ae546892f33b2c8a89ea90390d8ff4cfbb917a643b91e73f706fdb9d1" - }, - "responseDestination": { - "sumType": "internalAddress", - "internalAddress": "0:7e33132b7cef9ac53a24b5ea8c7d6f8d5707aadddbc3875869199137705f9a2e" - }, - "customPayload": { - "sumType": "optionalValue", - "optionalValue": { - "isExists": false - } - }, - "forwardAmount": { - "sumType": "coins", - "coins": "210000000" - }, - "forwardPayload": { - "sumType": "remaining", - "remaining": "b5ee9c720101030100c40001000101e16664de2a801244183034d9fd59a236f71ec4271be377399056dda4cc3a5ebf5dc40967df641001f8cc4cadf3be6b14e892d7aa31f5be355c1eab776f0e1d61a46644ddc17e68ba003f198995be77cd629d125af5463eb7c6ab83d56eede1c3ac348cc89bb82fcd17000000007fffffffc0020095446cf7101800fc662656f9df358a74496bd518fadf1aae0f55bbb7870eb0d233226ee0bf345c00000540095e99c8dc6a438526df4961936ff51209f307a28c37c6c78310ce140ab78ab658" - } - } - } + "queryId": 13784990908781977040, + "amount": "1594225", + "destination": "0:92e1411ae546892f33b2c8a89ea90390d8ff4cfbb917a643b91e73f706fdb9d1", + "responseDestination": "0:7e33132b7cef9ac53a24b5ea8c7d6f8d5707aadddbc3875869199137705f9a2e", + "customPayload": { + "isExists": false + }, + "forwardAmount": "210000000", + "forwardPayload": "b5ee9c720101030100c40001000101e16664de2a801244183034d9fd59a236f71ec4271be377399056dda4cc3a5ebf5dc40967df641001f8cc4cadf3be6b14e892d7aa31f5be355c1eab776f0e1d61a46644ddc17e68ba003f198995be77cd629d125af5463eb7c6ab83d56eede1c3ac348cc89bb82fcd17000000007fffffffc0020095446cf7101800fc662656f9df358a74496bd518fadf1aae0f55bbb7870eb0d233226ee0bf345c00000540095e99c8dc6a438526df4961936ff51209f307a28c37c6c78310ce140ab78ab658" } \ No newline at end of file diff --git a/tolk/parser/types.go b/tolk/parser/types.go index 31ee23f1..8f32c806 100644 --- a/tolk/parser/types.go +++ b/tolk/parser/types.go @@ -762,3 +762,11 @@ type ThrownError struct { Name string `json:"constName"` ErrCode int `json:"errCode"` } + +func MustParseABI(data []byte) ABI { + var abi ABI + if err := json.Unmarshal(data, &abi); err != nil { + panic(err) + } + return abi +} diff --git a/tolk/refs.go b/tolk/refs.go index 0897a8dd..ae21c1af 100644 --- a/tolk/refs.go +++ b/tolk/refs.go @@ -132,6 +132,38 @@ func (s *Struct) resolvePayload(cell *boc.Cell, ty parser.Ty, decoder *Decoder) if isResolved { return v, true, nil } + case "AliasRef": + if decoder.abiRefs.aliasRefs == nil { + return Value{}, false, fmt.Errorf("struct has alias reference but no abi has been given") + } + alias, found := decoder.abiRefs.aliasRefs[ty.AliasRef.AliasName] + if !found { + return Value{}, false, fmt.Errorf("alias with name %s was not found in given abi", ty.AliasRef.AliasName) + } + oldGenericMap := decoder.abiRefs.genericRefs + genericMap, err := resolveGeneric(ty.AliasRef.TypeArgs, alias.TypeParams, &decoder.abiRefs) + if err != nil { + return Value{}, false, fmt.Errorf("failed to resolve alias' generic value: %w", err) + } + decoder.abiRefs.genericRefs = genericMap + + val, ok, err := s.resolvePayload(cell, alias.TargetTy, decoder) + if err != nil { + return Value{}, false, fmt.Errorf("failed to resolve payload: %w", err) + } + if !ok { + return Value{}, false, nil + } + + decoder.abiRefs.genericRefs = oldGenericMap + return val, true, nil + case "Generic": + currentTy, found := decoder.abiRefs.genericRefs[ty.Generic.NameT] + if !found { + return Value{}, false, fmt.Errorf("cannot resolve generic's type %v ", ty.Generic.NameT) + } + + return s.resolvePayload(cell, currentTy, decoder) } return Value{}, false, nil