@taquito/wallet-connect 24.3.0-beta.2 → 24.3.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/{taquito-wallet-connect/src/taquito-wallet-connect.js → taquito-wallet-connect.js} +1 -4
- package/dist/lib/{taquito-http-utils/src/version.js → version.js} +2 -2
- package/package.json +5 -7
- package/dist/lib/taquito/src/batch/constants.js +0 -16
- package/dist/lib/taquito/src/batch/rpc-batch-provider.js +0 -327
- package/dist/lib/taquito/src/constants.js +0 -135
- package/dist/lib/taquito/src/context.js +0 -178
- package/dist/lib/taquito/src/contract/big-map.js +0 -57
- package/dist/lib/taquito/src/contract/compose.js +0 -6
- package/dist/lib/taquito/src/contract/constants.js +0 -4
- package/dist/lib/taquito/src/contract/contract-methods/contract-method-factory.js +0 -18
- package/dist/lib/taquito/src/contract/contract-methods/contract-method-interface.js +0 -2
- package/dist/lib/taquito/src/contract/contract-methods/contract-method-object-param.js +0 -72
- package/dist/lib/taquito/src/contract/contract-methods/contract-on-chain-view.js +0 -111
- package/dist/lib/taquito/src/contract/contract.js +0 -158
- package/dist/lib/taquito/src/contract/errors.js +0 -140
- package/dist/lib/taquito/src/contract/index.js +0 -30
- package/dist/lib/taquito/src/contract/interface.js +0 -2
- package/dist/lib/taquito/src/contract/manager-lambda.js +0 -71
- package/dist/lib/taquito/src/contract/prepare.js +0 -231
- package/dist/lib/taquito/src/contract/rpc-contract-provider.js +0 -675
- package/dist/lib/taquito/src/contract/sapling-state-abstraction.js +0 -24
- package/dist/lib/taquito/src/contract/semantic.js +0 -43
- package/dist/lib/taquito/src/contract/view_lambda.js +0 -27
- package/dist/lib/taquito/src/errors.js +0 -42
- package/dist/lib/taquito/src/estimate/errors.js +0 -16
- package/dist/lib/taquito/src/estimate/estimate-provider-interface.js +0 -2
- package/dist/lib/taquito/src/estimate/estimate.js +0 -176
- package/dist/lib/taquito/src/estimate/index.js +0 -20
- package/dist/lib/taquito/src/estimate/rpc-estimate-provider.js +0 -640
- package/dist/lib/taquito/src/extension/extension.js +0 -2
- package/dist/lib/taquito/src/forger/composite-forger.js +0 -32
- package/dist/lib/taquito/src/forger/errors.js +0 -30
- package/dist/lib/taquito/src/forger/rpc-forger.js +0 -12
- package/dist/lib/taquito/src/forger/taquito-local-forger.js +0 -21
- package/dist/lib/taquito/src/global-constants/default-global-constants-provider.js +0 -35
- package/dist/lib/taquito/src/global-constants/errors.js +0 -30
- package/dist/lib/taquito/src/global-constants/interface-global-constants-provider.js +0 -2
- package/dist/lib/taquito/src/global-constants/noop-global-constants-provider.js +0 -10
- package/dist/lib/taquito/src/import-key.js +0 -40
- package/dist/lib/taquito/src/injector/helper.js +0 -18
- package/dist/lib/taquito/src/injector/interface.js +0 -2
- package/dist/lib/taquito/src/injector/rpc-injector.js +0 -27
- package/dist/lib/taquito/src/operations/ballot-operation.js +0 -32
- package/dist/lib/taquito/src/operations/batch-operation.js +0 -69
- package/dist/lib/taquito/src/operations/delegate-operation.js +0 -54
- package/dist/lib/taquito/src/operations/drain-delegate-operation.js +0 -31
- package/dist/lib/taquito/src/operations/errors.js +0 -133
- package/dist/lib/taquito/src/operations/failing-noop-operation.js +0 -2
- package/dist/lib/taquito/src/operations/increase-paid-storage-operation.js +0 -49
- package/dist/lib/taquito/src/operations/index.js +0 -54
- package/dist/lib/taquito/src/operations/operations.js +0 -193
- package/dist/lib/taquito/src/operations/origination-operation.js +0 -78
- package/dist/lib/taquito/src/operations/proposals-operation.js +0 -29
- package/dist/lib/taquito/src/operations/register-global-constant-operation.js +0 -52
- package/dist/lib/taquito/src/operations/reveal-operation.js +0 -74
- package/dist/lib/taquito/src/operations/smart-rollup-add-messages-operation.js +0 -44
- package/dist/lib/taquito/src/operations/smart-rollup-execute-outbox-message-operation.js +0 -53
- package/dist/lib/taquito/src/operations/smart-rollup-originate-operation.js +0 -50
- package/dist/lib/taquito/src/operations/transaction-operation.js +0 -73
- package/dist/lib/taquito/src/operations/transfer-ticket-operation.js +0 -47
- package/dist/lib/taquito/src/operations/types.js +0 -88
- package/dist/lib/taquito/src/operations/update-companion-key-operation.js +0 -55
- package/dist/lib/taquito/src/operations/update-consensus-key-operation.js +0 -55
- package/dist/lib/taquito/src/packer/interface.js +0 -2
- package/dist/lib/taquito/src/packer/michel-codec-packer.js +0 -11
- package/dist/lib/taquito/src/packer/rpc-packer.js +0 -12
- package/dist/lib/taquito/src/parser/interface.js +0 -2
- package/dist/lib/taquito/src/parser/michel-codec-parser.js +0 -110
- package/dist/lib/taquito/src/parser/noop-parser.js +0 -9
- package/dist/lib/taquito/src/prepare/index.js +0 -18
- package/dist/lib/taquito/src/prepare/interface.js +0 -2
- package/dist/lib/taquito/src/prepare/prepare-provider.js +0 -1049
- package/dist/lib/taquito/src/provider.js +0 -363
- package/dist/lib/taquito/src/read-provider/interface.js +0 -2
- package/dist/lib/taquito/src/read-provider/rpc-read-adapter.js +0 -183
- package/dist/lib/taquito/src/signer/errors.js +0 -17
- package/dist/lib/taquito/src/signer/noop.js +0 -23
- package/dist/lib/taquito/src/subscribe/create-observable-from-subscription.js +0 -20
- package/dist/lib/taquito/src/subscribe/errors.js +0 -30
- package/dist/lib/taquito/src/subscribe/filters.js +0 -96
- package/dist/lib/taquito/src/subscribe/interface.js +0 -2
- package/dist/lib/taquito/src/subscribe/observable-subscription.js +0 -79
- package/dist/lib/taquito/src/subscribe/polling-subcribe-provider.js +0 -118
- package/dist/lib/taquito/src/taquito.js +0 -404
- package/dist/lib/taquito/src/tz/interface.js +0 -2
- package/dist/lib/taquito/src/tz/rpc-tz-provider.js +0 -46
- package/dist/lib/taquito/src/version.js +0 -8
- package/dist/lib/taquito/src/wallet/batch-operation.js +0 -71
- package/dist/lib/taquito/src/wallet/delegation-operation.js +0 -42
- package/dist/lib/taquito/src/wallet/errors.js +0 -40
- package/dist/lib/taquito/src/wallet/increase-paid-storage-operation.js +0 -42
- package/dist/lib/taquito/src/wallet/index.js +0 -25
- package/dist/lib/taquito/src/wallet/interface.js +0 -2
- package/dist/lib/taquito/src/wallet/legacy.js +0 -51
- package/dist/lib/taquito/src/wallet/operation-factory.js +0 -88
- package/dist/lib/taquito/src/wallet/operation.js +0 -221
- package/dist/lib/taquito/src/wallet/origination-operation.js +0 -53
- package/dist/lib/taquito/src/wallet/receipt.js +0 -46
- package/dist/lib/taquito/src/wallet/register-global-constant-operation.js +0 -45
- package/dist/lib/taquito/src/wallet/transaction-operation.js +0 -38
- package/dist/lib/taquito/src/wallet/transfer-ticket-operation.js +0 -38
- package/dist/lib/taquito/src/wallet/wallet.js +0 -445
- package/dist/lib/taquito-core/src/errors.js +0 -351
- package/dist/lib/taquito-core/src/signer-interfaces.js +0 -2
- package/dist/lib/taquito-core/src/taquito-core.js +0 -22
- package/dist/lib/taquito-http-utils/src/errors.js +0 -103
- package/dist/lib/taquito-http-utils/src/status_code.js +0 -322
- package/dist/lib/taquito-http-utils/src/taquito-http-utils.js +0 -308
- package/dist/lib/taquito-http-utils/src/transport-errors.js +0 -141
- package/dist/lib/taquito-local-forging/src/codec.js +0 -543
- package/dist/lib/taquito-local-forging/src/constants.js +0 -291
- package/dist/lib/taquito-local-forging/src/decoder.js +0 -64
- package/dist/lib/taquito-local-forging/src/encoder.js +0 -63
- package/dist/lib/taquito-local-forging/src/errors.js +0 -179
- package/dist/lib/taquito-local-forging/src/interface.js +0 -2
- package/dist/lib/taquito-local-forging/src/michelson/codec.js +0 -283
- package/dist/lib/taquito-local-forging/src/protocols.js +0 -60
- package/dist/lib/taquito-local-forging/src/schema/operation.js +0 -259
- package/dist/lib/taquito-local-forging/src/taquito-local-forging.js +0 -117
- package/dist/lib/taquito-local-forging/src/uint8array-consumer.js +0 -35
- package/dist/lib/taquito-local-forging/src/utils.js +0 -18
- package/dist/lib/taquito-local-forging/src/validator.js +0 -57
- package/dist/lib/taquito-local-forging/src/version.js +0 -8
- package/dist/lib/taquito-michel-codec/src/base58.js +0 -255
- package/dist/lib/taquito-michel-codec/src/binary.js +0 -1271
- package/dist/lib/taquito-michel-codec/src/errors.js +0 -90
- package/dist/lib/taquito-michel-codec/src/formatters.js +0 -58
- package/dist/lib/taquito-michel-codec/src/global-constants.js +0 -12
- package/dist/lib/taquito-michel-codec/src/macros.js +0 -551
- package/dist/lib/taquito-michel-codec/src/micheline-emitter.js +0 -128
- package/dist/lib/taquito-michel-codec/src/micheline-parser.js +0 -402
- package/dist/lib/taquito-michel-codec/src/micheline.js +0 -5
- package/dist/lib/taquito-michel-codec/src/michelson-contract.js +0 -93
- package/dist/lib/taquito-michel-codec/src/michelson-typecheck.js +0 -1756
- package/dist/lib/taquito-michel-codec/src/michelson-types.js +0 -83
- package/dist/lib/taquito-michel-codec/src/michelson-validator.js +0 -833
- package/dist/lib/taquito-michel-codec/src/scan.js +0 -128
- package/dist/lib/taquito-michel-codec/src/taquito-michel-codec.js +0 -38
- package/dist/lib/taquito-michel-codec/src/utils.js +0 -323
- package/dist/lib/taquito-michel-codec/src/version.js +0 -8
- package/dist/lib/taquito-michelson-encoder/src/constants.js +0 -11
- package/dist/lib/taquito-michelson-encoder/src/errors.js +0 -38
- package/dist/lib/taquito-michelson-encoder/src/michelson-map.js +0 -201
- package/dist/lib/taquito-michelson-encoder/src/schema/errors.js +0 -127
- package/dist/lib/taquito-michelson-encoder/src/schema/event-schema.js +0 -52
- package/dist/lib/taquito-michelson-encoder/src/schema/parameter.js +0 -113
- package/dist/lib/taquito-michelson-encoder/src/schema/storage.js +0 -260
- package/dist/lib/taquito-michelson-encoder/src/schema/types.js +0 -2
- package/dist/lib/taquito-michelson-encoder/src/schema/view-schema.js +0 -90
- package/dist/lib/taquito-michelson-encoder/src/taquito-michelson-encoder.js +0 -36
- package/dist/lib/taquito-michelson-encoder/src/tokens/bigmap.js +0 -130
- package/dist/lib/taquito-michelson-encoder/src/tokens/bls12-381-fr.js +0 -86
- package/dist/lib/taquito-michelson-encoder/src/tokens/bls12-381-g1.js +0 -76
- package/dist/lib/taquito-michelson-encoder/src/tokens/bls12-381-g2.js +0 -76
- package/dist/lib/taquito-michelson-encoder/src/tokens/chain-id.js +0 -78
- package/dist/lib/taquito-michelson-encoder/src/tokens/chest-key.js +0 -74
- package/dist/lib/taquito-michelson-encoder/src/tokens/chest.js +0 -74
- package/dist/lib/taquito-michelson-encoder/src/tokens/comparable/address.js +0 -116
- package/dist/lib/taquito-michelson-encoder/src/tokens/comparable/bool.js +0 -59
- package/dist/lib/taquito-michelson-encoder/src/tokens/comparable/bytes.js +0 -90
- package/dist/lib/taquito-michelson-encoder/src/tokens/comparable/int.js +0 -90
- package/dist/lib/taquito-michelson-encoder/src/tokens/comparable/key_hash.js +0 -90
- package/dist/lib/taquito-michelson-encoder/src/tokens/comparable/mutez.js +0 -90
- package/dist/lib/taquito-michelson-encoder/src/tokens/comparable/nat.js +0 -93
- package/dist/lib/taquito-michelson-encoder/src/tokens/comparable/string.js +0 -48
- package/dist/lib/taquito-michelson-encoder/src/tokens/comparable/timestamp.js +0 -66
- package/dist/lib/taquito-michelson-encoder/src/tokens/constant.js +0 -80
- package/dist/lib/taquito-michelson-encoder/src/tokens/contract.js +0 -86
- package/dist/lib/taquito-michelson-encoder/src/tokens/createToken.js +0 -35
- package/dist/lib/taquito-michelson-encoder/src/tokens/key.js +0 -97
- package/dist/lib/taquito-michelson-encoder/src/tokens/lambda.js +0 -55
- package/dist/lib/taquito-michelson-encoder/src/tokens/list.js +0 -85
- package/dist/lib/taquito-michelson-encoder/src/tokens/map.js +0 -112
- package/dist/lib/taquito-michelson-encoder/src/tokens/never.js +0 -61
- package/dist/lib/taquito-michelson-encoder/src/tokens/operation.js +0 -39
- package/dist/lib/taquito-michelson-encoder/src/tokens/option.js +0 -88
- package/dist/lib/taquito-michelson-encoder/src/tokens/or.js +0 -282
- package/dist/lib/taquito-michelson-encoder/src/tokens/pair.js +0 -233
- package/dist/lib/taquito-michelson-encoder/src/tokens/sapling-state.js +0 -84
- package/dist/lib/taquito-michelson-encoder/src/tokens/sapling-transaction-deprecated.js +0 -74
- package/dist/lib/taquito-michelson-encoder/src/tokens/sapling-transaction.js +0 -74
- package/dist/lib/taquito-michelson-encoder/src/tokens/set.js +0 -82
- package/dist/lib/taquito-michelson-encoder/src/tokens/signature.js +0 -82
- package/dist/lib/taquito-michelson-encoder/src/tokens/ticket-deprecated.js +0 -92
- package/dist/lib/taquito-michelson-encoder/src/tokens/ticket.js +0 -92
- package/dist/lib/taquito-michelson-encoder/src/tokens/token.js +0 -100
- package/dist/lib/taquito-michelson-encoder/src/tokens/tokens.js +0 -75
- package/dist/lib/taquito-michelson-encoder/src/tokens/unit.js +0 -52
- package/dist/lib/taquito-michelson-encoder/src/version.js +0 -8
- package/dist/lib/taquito-rpc/src/opkind.js +0 -49
- package/dist/lib/taquito-rpc/src/rpc-client-interface.js +0 -60
- package/dist/lib/taquito-rpc/src/rpc-client-modules/rpc-cache.js +0 -1118
- package/dist/lib/taquito-rpc/src/taquito-rpc.js +0 -990
- package/dist/lib/taquito-rpc/src/types.js +0 -114
- package/dist/lib/taquito-rpc/src/utils/utils.js +0 -65
- package/dist/lib/taquito-rpc/src/version.js +0 -8
- package/dist/lib/taquito-signer/src/bls-key.js +0 -104
- package/dist/lib/taquito-signer/src/derivation-tools/ecdsa.js +0 -156
- package/dist/lib/taquito-signer/src/derivation-tools/ed25519.js +0 -82
- package/dist/lib/taquito-signer/src/derivation-tools/index.js +0 -79
- package/dist/lib/taquito-signer/src/derivation-tools/types.js +0 -4
- package/dist/lib/taquito-signer/src/derivation-tools/utils.js +0 -16
- package/dist/lib/taquito-signer/src/ec-key.js +0 -196
- package/dist/lib/taquito-signer/src/ed-key.js +0 -130
- package/dist/lib/taquito-signer/src/errors.js +0 -77
- package/dist/lib/taquito-signer/src/helpers.js +0 -44
- package/dist/lib/taquito-signer/src/in-memory-signer.js +0 -240
- package/dist/lib/taquito-signer/src/key-interface.js +0 -6
- package/dist/lib/taquito-signer/src/taquito-signer.js +0 -28
- package/dist/lib/taquito-signer/src/version.js +0 -8
- package/dist/lib/taquito-utils/src/constants.js +0 -203
- package/dist/lib/taquito-utils/src/encoding.js +0 -606
- package/dist/lib/taquito-utils/src/errors.js +0 -45
- package/dist/lib/taquito-utils/src/format.js +0 -29
- package/dist/lib/taquito-utils/src/taquito-utils.js +0 -42
- package/dist/lib/taquito-utils/src/validators.js +0 -236
- package/dist/lib/taquito-utils/src/verify-signature.js +0 -136
- package/dist/lib/taquito-utils/src/version.js +0 -8
- package/dist/lib/taquito-wallet-connect/src/version.js +0 -8
- package/dist/types/taquito/src/batch/constants.d.ts +0 -3
- package/dist/types/taquito/src/batch/rpc-batch-provider.d.ts +0 -139
- package/dist/types/taquito/src/constants.d.ts +0 -81
- package/dist/types/taquito/src/context.d.ts +0 -100
- package/dist/types/taquito/src/contract/big-map.d.ts +0 -35
- package/dist/types/taquito/src/contract/compose.d.ts +0 -5
- package/dist/types/taquito/src/contract/constants.d.ts +0 -1
- package/dist/types/taquito/src/contract/contract-methods/contract-method-factory.d.ts +0 -14
- package/dist/types/taquito/src/contract/contract-methods/contract-method-interface.d.ts +0 -28
- package/dist/types/taquito/src/contract/contract-methods/contract-method-object-param.d.ts +0 -39
- package/dist/types/taquito/src/contract/contract-methods/contract-on-chain-view.d.ts +0 -43
- package/dist/types/taquito/src/contract/contract.d.ts +0 -75
- package/dist/types/taquito/src/contract/errors.d.ts +0 -83
- package/dist/types/taquito/src/contract/index.d.ts +0 -11
- package/dist/types/taquito/src/contract/interface.d.ts +0 -254
- package/dist/types/taquito/src/contract/manager-lambda.d.ts +0 -73
- package/dist/types/taquito/src/contract/prepare.d.ts +0 -18
- package/dist/types/taquito/src/contract/rpc-contract-provider.d.ts +0 -270
- package/dist/types/taquito/src/contract/sapling-state-abstraction.d.ts +0 -17
- package/dist/types/taquito/src/contract/semantic.d.ts +0 -7
- package/dist/types/taquito/src/contract/view_lambda.d.ts +0 -34
- package/dist/types/taquito/src/errors.d.ts +0 -26
- package/dist/types/taquito/src/estimate/errors.d.ts +0 -8
- package/dist/types/taquito/src/estimate/estimate-provider-interface.d.ts +0 -153
- package/dist/types/taquito/src/estimate/estimate.d.ts +0 -111
- package/dist/types/taquito/src/estimate/index.d.ts +0 -4
- package/dist/types/taquito/src/estimate/rpc-estimate-provider.d.ts +0 -174
- package/dist/types/taquito/src/extension/extension.d.ts +0 -4
- package/dist/types/taquito/src/forger/composite-forger.d.ts +0 -6
- package/dist/types/taquito/src/forger/errors.d.ts +0 -16
- package/dist/types/taquito/src/forger/rpc-forger.d.ts +0 -7
- package/dist/types/taquito/src/forger/taquito-local-forger.d.ts +0 -8
- package/dist/types/taquito/src/global-constants/default-global-constants-provider.d.ts +0 -18
- package/dist/types/taquito/src/global-constants/errors.d.ts +0 -16
- package/dist/types/taquito/src/global-constants/interface-global-constants-provider.d.ts +0 -11
- package/dist/types/taquito/src/global-constants/noop-global-constants-provider.d.ts +0 -5
- package/dist/types/taquito/src/import-key.d.ts +0 -13
- package/dist/types/taquito/src/injector/helper.d.ts +0 -2
- package/dist/types/taquito/src/injector/interface.d.ts +0 -5
- package/dist/types/taquito/src/injector/rpc-injector.d.ts +0 -7
- package/dist/types/taquito/src/operations/ballot-operation.d.ts +0 -18
- package/dist/types/taquito/src/operations/batch-operation.d.ts +0 -19
- package/dist/types/taquito/src/operations/delegate-operation.d.ts +0 -24
- package/dist/types/taquito/src/operations/drain-delegate-operation.d.ts +0 -17
- package/dist/types/taquito/src/operations/errors.d.ts +0 -50
- package/dist/types/taquito/src/operations/failing-noop-operation.d.ts +0 -17
- package/dist/types/taquito/src/operations/increase-paid-storage-operation.d.ts +0 -23
- package/dist/types/taquito/src/operations/index.d.ts +0 -18
- package/dist/types/taquito/src/operations/operations.d.ts +0 -35
- package/dist/types/taquito/src/operations/origination-operation.d.ts +0 -35
- package/dist/types/taquito/src/operations/proposals-operation.d.ts +0 -17
- package/dist/types/taquito/src/operations/register-global-constant-operation.d.ts +0 -25
- package/dist/types/taquito/src/operations/reveal-operation.d.ts +0 -25
- package/dist/types/taquito/src/operations/smart-rollup-add-messages-operation.d.ts +0 -20
- package/dist/types/taquito/src/operations/smart-rollup-execute-outbox-message-operation.d.ts +0 -24
- package/dist/types/taquito/src/operations/smart-rollup-originate-operation.d.ts +0 -23
- package/dist/types/taquito/src/operations/transaction-operation.d.ts +0 -28
- package/dist/types/taquito/src/operations/transfer-ticket-operation.d.ts +0 -22
- package/dist/types/taquito/src/operations/types.d.ts +0 -823
- package/dist/types/taquito/src/operations/update-companion-key-operation.d.ts +0 -23
- package/dist/types/taquito/src/operations/update-consensus-key-operation.d.ts +0 -23
- package/dist/types/taquito/src/packer/interface.d.ts +0 -4
- package/dist/types/taquito/src/packer/michel-codec-packer.d.ts +0 -5
- package/dist/types/taquito/src/packer/rpc-packer.d.ts +0 -8
- package/dist/types/taquito/src/parser/interface.d.ts +0 -4
- package/dist/types/taquito/src/parser/michel-codec-parser.d.ts +0 -16
- package/dist/types/taquito/src/parser/noop-parser.d.ts +0 -5
- package/dist/types/taquito/src/prepare/index.d.ts +0 -2
- package/dist/types/taquito/src/prepare/interface.d.ts +0 -152
- package/dist/types/taquito/src/prepare/prepare-provider.d.ts +0 -187
- package/dist/types/taquito/src/provider.d.ts +0 -50
- package/dist/types/taquito/src/read-provider/interface.d.ts +0 -132
- package/dist/types/taquito/src/read-provider/rpc-read-adapter.d.ts +0 -130
- package/dist/types/taquito/src/signer/errors.d.ts +0 -8
- package/dist/types/taquito/src/signer/noop.d.ts +0 -11
- package/dist/types/taquito/src/subscribe/create-observable-from-subscription.d.ts +0 -4
- package/dist/types/taquito/src/subscribe/errors.d.ts +0 -18
- package/dist/types/taquito/src/subscribe/filters.d.ts +0 -6
- package/dist/types/taquito/src/subscribe/interface.d.ts +0 -48
- package/dist/types/taquito/src/subscribe/observable-subscription.d.ts +0 -21
- package/dist/types/taquito/src/subscribe/polling-subcribe-provider.d.ts +0 -23
- package/dist/types/taquito/src/taquito.d.ts +0 -248
- package/dist/types/taquito/src/tz/interface.d.ts +0 -20
- package/dist/types/taquito/src/tz/rpc-tz-provider.d.ts +0 -13
- package/dist/types/taquito/src/version.d.ts +0 -4
- package/dist/types/taquito/src/wallet/batch-operation.d.ts +0 -13
- package/dist/types/taquito/src/wallet/delegation-operation.d.ts +0 -12
- package/dist/types/taquito/src/wallet/errors.d.ts +0 -24
- package/dist/types/taquito/src/wallet/increase-paid-storage-operation.d.ts +0 -12
- package/dist/types/taquito/src/wallet/index.d.ts +0 -9
- package/dist/types/taquito/src/wallet/interface.d.ts +0 -66
- package/dist/types/taquito/src/wallet/legacy.d.ts +0 -21
- package/dist/types/taquito/src/wallet/operation-factory.d.ts +0 -32
- package/dist/types/taquito/src/wallet/operation.d.ts +0 -55
- package/dist/types/taquito/src/wallet/origination-operation.d.ts +0 -14
- package/dist/types/taquito/src/wallet/receipt.d.ts +0 -16
- package/dist/types/taquito/src/wallet/register-global-constant-operation.d.ts +0 -13
- package/dist/types/taquito/src/wallet/transaction-operation.d.ts +0 -12
- package/dist/types/taquito/src/wallet/transfer-ticket-operation.d.ts +0 -12
- package/dist/types/taquito/src/wallet/wallet.d.ts +0 -196
- package/dist/types/taquito-core/src/errors.d.ts +0 -213
- package/dist/types/taquito-core/src/signer-interfaces.d.ts +0 -38
- package/dist/types/taquito-core/src/taquito-core.d.ts +0 -6
- package/dist/types/taquito-http-utils/src/errors.d.ts +0 -63
- package/dist/types/taquito-http-utils/src/status_code.d.ts +0 -318
- package/dist/types/taquito-http-utils/src/taquito-http-utils.d.ts +0 -58
- package/dist/types/taquito-http-utils/src/transport-errors.d.ts +0 -28
- package/dist/types/taquito-local-forging/src/codec.d.ts +0 -79
- package/dist/types/taquito-local-forging/src/constants.d.ts +0 -75
- package/dist/types/taquito-local-forging/src/decoder.d.ts +0 -5
- package/dist/types/taquito-local-forging/src/encoder.d.ts +0 -4
- package/dist/types/taquito-local-forging/src/errors.d.ts +0 -109
- package/dist/types/taquito-local-forging/src/interface.d.ts +0 -9
- package/dist/types/taquito-local-forging/src/michelson/codec.d.ts +0 -49
- package/dist/types/taquito-local-forging/src/protocols.d.ts +0 -27
- package/dist/types/taquito-local-forging/src/schema/operation.d.ts +0 -198
- package/dist/types/taquito-local-forging/src/taquito-local-forging.d.ts +0 -27
- package/dist/types/taquito-local-forging/src/uint8array-consumer.d.ts +0 -10
- package/dist/types/taquito-local-forging/src/utils.d.ts +0 -3
- package/dist/types/taquito-local-forging/src/validator.d.ts +0 -13
- package/dist/types/taquito-local-forging/src/version.d.ts +0 -4
- package/dist/types/taquito-michel-codec/src/base58.d.ts +0 -13
- package/dist/types/taquito-michel-codec/src/binary.d.ts +0 -127
- package/dist/types/taquito-michel-codec/src/errors.d.ts +0 -57
- package/dist/types/taquito-michel-codec/src/formatters.d.ts +0 -6
- package/dist/types/taquito-michel-codec/src/global-constants.d.ts +0 -3
- package/dist/types/taquito-michel-codec/src/macros.d.ts +0 -13
- package/dist/types/taquito-michel-codec/src/micheline-emitter.d.ts +0 -17
- package/dist/types/taquito-michel-codec/src/micheline-parser.d.ts +0 -130
- package/dist/types/taquito-michel-codec/src/micheline.d.ts +0 -44
- package/dist/types/taquito-michel-codec/src/michelson-contract.d.ts +0 -24
- package/dist/types/taquito-michel-codec/src/michelson-typecheck.d.ts +0 -38
- package/dist/types/taquito-michel-codec/src/michelson-types.d.ts +0 -147
- package/dist/types/taquito-michel-codec/src/michelson-validator.d.ts +0 -66
- package/dist/types/taquito-michel-codec/src/scan.d.ts +0 -26
- package/dist/types/taquito-michel-codec/src/taquito-michel-codec.d.ts +0 -16
- package/dist/types/taquito-michel-codec/src/utils.d.ts +0 -76
- package/dist/types/taquito-michel-codec/src/version.d.ts +0 -4
- package/dist/types/taquito-michelson-encoder/src/constants.d.ts +0 -8
- package/dist/types/taquito-michelson-encoder/src/errors.d.ts +0 -17
- package/dist/types/taquito-michelson-encoder/src/michelson-map.d.ts +0 -82
- package/dist/types/taquito-michelson-encoder/src/schema/errors.d.ts +0 -83
- package/dist/types/taquito-michelson-encoder/src/schema/event-schema.d.ts +0 -12
- package/dist/types/taquito-michelson-encoder/src/schema/parameter.d.ts +0 -54
- package/dist/types/taquito-michelson-encoder/src/schema/storage.d.ts +0 -97
- package/dist/types/taquito-michelson-encoder/src/schema/types.d.ts +0 -105
- package/dist/types/taquito-michelson-encoder/src/schema/view-schema.d.ts +0 -53
- package/dist/types/taquito-michelson-encoder/src/taquito-michelson-encoder.d.ts +0 -16
- package/dist/types/taquito-michelson-encoder/src/tokens/bigmap.d.ts +0 -51
- package/dist/types/taquito-michelson-encoder/src/tokens/bls12-381-fr.d.ts +0 -51
- package/dist/types/taquito-michelson-encoder/src/tokens/bls12-381-g1.d.ts +0 -47
- package/dist/types/taquito-michelson-encoder/src/tokens/bls12-381-g2.d.ts +0 -47
- package/dist/types/taquito-michelson-encoder/src/tokens/chain-id.d.ts +0 -51
- package/dist/types/taquito-michelson-encoder/src/tokens/chest-key.d.ts +0 -47
- package/dist/types/taquito-michelson-encoder/src/tokens/chest.d.ts +0 -47
- package/dist/types/taquito-michelson-encoder/src/tokens/comparable/address.d.ts +0 -61
- package/dist/types/taquito-michelson-encoder/src/tokens/comparable/bool.d.ts +0 -32
- package/dist/types/taquito-michelson-encoder/src/tokens/comparable/bytes.d.ts +0 -52
- package/dist/types/taquito-michelson-encoder/src/tokens/comparable/int.d.ts +0 -56
- package/dist/types/taquito-michelson-encoder/src/tokens/comparable/key_hash.d.ts +0 -55
- package/dist/types/taquito-michelson-encoder/src/tokens/comparable/mutez.d.ts +0 -53
- package/dist/types/taquito-michelson-encoder/src/tokens/comparable/nat.d.ts +0 -55
- package/dist/types/taquito-michelson-encoder/src/tokens/comparable/string.d.ts +0 -31
- package/dist/types/taquito-michelson-encoder/src/tokens/comparable/timestamp.d.ts +0 -34
- package/dist/types/taquito-michelson-encoder/src/tokens/constant.d.ts +0 -51
- package/dist/types/taquito-michelson-encoder/src/tokens/contract.d.ts +0 -48
- package/dist/types/taquito-michelson-encoder/src/tokens/createToken.d.ts +0 -18
- package/dist/types/taquito-michelson-encoder/src/tokens/key.d.ts +0 -55
- package/dist/types/taquito-michelson-encoder/src/tokens/lambda.d.ts +0 -24
- package/dist/types/taquito-michelson-encoder/src/tokens/list.d.ts +0 -46
- package/dist/types/taquito-michelson-encoder/src/tokens/map.d.ts +0 -47
- package/dist/types/taquito-michelson-encoder/src/tokens/never.d.ts +0 -41
- package/dist/types/taquito-michelson-encoder/src/tokens/operation.d.ts +0 -24
- package/dist/types/taquito-michelson-encoder/src/tokens/option.d.ts +0 -37
- package/dist/types/taquito-michelson-encoder/src/tokens/or.d.ts +0 -53
- package/dist/types/taquito-michelson-encoder/src/tokens/pair.d.ts +0 -50
- package/dist/types/taquito-michelson-encoder/src/tokens/sapling-state.d.ts +0 -44
- package/dist/types/taquito-michelson-encoder/src/tokens/sapling-transaction-deprecated.d.ts +0 -40
- package/dist/types/taquito-michelson-encoder/src/tokens/sapling-transaction.d.ts +0 -40
- package/dist/types/taquito-michelson-encoder/src/tokens/set.d.ts +0 -43
- package/dist/types/taquito-michelson-encoder/src/tokens/signature.d.ts +0 -53
- package/dist/types/taquito-michelson-encoder/src/tokens/ticket-deprecated.d.ts +0 -38
- package/dist/types/taquito-michelson-encoder/src/tokens/ticket.d.ts +0 -38
- package/dist/types/taquito-michelson-encoder/src/tokens/token.d.ts +0 -68
- package/dist/types/taquito-michelson-encoder/src/tokens/tokens.d.ts +0 -36
- package/dist/types/taquito-michelson-encoder/src/tokens/unit.d.ts +0 -34
- package/dist/types/taquito-michelson-encoder/src/version.d.ts +0 -4
- package/dist/types/taquito-rpc/src/opkind.d.ts +0 -45
- package/dist/types/taquito-rpc/src/rpc-client-interface.d.ts +0 -126
- package/dist/types/taquito-rpc/src/rpc-client-modules/rpc-cache.d.ts +0 -473
- package/dist/types/taquito-rpc/src/taquito-rpc.d.ts +0 -483
- package/dist/types/taquito-rpc/src/types.d.ts +0 -2362
- package/dist/types/taquito-rpc/src/utils/utils.d.ts +0 -14
- package/dist/types/taquito-rpc/src/version.d.ts +0 -4
- package/dist/types/taquito-signer/src/bls-key.d.ts +0 -21
- package/dist/types/taquito-signer/src/derivation-tools/ecdsa.d.ts +0 -49
- package/dist/types/taquito-signer/src/derivation-tools/ed25519.d.ts +0 -33
- package/dist/types/taquito-signer/src/derivation-tools/index.d.ts +0 -12
- package/dist/types/taquito-signer/src/derivation-tools/types.d.ts +0 -10
- package/dist/types/taquito-signer/src/derivation-tools/utils.d.ts +0 -1
- package/dist/types/taquito-signer/src/ec-key.d.ts +0 -42
- package/dist/types/taquito-signer/src/ed-key.d.ts +0 -39
- package/dist/types/taquito-signer/src/errors.d.ts +0 -51
- package/dist/types/taquito-signer/src/helpers.d.ts +0 -10
- package/dist/types/taquito-signer/src/in-memory-signer.d.ts +0 -56
- package/dist/types/taquito-signer/src/key-interface.d.ts +0 -37
- package/dist/types/taquito-signer/src/taquito-signer.d.ts +0 -10
- package/dist/types/taquito-signer/src/version.d.ts +0 -4
- package/dist/types/taquito-utils/src/constants.d.ts +0 -78
- package/dist/types/taquito-utils/src/encoding.d.ts +0 -184
- package/dist/types/taquito-utils/src/errors.d.ts +0 -20
- package/dist/types/taquito-utils/src/format.d.ts +0 -4
- package/dist/types/taquito-utils/src/taquito-utils.d.ts +0 -11
- package/dist/types/taquito-utils/src/validators.d.ts +0 -167
- package/dist/types/taquito-utils/src/verify-signature.d.ts +0 -22
- package/dist/types/taquito-utils/src/version.d.ts +0 -4
- package/dist/types/taquito-wallet-connect/src/version.d.ts +0 -4
- /package/dist/lib/{taquito-wallet-connect/src/errors.js → errors.js} +0 -0
- /package/dist/lib/{taquito-wallet-connect/src/types.js → types.js} +0 -0
- /package/dist/types/{taquito-wallet-connect/src/errors.d.ts → errors.d.ts} +0 -0
- /package/dist/types/{taquito-wallet-connect/src/taquito-wallet-connect.d.ts → taquito-wallet-connect.d.ts} +0 -0
- /package/dist/types/{taquito-wallet-connect/src/types.d.ts → types.d.ts} +0 -0
- /package/dist/types/{taquito-http-utils/src/version.d.ts → version.d.ts} +0 -0
|
@@ -1,1756 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MichelsonInstructionError = void 0;
|
|
4
|
-
exports.assertTypeAnnotationsValid = assertTypeAnnotationsValid;
|
|
5
|
-
exports.contractSection = contractSection;
|
|
6
|
-
exports.contractViews = contractViews;
|
|
7
|
-
exports.contractEntryPoint = contractEntryPoint;
|
|
8
|
-
exports.contractEntryPoints = contractEntryPoints;
|
|
9
|
-
exports.assertContractValid = assertContractValid;
|
|
10
|
-
exports.assertDataValid = assertDataValid;
|
|
11
|
-
exports.functionType = functionType;
|
|
12
|
-
exports.assertTypesEqual = assertTypesEqual;
|
|
13
|
-
exports.isTypeAnnotationsValid = isTypeAnnotationsValid;
|
|
14
|
-
exports.isContractValid = isContractValid;
|
|
15
|
-
exports.isDataValid = isDataValid;
|
|
16
|
-
exports.isTypeEqual = isTypeEqual;
|
|
17
|
-
const michelson_types_1 = require("./michelson-types");
|
|
18
|
-
const utils_1 = require("./utils");
|
|
19
|
-
const base58_1 = require("./base58");
|
|
20
|
-
const binary_1 = require("./binary");
|
|
21
|
-
const michelson_validator_1 = require("./michelson-validator");
|
|
22
|
-
class MichelsonInstructionError extends utils_1.MichelsonError {
|
|
23
|
-
/**
|
|
24
|
-
* @param val Value of a type node caused the error
|
|
25
|
-
* @param stackState Current stack state
|
|
26
|
-
* @param message An error message
|
|
27
|
-
*/
|
|
28
|
-
constructor(val, stackState, message) {
|
|
29
|
-
super(val, message);
|
|
30
|
-
this.val = val;
|
|
31
|
-
this.stackState = stackState;
|
|
32
|
-
this.message = message;
|
|
33
|
-
this.name = 'MichelsonInstructionError';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.MichelsonInstructionError = MichelsonInstructionError;
|
|
37
|
-
// 'sequence as a pair' edo syntax helpers
|
|
38
|
-
function typeID(t) {
|
|
39
|
-
return Array.isArray(t) ? 'pair' : t.prim;
|
|
40
|
-
}
|
|
41
|
-
function typeArgs(t) {
|
|
42
|
-
return ('prim' in t ? t.args : t);
|
|
43
|
-
}
|
|
44
|
-
function assertScalarTypesEqual(a, b, field = false) {
|
|
45
|
-
if (typeID(a) !== typeID(b)) {
|
|
46
|
-
throw new utils_1.MichelsonTypeError(a, `types mismatch: ${typeID(a)} != ${typeID(b)}`, undefined);
|
|
47
|
-
}
|
|
48
|
-
const ann = [(0, utils_1.unpackAnnotations)(a), (0, utils_1.unpackAnnotations)(b)];
|
|
49
|
-
if (ann[0].t && ann[1].t && ann[0].t[0] !== ann[1].t[0]) {
|
|
50
|
-
throw new utils_1.MichelsonTypeError(a, `${typeID(a)}: type names mismatch: ${ann[0].t[0]} != ${ann[1].t[0]}`, undefined);
|
|
51
|
-
}
|
|
52
|
-
if (field && ann[0].f && ann[1].f && ann[0].f[0] !== ann[1].f[0]) {
|
|
53
|
-
throw new utils_1.MichelsonTypeError(a, `${typeID(a)}: field names mismatch: ${ann[0].f[0]} != ${ann[1].f}`, undefined);
|
|
54
|
-
}
|
|
55
|
-
if ((0, utils_1.isPairType)(a)) {
|
|
56
|
-
const aArgs = (0, utils_1.unpackComb)('pair', a);
|
|
57
|
-
const bArgs = (0, utils_1.unpackComb)('pair', b);
|
|
58
|
-
assertScalarTypesEqual(aArgs.args[0], bArgs.args[0], true);
|
|
59
|
-
assertScalarTypesEqual(aArgs.args[1], bArgs.args[1], true);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
switch (a.prim) {
|
|
63
|
-
case 'option':
|
|
64
|
-
case 'list':
|
|
65
|
-
case 'contract':
|
|
66
|
-
case 'set':
|
|
67
|
-
case 'ticket':
|
|
68
|
-
assertScalarTypesEqual(a.args[0], b.args[0]);
|
|
69
|
-
break;
|
|
70
|
-
case 'or':
|
|
71
|
-
assertScalarTypesEqual(a.args[0], b.args[0], true);
|
|
72
|
-
assertScalarTypesEqual(a.args[1], b.args[1], true);
|
|
73
|
-
break;
|
|
74
|
-
case 'lambda':
|
|
75
|
-
case 'map':
|
|
76
|
-
case 'big_map':
|
|
77
|
-
assertScalarTypesEqual(a.args[0], b.args[0]);
|
|
78
|
-
assertScalarTypesEqual(a.args[1], b.args[1]);
|
|
79
|
-
break;
|
|
80
|
-
case 'sapling_state':
|
|
81
|
-
case 'sapling_transaction':
|
|
82
|
-
if (parseInt(a.args[0].int, 10) !== parseInt(b.args[0].int, 10)) {
|
|
83
|
-
throw new utils_1.MichelsonTypeError(a, `${typeID(a)}: type argument mismatch: ${a.args[0].int} != ${b.args[0].int}`, undefined);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
function assertStacksEqual(a, b) {
|
|
88
|
-
if (a.length !== b.length) {
|
|
89
|
-
throw new utils_1.MichelsonTypeError(a, `stack length mismatch: ${a.length} != ${b.length}`, undefined);
|
|
90
|
-
}
|
|
91
|
-
for (let i = 0; i < a.length; i++) {
|
|
92
|
-
assertScalarTypesEqual(a[i], b[i]);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
function assertTypeAnnotationsValid(t, field = false) {
|
|
96
|
-
if (!Array.isArray(t)) {
|
|
97
|
-
const ann = (0, utils_1.unpackAnnotations)(t);
|
|
98
|
-
if ((ann.t?.length || 0) > 1) {
|
|
99
|
-
throw new utils_1.MichelsonTypeError(t, `${t.prim}: at most one type annotation allowed: ${t.annots}`, undefined);
|
|
100
|
-
}
|
|
101
|
-
if (field) {
|
|
102
|
-
if ((ann.f?.length || 0) > 1) {
|
|
103
|
-
throw new utils_1.MichelsonTypeError(t, `${t.prim}: at most one field annotation allowed: ${t.annots}`, undefined);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
if ((ann.f?.length || 0) > 0) {
|
|
108
|
-
throw new utils_1.MichelsonTypeError(t, `${t.prim}: field annotations aren't allowed: ${t.annots}`, undefined);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
if ((0, utils_1.isPairType)(t)) {
|
|
113
|
-
const args = typeArgs(t);
|
|
114
|
-
for (const a of args) {
|
|
115
|
-
assertTypeAnnotationsValid(a, true);
|
|
116
|
-
}
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
switch (t.prim) {
|
|
120
|
-
case 'option':
|
|
121
|
-
case 'list':
|
|
122
|
-
case 'contract':
|
|
123
|
-
case 'set':
|
|
124
|
-
assertTypeAnnotationsValid(t.args[0]);
|
|
125
|
-
break;
|
|
126
|
-
case 'or':
|
|
127
|
-
for (const a of t.args) {
|
|
128
|
-
assertTypeAnnotationsValid(a, true);
|
|
129
|
-
}
|
|
130
|
-
break;
|
|
131
|
-
case 'lambda':
|
|
132
|
-
case 'map':
|
|
133
|
-
case 'big_map':
|
|
134
|
-
assertTypeAnnotationsValid(t.args[0]);
|
|
135
|
-
assertTypeAnnotationsValid(t.args[1]);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
// Data integrity check
|
|
139
|
-
function _compareMichelsonData(t, a, b) {
|
|
140
|
-
if ((0, utils_1.isPairType)(t)) {
|
|
141
|
-
if ((0, utils_1.isPairData)(a) && (0, utils_1.isPairData)(b)) {
|
|
142
|
-
(0, michelson_validator_1.assertDataListIfAny)(a);
|
|
143
|
-
(0, michelson_validator_1.assertDataListIfAny)(b);
|
|
144
|
-
const tComb = (0, utils_1.unpackComb)('pair', t);
|
|
145
|
-
const aComb = (0, utils_1.unpackComb)('Pair', a);
|
|
146
|
-
const bComb = (0, utils_1.unpackComb)('Pair', b);
|
|
147
|
-
const x = _compareMichelsonData(tComb.args[0], aComb.args[0], bComb.args[0]);
|
|
148
|
-
if (x !== 0) {
|
|
149
|
-
return x;
|
|
150
|
-
}
|
|
151
|
-
return _compareMichelsonData(tComb.args[0], aComb.args[1], bComb.args[1]);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
switch (t.prim) {
|
|
156
|
-
case 'int':
|
|
157
|
-
case 'nat':
|
|
158
|
-
case 'mutez':
|
|
159
|
-
if ('int' in a && 'int' in b) {
|
|
160
|
-
return new utils_1.LongInteger(a.int).cmp(new utils_1.LongInteger(b.int));
|
|
161
|
-
}
|
|
162
|
-
break;
|
|
163
|
-
case 'string':
|
|
164
|
-
if ('string' in a && 'string' in b) {
|
|
165
|
-
const x = a.string.localeCompare(b.string);
|
|
166
|
-
return x < 0 ? -1 : x > 0 ? 1 : 0;
|
|
167
|
-
}
|
|
168
|
-
break;
|
|
169
|
-
case 'bytes':
|
|
170
|
-
if ('bytes' in a && 'bytes' in b) {
|
|
171
|
-
const aa = (0, utils_1.parseBytes)(a.bytes);
|
|
172
|
-
const bb = (0, utils_1.parseBytes)(b.bytes);
|
|
173
|
-
if (aa !== null && bb !== null) {
|
|
174
|
-
return (0, utils_1.compareBytes)(aa, bb);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
break;
|
|
178
|
-
case 'bool':
|
|
179
|
-
if ('prim' in a &&
|
|
180
|
-
'prim' in b &&
|
|
181
|
-
(a.prim === 'True' || a.prim === 'False') &&
|
|
182
|
-
(b.prim === 'True' || b.prim === 'False')) {
|
|
183
|
-
return a.prim === b.prim ? 0 : a.prim === 'False' ? -1 : 1;
|
|
184
|
-
}
|
|
185
|
-
break;
|
|
186
|
-
case 'key':
|
|
187
|
-
case 'key_hash':
|
|
188
|
-
case 'address':
|
|
189
|
-
case 'signature':
|
|
190
|
-
case 'chain_id':
|
|
191
|
-
if (('string' in a || 'bytes' in a) && ('string' in b || 'bytes' in b)) {
|
|
192
|
-
return (0, utils_1.compareBytes)('string' in a ? (0, base58_1.decodeBase58Check)(a.string) : (0, utils_1.parseBytes)(a.bytes) || [], 'string' in b ? (0, base58_1.decodeBase58Check)(b.string) : (0, utils_1.parseBytes)(b.bytes) || []);
|
|
193
|
-
}
|
|
194
|
-
break;
|
|
195
|
-
case 'timestamp':
|
|
196
|
-
if (('string' in a || 'int' in a) && ('string' in b || 'int' in b)) {
|
|
197
|
-
const aa = (0, utils_1.parseDate)(a);
|
|
198
|
-
const bb = (0, utils_1.parseDate)(b);
|
|
199
|
-
if (aa !== null && bb !== null) {
|
|
200
|
-
const x = aa.valueOf() - bb.valueOf();
|
|
201
|
-
return x < 0 ? -1 : x > 0 ? 1 : 0;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
break;
|
|
205
|
-
case 'unit':
|
|
206
|
-
if ('prim' in a && 'prim' in b && a.prim === 'Unit' && b.prim === 'Unit') {
|
|
207
|
-
return 0;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
// Unlikely, types are expected to be verified before the function call
|
|
212
|
-
throw new utils_1.MichelsonTypeError(t, `${typeID(t)}: not comparable values: ${JSON.stringify(a)}, ${JSON.stringify(b)}`, undefined);
|
|
213
|
-
}
|
|
214
|
-
// Simplified version of assertMichelsonInstruction() for previously validated data
|
|
215
|
-
function isFunction(d) {
|
|
216
|
-
if (!Array.isArray(d)) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
for (const v of d) {
|
|
220
|
-
if (!((Array.isArray(v) && isFunction(v)) || ('prim' in v && (0, michelson_validator_1.isInstruction)(v)))) {
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
function assertDataValidInternal(d, t, ctx) {
|
|
227
|
-
if ((0, utils_1.isPairType)(t)) {
|
|
228
|
-
if ((0, utils_1.isPairData)(d)) {
|
|
229
|
-
(0, michelson_validator_1.assertDataListIfAny)(d);
|
|
230
|
-
const dc = (0, utils_1.unpackComb)('Pair', d);
|
|
231
|
-
const tc = (0, utils_1.unpackComb)('pair', t);
|
|
232
|
-
assertDataValidInternal(dc.args[0], tc.args[0], ctx);
|
|
233
|
-
assertDataValidInternal(dc.args[1], tc.args[1], ctx);
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
throw new utils_1.MichelsonTypeError(t, `pair expected: ${JSON.stringify(d)}`, d);
|
|
237
|
-
}
|
|
238
|
-
switch (t.prim) {
|
|
239
|
-
// Atomic literals
|
|
240
|
-
case 'int':
|
|
241
|
-
if ('int' in d && (0, utils_1.isDecimal)(d.int)) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
throw new utils_1.MichelsonTypeError(t, `integer value expected: ${JSON.stringify(d)}`, d);
|
|
245
|
-
case 'nat':
|
|
246
|
-
case 'mutez':
|
|
247
|
-
if ('int' in d && (0, utils_1.isNatural)(d.int)) {
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
throw new utils_1.MichelsonTypeError(t, `natural value expected: ${JSON.stringify(d)}`, d);
|
|
251
|
-
case 'string':
|
|
252
|
-
if ('string' in d) {
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
throw new utils_1.MichelsonTypeError(t, `string value expected: ${JSON.stringify(d)}`, d);
|
|
256
|
-
case 'bytes':
|
|
257
|
-
case 'bls12_381_g1':
|
|
258
|
-
case 'bls12_381_g2':
|
|
259
|
-
if ('bytes' in d && (0, utils_1.parseBytes)(d.bytes) !== null) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
throw new utils_1.MichelsonTypeError(t, `bytes value expected: ${JSON.stringify(d)}`, d);
|
|
263
|
-
case 'bool':
|
|
264
|
-
if ('prim' in d && (d.prim === 'True' || d.prim === 'False')) {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
throw new utils_1.MichelsonTypeError(t, `boolean value expected: ${JSON.stringify(d)}`, d);
|
|
268
|
-
case 'key_hash':
|
|
269
|
-
if ('string' in d &&
|
|
270
|
-
(0, utils_1.checkDecodeTezosID)(d.string, 'ED25519PublicKeyHash', 'SECP256K1PublicKeyHash', 'P256PublicKeyHash') !== null) {
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
else if ('bytes' in d) {
|
|
274
|
-
try {
|
|
275
|
-
(0, binary_1.decodePublicKeyHashBytes)(d);
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
catch (err) {
|
|
279
|
-
// ignore message
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
throw new utils_1.MichelsonTypeError(t, `key hash expected: ${JSON.stringify(d)}`, d);
|
|
283
|
-
case 'timestamp':
|
|
284
|
-
if (('string' in d || 'int' in d) && (0, utils_1.parseDate)(d) !== null) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
throw new utils_1.MichelsonTypeError(t, `timestamp expected: ${JSON.stringify(d)}`, d);
|
|
288
|
-
case 'address':
|
|
289
|
-
if ('string' in d) {
|
|
290
|
-
let address = d.string;
|
|
291
|
-
const ep = d.string.indexOf('%');
|
|
292
|
-
if (ep >= 0) {
|
|
293
|
-
// trim entry point
|
|
294
|
-
address = d.string.slice(0, ep);
|
|
295
|
-
}
|
|
296
|
-
if ((0, utils_1.checkDecodeTezosID)(address, 'ED25519PublicKeyHash', 'SECP256K1PublicKeyHash', 'P256PublicKeyHash', 'ContractHash', 'RollupAddress') !== null) {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
else if ('bytes' in d) {
|
|
301
|
-
try {
|
|
302
|
-
(0, binary_1.decodeAddressBytes)(d);
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
catch (err) {
|
|
306
|
-
// ignore message
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
throw new utils_1.MichelsonTypeError(t, `address expected: ${JSON.stringify(d)}`, d);
|
|
310
|
-
case 'key':
|
|
311
|
-
if ('string' in d &&
|
|
312
|
-
(0, utils_1.checkDecodeTezosID)(d.string, 'ED25519PublicKey', 'SECP256K1PublicKey', 'P256PublicKey') !==
|
|
313
|
-
null) {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
else if ('bytes' in d) {
|
|
317
|
-
try {
|
|
318
|
-
(0, binary_1.decodePublicKeyBytes)(d);
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
catch (err) {
|
|
322
|
-
// ignore message
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
throw new utils_1.MichelsonTypeError(t, `public key expected: ${JSON.stringify(d)}`, d);
|
|
326
|
-
case 'unit':
|
|
327
|
-
if ('prim' in d && d.prim === 'Unit') {
|
|
328
|
-
return;
|
|
329
|
-
}
|
|
330
|
-
throw new utils_1.MichelsonTypeError(t, `unit value expected: ${JSON.stringify(d)}`, d);
|
|
331
|
-
case 'signature':
|
|
332
|
-
if ('bytes' in d ||
|
|
333
|
-
('string' in d &&
|
|
334
|
-
(0, utils_1.checkDecodeTezosID)(d.string, 'ED25519Signature', 'SECP256K1Signature', 'P256Signature', 'GenericSignature') !== null)) {
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
throw new utils_1.MichelsonTypeError(t, `signature expected: ${JSON.stringify(d)}`, d);
|
|
338
|
-
case 'chain_id':
|
|
339
|
-
if ('bytes' in d || 'string' in d) {
|
|
340
|
-
const x = 'string' in d ? (0, base58_1.decodeBase58Check)(d.string) : (0, utils_1.parseBytes)(d.bytes);
|
|
341
|
-
if (x !== null) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
throw new utils_1.MichelsonTypeError(t, `chain id expected: ${JSON.stringify(d)}`, d);
|
|
346
|
-
// Complex types
|
|
347
|
-
case 'option':
|
|
348
|
-
if ('prim' in d) {
|
|
349
|
-
if (d.prim === 'None') {
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
else if (d.prim === 'Some') {
|
|
353
|
-
assertDataValidInternal(d.args[0], t.args[0], ctx);
|
|
354
|
-
return;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
throw new utils_1.MichelsonTypeError(t, `option expected: ${JSON.stringify(d)}`, d);
|
|
358
|
-
case 'list':
|
|
359
|
-
case 'set':
|
|
360
|
-
if ((0, michelson_validator_1.assertDataListIfAny)(d)) {
|
|
361
|
-
//let prev: MichelsonData | undefined;
|
|
362
|
-
for (const v of d) {
|
|
363
|
-
assertDataValidInternal(v, t.args[0], ctx);
|
|
364
|
-
}
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
throw new utils_1.MichelsonTypeError(t, `${t.prim} expected: ${JSON.stringify(d)}`, d);
|
|
368
|
-
case 'or':
|
|
369
|
-
if ('prim' in d) {
|
|
370
|
-
if (d.prim === 'Left') {
|
|
371
|
-
assertDataValidInternal(d.args[0], t.args[0], ctx);
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
else if (d.prim === 'Right') {
|
|
375
|
-
assertDataValidInternal(d.args[0], t.args[1], ctx);
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
throw new utils_1.MichelsonTypeError(t, `union (or) expected: ${JSON.stringify(d)}`, d);
|
|
380
|
-
case 'lambda':
|
|
381
|
-
if (isFunction(d)) {
|
|
382
|
-
const ret = functionTypeInternal(d, [t.args[0]], ctx);
|
|
383
|
-
if ('failed' in ret) {
|
|
384
|
-
throw new utils_1.MichelsonTypeError(t, `function is failed with error type: ${ret.failed}`, d);
|
|
385
|
-
}
|
|
386
|
-
if (ret.length !== 1) {
|
|
387
|
-
throw new utils_1.MichelsonTypeError(t, 'function must return a value', d);
|
|
388
|
-
}
|
|
389
|
-
assertScalarTypesEqual(t.args[1], ret[0]);
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
throw new utils_1.MichelsonTypeError(t, `function expected: ${JSON.stringify(d)}`, d);
|
|
393
|
-
case 'map':
|
|
394
|
-
case 'big_map':
|
|
395
|
-
if (Array.isArray(d)) {
|
|
396
|
-
//let prev: MichelsonMapElt | undefined;
|
|
397
|
-
for (const v of d) {
|
|
398
|
-
if (!('prim' in v) || v.prim !== 'Elt') {
|
|
399
|
-
throw new utils_1.MichelsonTypeError(t, `map elements expected: ${JSON.stringify(d)}`, d);
|
|
400
|
-
}
|
|
401
|
-
assertDataValidInternal(v.args[0], t.args[0], ctx);
|
|
402
|
-
assertDataValidInternal(v.args[1], t.args[1], ctx);
|
|
403
|
-
}
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
throw new utils_1.MichelsonTypeError(t, `${t.prim} expected: ${JSON.stringify(d)}`, d);
|
|
407
|
-
case 'bls12_381_fr':
|
|
408
|
-
if (('int' in d && (0, utils_1.isDecimal)(d.int)) || ('bytes' in d && (0, utils_1.parseBytes)(d.bytes) !== null)) {
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
throw new utils_1.MichelsonTypeError(t, `BLS12-381 element expected: ${JSON.stringify(d)}`, d);
|
|
412
|
-
case 'sapling_state':
|
|
413
|
-
if (Array.isArray(d)) {
|
|
414
|
-
return;
|
|
415
|
-
}
|
|
416
|
-
throw new utils_1.MichelsonTypeError(t, `sapling state expected: ${JSON.stringify(d)}`, d);
|
|
417
|
-
case 'ticket':
|
|
418
|
-
if ('prim' in d && d.prim === 'Ticket') {
|
|
419
|
-
assertDataValidInternal(d.args[0], { prim: 'address' }, ctx);
|
|
420
|
-
assertTypesEqual(d.args[1], t.args[0]);
|
|
421
|
-
assertDataValidInternal(d.args[2], t.args[0], ctx);
|
|
422
|
-
assertDataValidInternal(d.args[3], { prim: 'nat' }, ctx);
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
else if ((0, utils_1.isPairData)(d)) {
|
|
426
|
-
// backward compatibility
|
|
427
|
-
assertDataValidInternal(d, {
|
|
428
|
-
prim: 'pair',
|
|
429
|
-
args: [{ prim: 'address' }, t.args[0], { prim: 'nat' }],
|
|
430
|
-
}, ctx);
|
|
431
|
-
return;
|
|
432
|
-
}
|
|
433
|
-
throw new utils_1.MichelsonTypeError(t, `ticket expected: ${JSON.stringify(d)}`, d);
|
|
434
|
-
default:
|
|
435
|
-
throw new utils_1.MichelsonTypeError(t, `type ${typeID(t)} don't have Michelson literal representation`, d);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
function instructionListType(inst, stack, ctx) {
|
|
439
|
-
let ret = stack;
|
|
440
|
-
let s = stack;
|
|
441
|
-
let i = 0;
|
|
442
|
-
for (const op of inst) {
|
|
443
|
-
const ft = functionTypeInternal(op, s, ctx);
|
|
444
|
-
ret = ft;
|
|
445
|
-
if ('failed' in ft) {
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
s = ft;
|
|
449
|
-
i++;
|
|
450
|
-
}
|
|
451
|
-
if ('failed' in ret &&
|
|
452
|
-
ret.level == 0 &&
|
|
453
|
-
(!('prim' in ret.failed) || ret.failed.prim !== 'never') &&
|
|
454
|
-
i !== inst.length - 1) {
|
|
455
|
-
throw new MichelsonInstructionError(inst, ret, 'FAIL must appear in a tail position');
|
|
456
|
-
}
|
|
457
|
-
if (ctx?.traceCallback !== undefined) {
|
|
458
|
-
const trace = {
|
|
459
|
-
op: inst,
|
|
460
|
-
in: stack,
|
|
461
|
-
out: ret,
|
|
462
|
-
};
|
|
463
|
-
ctx.traceCallback(trace);
|
|
464
|
-
}
|
|
465
|
-
return 'failed' in ret ? { failed: ret.failed, level: ret.level + 1 } : ret;
|
|
466
|
-
}
|
|
467
|
-
function functionTypeInternal(inst, stack, ctx) {
|
|
468
|
-
const proto = ctx?.protocol || michelson_types_1.DefaultProtocol;
|
|
469
|
-
if (Array.isArray(inst)) {
|
|
470
|
-
return instructionListType(inst, stack, ctx);
|
|
471
|
-
}
|
|
472
|
-
const instruction = inst; // Make it const for type guarding
|
|
473
|
-
// make sure the stack has enough number of arguments of specific types
|
|
474
|
-
function args(n, ...typeIds) {
|
|
475
|
-
if (stack.length < typeIds.length + n) {
|
|
476
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: stack must have at least ${typeIds.length} element(s)`);
|
|
477
|
-
}
|
|
478
|
-
let i = n;
|
|
479
|
-
for (const ids of typeIds) {
|
|
480
|
-
if (ids !== null && ids.length !== 0) {
|
|
481
|
-
let ii = 0;
|
|
482
|
-
while (ii < ids.length && ids[ii] !== typeID(stack[i])) {
|
|
483
|
-
ii++;
|
|
484
|
-
}
|
|
485
|
-
if (ii === ids.length) {
|
|
486
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: stack type mismatch: [${i}] expected to be ${ids}, got ${typeID(stack[i])} instead`);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
i++;
|
|
490
|
-
}
|
|
491
|
-
return stack.slice(n, typeIds.length + n);
|
|
492
|
-
}
|
|
493
|
-
function rethrow(fn) {
|
|
494
|
-
return (...args) => {
|
|
495
|
-
try {
|
|
496
|
-
return fn(...args);
|
|
497
|
-
}
|
|
498
|
-
catch (err) {
|
|
499
|
-
if (err instanceof utils_1.MichelsonError) {
|
|
500
|
-
throw new MichelsonInstructionError(instruction, stack, err.message);
|
|
501
|
-
}
|
|
502
|
-
else {
|
|
503
|
-
throw err;
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
function rethrowTypeGuard(fn) {
|
|
509
|
-
return (arg) => {
|
|
510
|
-
try {
|
|
511
|
-
return fn(arg);
|
|
512
|
-
}
|
|
513
|
-
catch (err) {
|
|
514
|
-
if (err instanceof utils_1.MichelsonError) {
|
|
515
|
-
throw new MichelsonInstructionError(instruction, stack, err.message);
|
|
516
|
-
}
|
|
517
|
-
else {
|
|
518
|
-
throw err;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
};
|
|
522
|
-
}
|
|
523
|
-
const argAnn = rethrow(utils_1.unpackAnnotations);
|
|
524
|
-
const ensureStacksEqual = rethrow(assertStacksEqual);
|
|
525
|
-
const ensureTypesEqual = rethrow(assertScalarTypesEqual);
|
|
526
|
-
const ensureComparableType = rethrowTypeGuard(michelson_validator_1.assertMichelsonComparableType);
|
|
527
|
-
const ensurePackableType = rethrowTypeGuard(michelson_validator_1.assertMichelsonPackableType);
|
|
528
|
-
const ensureStorableType = rethrowTypeGuard(michelson_validator_1.assertMichelsonStorableType);
|
|
529
|
-
const ensurePushableType = rethrowTypeGuard(michelson_validator_1.assertMichelsonPushableType);
|
|
530
|
-
const ensureBigMapStorableType = rethrowTypeGuard(michelson_validator_1.assertMichelsonBigMapStorableType);
|
|
531
|
-
// unpack instruction annotations and assert their maximum number
|
|
532
|
-
function instructionAnn(num, opt) {
|
|
533
|
-
const a = argAnn(instruction, {
|
|
534
|
-
...opt,
|
|
535
|
-
emptyFields: num.f !== undefined && num.f > 1,
|
|
536
|
-
emptyVar: num.v !== undefined && num.v > 1,
|
|
537
|
-
});
|
|
538
|
-
const assertNum = (a, n, type) => {
|
|
539
|
-
if (a && a.length > (n || 0)) {
|
|
540
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: at most ${n || 0} ${type} annotations allowed`);
|
|
541
|
-
}
|
|
542
|
-
};
|
|
543
|
-
assertNum(a.f, num.f, 'field');
|
|
544
|
-
assertNum(a.t, num.t, 'type');
|
|
545
|
-
assertNum(a.v, num.v, 'variable');
|
|
546
|
-
return a;
|
|
547
|
-
}
|
|
548
|
-
// also keeps annotation class if null is provided
|
|
549
|
-
function annotate(tt, a) {
|
|
550
|
-
const tx = tt;
|
|
551
|
-
const t = Array.isArray(tx) ? { prim: 'pair', args: tx } : tx;
|
|
552
|
-
const src = argAnn(t);
|
|
553
|
-
const ann = a.v !== undefined || a.t !== undefined || a.f !== undefined
|
|
554
|
-
? [
|
|
555
|
-
...((a.v === null ? src.v : a.v) || []),
|
|
556
|
-
...((a.t === null ? src.t : a.t) || []),
|
|
557
|
-
...((a.f === null ? src.f : a.f) || []),
|
|
558
|
-
]
|
|
559
|
-
: undefined;
|
|
560
|
-
const { annots: _annots, ...rest } = t;
|
|
561
|
-
return { ...rest, ...(ann && ann.length !== 0 && { annots: ann }) };
|
|
562
|
-
}
|
|
563
|
-
// shortcut to copy at most one variable annotation from the instruction to the type
|
|
564
|
-
function annotateVar(t, def) {
|
|
565
|
-
const ia = instructionAnn({ v: 1 });
|
|
566
|
-
return annotate(t, {
|
|
567
|
-
v: ia.v !== undefined ? ia.v : def !== undefined ? [def] : null,
|
|
568
|
-
t: null,
|
|
569
|
-
});
|
|
570
|
-
}
|
|
571
|
-
// annotate CAR/CDR/UNPAIR/GET
|
|
572
|
-
function annotateField(arg, field, insAnn, n, defField) {
|
|
573
|
-
const fieldAnn = argAnn(field).f?.[0]; // field's field annotation
|
|
574
|
-
const insFieldAnn = insAnn.f?.[n];
|
|
575
|
-
if (insFieldAnn !== undefined &&
|
|
576
|
-
insFieldAnn !== '%' &&
|
|
577
|
-
fieldAnn !== undefined &&
|
|
578
|
-
insFieldAnn !== fieldAnn) {
|
|
579
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: field names doesn't match: ${insFieldAnn} !== ${fieldAnn}`);
|
|
580
|
-
}
|
|
581
|
-
const insVarAnn = insAnn.v?.[n]; // nth instruction's variable annotation
|
|
582
|
-
const varAnn = argAnn(arg).v?.[0]; // instruction argument's variable annotation
|
|
583
|
-
return annotate(field, {
|
|
584
|
-
t: null,
|
|
585
|
-
v: insVarAnn
|
|
586
|
-
? insVarAnn === '@%'
|
|
587
|
-
? fieldAnn
|
|
588
|
-
? ['@' + fieldAnn.slice(1)]
|
|
589
|
-
: undefined
|
|
590
|
-
: insVarAnn === '@%%'
|
|
591
|
-
? varAnn
|
|
592
|
-
? ['@' + varAnn.slice(1) + '.' + (fieldAnn ? fieldAnn.slice(1) : defField)]
|
|
593
|
-
: fieldAnn
|
|
594
|
-
? ['@' + fieldAnn.slice(1)]
|
|
595
|
-
: undefined
|
|
596
|
-
: [insVarAnn]
|
|
597
|
-
: null,
|
|
598
|
-
});
|
|
599
|
-
}
|
|
600
|
-
// comb helper functions
|
|
601
|
-
function getN(src, n, i = n) {
|
|
602
|
-
const p = (0, utils_1.unpackComb)('pair', src);
|
|
603
|
-
if (i === 1) {
|
|
604
|
-
return [p.args[0]];
|
|
605
|
-
}
|
|
606
|
-
else if (i === 2) {
|
|
607
|
-
return p.args;
|
|
608
|
-
}
|
|
609
|
-
const right = p.args[1];
|
|
610
|
-
if ((0, utils_1.isPairType)(right)) {
|
|
611
|
-
return [p.args[0], ...getN(right, n, i - 1)];
|
|
612
|
-
}
|
|
613
|
-
else {
|
|
614
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: at least ${n} fields are expected`);
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
function getNth(src, n, i = n) {
|
|
618
|
-
if (i === 0) {
|
|
619
|
-
return src;
|
|
620
|
-
}
|
|
621
|
-
const p = (0, utils_1.unpackComb)('pair', src);
|
|
622
|
-
if (i === 1) {
|
|
623
|
-
return p.args[0];
|
|
624
|
-
}
|
|
625
|
-
const right = p.args[1];
|
|
626
|
-
if ((0, utils_1.isPairType)(right)) {
|
|
627
|
-
return getNth(right, n, i - 2);
|
|
628
|
-
}
|
|
629
|
-
else if (i === 2) {
|
|
630
|
-
return right;
|
|
631
|
-
}
|
|
632
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: at least ${n + 1} fields are expected`);
|
|
633
|
-
}
|
|
634
|
-
function updateNth(src, x, n, i = n) {
|
|
635
|
-
if (i === 0) {
|
|
636
|
-
return x;
|
|
637
|
-
}
|
|
638
|
-
const p = (0, utils_1.unpackComb)('pair', src);
|
|
639
|
-
if (i === 1) {
|
|
640
|
-
return {
|
|
641
|
-
...p,
|
|
642
|
-
args: [x, p.args[1]],
|
|
643
|
-
};
|
|
644
|
-
}
|
|
645
|
-
const right = p.args[1];
|
|
646
|
-
if ((0, utils_1.isPairType)(right)) {
|
|
647
|
-
return {
|
|
648
|
-
...p,
|
|
649
|
-
args: [p.args[0], updateNth(right, x, n, i - 2)],
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
else if (i === 2) {
|
|
653
|
-
return {
|
|
654
|
-
...p,
|
|
655
|
-
args: [p.args[0], x],
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: at least ${n + 1} fields are expected`);
|
|
659
|
-
}
|
|
660
|
-
const varSuffix = (a, suffix) => [
|
|
661
|
-
'@' + (a.v ? a.v[0].slice(1) + '.' : '') + suffix,
|
|
662
|
-
];
|
|
663
|
-
function branchType(br0, br1) {
|
|
664
|
-
if ('failed' in br0 || 'failed' in br1) {
|
|
665
|
-
return 'failed' in br0 ? br1 : br0;
|
|
666
|
-
}
|
|
667
|
-
else {
|
|
668
|
-
ensureStacksEqual(br0, br1);
|
|
669
|
-
return br0;
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
const retStack = ((instruction) => {
|
|
673
|
-
switch (instruction.prim) {
|
|
674
|
-
case 'DUP': {
|
|
675
|
-
const n = instruction.args ? parseInt(instruction.args[0].int, 10) : 1;
|
|
676
|
-
if (n === 0) {
|
|
677
|
-
throw new MichelsonInstructionError(instruction, stack, 'DUP 0 is forbidden');
|
|
678
|
-
}
|
|
679
|
-
const s = args(n - 1, null)[0];
|
|
680
|
-
if (typeID(s) === 'ticket') {
|
|
681
|
-
throw new MichelsonInstructionError(instruction, stack, "ticket can't be DUPed");
|
|
682
|
-
}
|
|
683
|
-
return [s, ...stack];
|
|
684
|
-
}
|
|
685
|
-
case 'SWAP': {
|
|
686
|
-
const s = args(0, null, null);
|
|
687
|
-
instructionAnn({});
|
|
688
|
-
return [s[1], s[0], ...stack.slice(2)];
|
|
689
|
-
}
|
|
690
|
-
case 'SOME':
|
|
691
|
-
return [
|
|
692
|
-
annotate({ prim: 'option', args: [args(0, null)[0]] }, instructionAnn({ t: 1, v: 1 })),
|
|
693
|
-
...stack.slice(1),
|
|
694
|
-
];
|
|
695
|
-
case 'UNIT':
|
|
696
|
-
return [annotate({ prim: 'unit' }, instructionAnn({ v: 1, t: 1 })), ...stack];
|
|
697
|
-
case 'PAIR': {
|
|
698
|
-
const n = instruction.args ? parseInt(instruction.args[0].int, 10) : 2;
|
|
699
|
-
if (n < 2) {
|
|
700
|
-
throw new MichelsonInstructionError(instruction, stack, `PAIR ${n} is forbidden`);
|
|
701
|
-
}
|
|
702
|
-
const s = args(0, ...new Array(n).fill(null));
|
|
703
|
-
const ia = instructionAnn({ f: n, t: 1, v: 1 }, { specialFields: true });
|
|
704
|
-
const trim = (s) => {
|
|
705
|
-
const i = s.lastIndexOf('.');
|
|
706
|
-
return s.slice(i > 0 ? i + 1 : 1);
|
|
707
|
-
};
|
|
708
|
-
const retArgs = s.map((v, i) => {
|
|
709
|
-
const va = argAnn(v);
|
|
710
|
-
const f = ia.f && ia.f.length > i && ia.f[i] !== '%'
|
|
711
|
-
? ia.f[i] === '%@'
|
|
712
|
-
? va.v
|
|
713
|
-
? ['%' + trim(va.v?.[0] || '')]
|
|
714
|
-
: undefined
|
|
715
|
-
: [ia.f[i]]
|
|
716
|
-
: undefined;
|
|
717
|
-
return annotate(v, { v: null, t: null, f });
|
|
718
|
-
});
|
|
719
|
-
return [
|
|
720
|
-
annotate({
|
|
721
|
-
prim: 'pair',
|
|
722
|
-
args: retArgs,
|
|
723
|
-
}, { t: ia.t, v: ia.v }),
|
|
724
|
-
...stack.slice(n),
|
|
725
|
-
];
|
|
726
|
-
}
|
|
727
|
-
case 'UNPAIR': {
|
|
728
|
-
const n = instruction.args ? parseInt(instruction.args[0].int, 10) : 2;
|
|
729
|
-
if (n < 2) {
|
|
730
|
-
throw new MichelsonInstructionError(instruction, stack, `UNPAIR ${n} is forbidden`);
|
|
731
|
-
}
|
|
732
|
-
const s = args(0, ['pair'])[0];
|
|
733
|
-
const ia = instructionAnn({ f: 2, v: 2 }, { specialVar: true });
|
|
734
|
-
const fields = getN(s, n);
|
|
735
|
-
return [
|
|
736
|
-
...fields.map((field, i) => annotateField(s, field, ia, i, i === 0 ? 'car' : 'cdr')),
|
|
737
|
-
...stack.slice(1),
|
|
738
|
-
];
|
|
739
|
-
}
|
|
740
|
-
case 'CAR':
|
|
741
|
-
case 'CDR': {
|
|
742
|
-
const s = (0, utils_1.unpackComb)('pair', args(0, ['pair'])[0]);
|
|
743
|
-
const field = s.args[instruction.prim === 'CAR' ? 0 : 1];
|
|
744
|
-
const ia = instructionAnn({ f: 1, v: 1 }, { specialVar: true });
|
|
745
|
-
return [
|
|
746
|
-
annotateField(s, field, ia, 0, instruction.prim.toLocaleLowerCase()),
|
|
747
|
-
...stack.slice(1),
|
|
748
|
-
];
|
|
749
|
-
}
|
|
750
|
-
case 'CONS': {
|
|
751
|
-
const s = args(0, null, ['list']);
|
|
752
|
-
ensureTypesEqual(s[0], s[1].args[0]);
|
|
753
|
-
return [annotateVar({ prim: 'list', args: [s[1].args[0]] }), ...stack.slice(2)];
|
|
754
|
-
}
|
|
755
|
-
case 'SIZE':
|
|
756
|
-
args(0, ['string', 'list', 'set', 'map', 'bytes']);
|
|
757
|
-
return [annotateVar({ prim: 'nat' }), ...stack.slice(1)];
|
|
758
|
-
case 'MEM': {
|
|
759
|
-
const s = args(0, null, ['set', 'map', 'big_map']);
|
|
760
|
-
ensureComparableType(s[0]);
|
|
761
|
-
ensureTypesEqual(s[0], s[1].args[0]);
|
|
762
|
-
return [annotateVar({ prim: 'bool' }), ...stack.slice(2)];
|
|
763
|
-
}
|
|
764
|
-
case 'GET':
|
|
765
|
-
if (instruction.args) {
|
|
766
|
-
// comb operation
|
|
767
|
-
const n = parseInt(instruction.args[0].int, 10);
|
|
768
|
-
const s = args(0, ['pair'])[0];
|
|
769
|
-
return [annotateVar(getNth(s, n)), ...stack.slice(1)];
|
|
770
|
-
}
|
|
771
|
-
else {
|
|
772
|
-
// map operation
|
|
773
|
-
const s = args(0, null, ['map', 'big_map']);
|
|
774
|
-
ensureComparableType(s[0]);
|
|
775
|
-
ensureTypesEqual(s[0], s[1].args[0]);
|
|
776
|
-
return [annotateVar({ prim: 'option', args: [s[1].args[1]] }), ...stack.slice(2)];
|
|
777
|
-
}
|
|
778
|
-
case 'UPDATE':
|
|
779
|
-
if (instruction.args) {
|
|
780
|
-
// comb operation
|
|
781
|
-
const n = parseInt(instruction.args[0].int, 10);
|
|
782
|
-
const s = args(0, null, ['pair']);
|
|
783
|
-
return [annotateVar(updateNth(s[1], s[0], n)), ...stack.slice(2)];
|
|
784
|
-
}
|
|
785
|
-
else {
|
|
786
|
-
// map operation
|
|
787
|
-
const s0 = args(0, null, ['bool', 'option']);
|
|
788
|
-
ensureComparableType(s0[0]);
|
|
789
|
-
if (s0[1].prim === 'bool') {
|
|
790
|
-
const s1 = args(2, ['set']);
|
|
791
|
-
ensureTypesEqual(s0[0], s1[0].args[0]);
|
|
792
|
-
return [
|
|
793
|
-
annotateVar({
|
|
794
|
-
prim: 'set',
|
|
795
|
-
args: [annotate(s0[0], { t: null })],
|
|
796
|
-
}),
|
|
797
|
-
...stack.slice(3),
|
|
798
|
-
];
|
|
799
|
-
}
|
|
800
|
-
const s1 = args(2, ['map', 'big_map']);
|
|
801
|
-
ensureTypesEqual(s0[0], s1[0].args[0]);
|
|
802
|
-
if (s1[0].prim === 'map') {
|
|
803
|
-
return [
|
|
804
|
-
annotateVar({
|
|
805
|
-
prim: 'map',
|
|
806
|
-
args: [annotate(s0[0], { t: null }), annotate(s0[1].args[0], { t: null })],
|
|
807
|
-
}),
|
|
808
|
-
...stack.slice(3),
|
|
809
|
-
];
|
|
810
|
-
}
|
|
811
|
-
ensureBigMapStorableType(s0[1].args[0]);
|
|
812
|
-
return [
|
|
813
|
-
annotateVar({
|
|
814
|
-
prim: 'big_map',
|
|
815
|
-
args: [annotate(s0[0], { t: null }), annotate(s0[1].args[0], { t: null })],
|
|
816
|
-
}),
|
|
817
|
-
...stack.slice(3),
|
|
818
|
-
];
|
|
819
|
-
}
|
|
820
|
-
case 'GET_AND_UPDATE': {
|
|
821
|
-
const ia = instructionAnn({ v: 2 });
|
|
822
|
-
const s = args(0, null, ['option'], ['map', 'big_map']);
|
|
823
|
-
ensureComparableType(s[0]);
|
|
824
|
-
ensureTypesEqual(s[0], s[2].args[0]);
|
|
825
|
-
ensureTypesEqual(s[1].args[0], s[2].args[1]);
|
|
826
|
-
const va = ia.v?.map((v) => (v !== '@' ? [v] : undefined));
|
|
827
|
-
if (s[2].prim === 'map') {
|
|
828
|
-
return [
|
|
829
|
-
annotate({ prim: 'option', args: [s[2].args[1]] }, { v: va?.[0] }),
|
|
830
|
-
annotate({
|
|
831
|
-
prim: 'map',
|
|
832
|
-
args: [annotate(s[0], { t: null }), annotate(s[1].args[0], { t: null })],
|
|
833
|
-
}, { v: va?.[1] }),
|
|
834
|
-
...stack.slice(3),
|
|
835
|
-
];
|
|
836
|
-
}
|
|
837
|
-
ensureBigMapStorableType(s[1].args[0]);
|
|
838
|
-
return [
|
|
839
|
-
annotate({ prim: 'option', args: [s[2].args[1]] }, { v: va?.[0] }),
|
|
840
|
-
annotate({
|
|
841
|
-
prim: 'big_map',
|
|
842
|
-
args: [annotate(s[0], { t: null }), annotate(s[1].args[0], { t: null })],
|
|
843
|
-
}, { v: va?.[1] }),
|
|
844
|
-
...stack.slice(3),
|
|
845
|
-
];
|
|
846
|
-
}
|
|
847
|
-
case 'EXEC': {
|
|
848
|
-
const s = args(0, null, ['lambda']);
|
|
849
|
-
ensureTypesEqual(s[0], s[1].args[0]);
|
|
850
|
-
return [annotateVar(s[1].args[1]), ...stack.slice(2)];
|
|
851
|
-
}
|
|
852
|
-
case 'APPLY': {
|
|
853
|
-
const s = args(0, null, ['lambda']);
|
|
854
|
-
ensureStorableType(s[0]);
|
|
855
|
-
ensurePushableType(s[0]);
|
|
856
|
-
if (!(0, utils_1.isPairType)(s[1].args[0])) {
|
|
857
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: function's argument must be a pair: ${typeID(s[1].args[0])}`);
|
|
858
|
-
}
|
|
859
|
-
const pt = s[1].args[0];
|
|
860
|
-
ensureTypesEqual(s[0], typeArgs(pt)[0]);
|
|
861
|
-
return [
|
|
862
|
-
annotateVar({ prim: 'lambda', args: [typeArgs(pt)[1], s[1].args[1]] }),
|
|
863
|
-
...stack.slice(2),
|
|
864
|
-
];
|
|
865
|
-
}
|
|
866
|
-
case 'FAILWITH': {
|
|
867
|
-
const s = args(0, null)[0];
|
|
868
|
-
if (!(0, michelson_types_1.ProtoInferiorTo)(proto, michelson_types_1.Protocol.PtEdo2Zk)) {
|
|
869
|
-
ensurePackableType(s);
|
|
870
|
-
}
|
|
871
|
-
return { failed: s, level: 0 };
|
|
872
|
-
}
|
|
873
|
-
case 'NEVER':
|
|
874
|
-
args(0, ['never']);
|
|
875
|
-
return { failed: { prim: 'never' }, level: 0 };
|
|
876
|
-
case 'RENAME':
|
|
877
|
-
return [annotateVar(args(0, null)[0]), ...stack.slice(1)];
|
|
878
|
-
case 'CONCAT': {
|
|
879
|
-
const s0 = args(0, ['string', 'list', 'bytes']);
|
|
880
|
-
if (s0[0].prim === 'list') {
|
|
881
|
-
if (typeID(s0[0].args[0]) !== 'string' && typeID(s0[0].args[0]) !== 'bytes') {
|
|
882
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: can't concatenate list of ${typeID(s0[0].args[0])}'s`);
|
|
883
|
-
}
|
|
884
|
-
return [annotateVar(s0[0].args[0]), ...stack.slice(1)];
|
|
885
|
-
}
|
|
886
|
-
const s1 = args(1, ['string', 'bytes']);
|
|
887
|
-
if (s0[0].prim !== s1[0].prim) {
|
|
888
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: can't concatenate ${s0[0].prim} with ${s1[0].prim}`);
|
|
889
|
-
}
|
|
890
|
-
return [annotateVar(s1[0]), ...stack.slice(2)];
|
|
891
|
-
}
|
|
892
|
-
case 'SLICE':
|
|
893
|
-
return [
|
|
894
|
-
annotateVar({ prim: 'option', args: [args(0, ['nat'], ['nat'], ['string', 'bytes'])[2]] }, '@slice'),
|
|
895
|
-
...stack.slice(3),
|
|
896
|
-
];
|
|
897
|
-
case 'PACK': {
|
|
898
|
-
const s = args(0, null)[0];
|
|
899
|
-
ensurePackableType(s);
|
|
900
|
-
return [annotateVar({ prim: 'bytes' }, '@packed'), ...stack.slice(1)];
|
|
901
|
-
}
|
|
902
|
-
case 'ADD': {
|
|
903
|
-
const s = args(0, ['nat', 'int', 'timestamp', 'mutez', 'bls12_381_g1', 'bls12_381_g2', 'bls12_381_fr'], ['nat', 'int', 'timestamp', 'mutez', 'bls12_381_g1', 'bls12_381_g2', 'bls12_381_fr']);
|
|
904
|
-
if ((s[0].prim === 'nat' && s[1].prim === 'int') ||
|
|
905
|
-
(s[0].prim === 'int' && s[1].prim === 'nat')) {
|
|
906
|
-
return [annotateVar({ prim: 'int' }), ...stack.slice(2)];
|
|
907
|
-
}
|
|
908
|
-
else if ((s[0].prim === 'int' && s[1].prim === 'timestamp') ||
|
|
909
|
-
(s[0].prim === 'timestamp' && s[1].prim === 'int')) {
|
|
910
|
-
return [annotateVar({ prim: 'timestamp' }), ...stack.slice(2)];
|
|
911
|
-
}
|
|
912
|
-
else if ((s[0].prim === 'int' ||
|
|
913
|
-
s[0].prim === 'nat' ||
|
|
914
|
-
s[0].prim === 'mutez' ||
|
|
915
|
-
s[0].prim === 'bls12_381_g1' ||
|
|
916
|
-
s[0].prim === 'bls12_381_g2' ||
|
|
917
|
-
s[0].prim === 'bls12_381_fr') &&
|
|
918
|
-
s[0].prim === s[1].prim) {
|
|
919
|
-
return [annotateVar(s[0]), ...stack.slice(2)];
|
|
920
|
-
}
|
|
921
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: can't add ${s[0].prim} to ${s[1].prim}`);
|
|
922
|
-
}
|
|
923
|
-
case 'SUB': {
|
|
924
|
-
const s = (0, michelson_types_1.ProtoInferiorTo)(proto, michelson_types_1.Protocol.PsiThaCa)
|
|
925
|
-
? args(0, ['nat', 'int', 'timestamp', 'mutez'], ['nat', 'int', 'timestamp', 'mutez'])
|
|
926
|
-
: args(0, ['nat', 'int', 'timestamp'], ['nat', 'int', 'timestamp']);
|
|
927
|
-
if (((s[0].prim === 'nat' || s[0].prim === 'int') &&
|
|
928
|
-
(s[1].prim === 'nat' || s[1].prim === 'int')) ||
|
|
929
|
-
(s[0].prim === 'timestamp' && s[1].prim === 'timestamp')) {
|
|
930
|
-
return [annotateVar({ prim: 'int' }), ...stack.slice(2)];
|
|
931
|
-
}
|
|
932
|
-
else if (s[0].prim === 'timestamp' && s[1].prim === 'int') {
|
|
933
|
-
return [annotateVar({ prim: 'timestamp' }), ...stack.slice(2)];
|
|
934
|
-
}
|
|
935
|
-
else if (s[0].prim === 'mutez' && s[1].prim === 'mutez') {
|
|
936
|
-
return [annotateVar({ prim: 'mutez' }), ...stack.slice(2)];
|
|
937
|
-
}
|
|
938
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: can't subtract ${s[0].prim} from ${s[1].prim}`);
|
|
939
|
-
}
|
|
940
|
-
case 'SUB_MUTEZ': {
|
|
941
|
-
const _s = args(0, ['mutez'], ['mutez']);
|
|
942
|
-
return [annotateVar({ prim: 'option', args: [{ prim: 'mutez' }] }), ...stack.slice(2)];
|
|
943
|
-
}
|
|
944
|
-
case 'MUL': {
|
|
945
|
-
const s = args(0, ['nat', 'int', 'mutez', 'bls12_381_g1', 'bls12_381_g2', 'bls12_381_fr'], ['nat', 'int', 'mutez', 'bls12_381_g1', 'bls12_381_g2', 'bls12_381_fr']);
|
|
946
|
-
if ((s[0].prim === 'nat' && s[1].prim === 'int') ||
|
|
947
|
-
(s[0].prim === 'int' && s[1].prim === 'nat')) {
|
|
948
|
-
return [annotateVar({ prim: 'int' }), ...stack.slice(2)];
|
|
949
|
-
}
|
|
950
|
-
else if ((s[0].prim === 'nat' && s[1].prim === 'mutez') ||
|
|
951
|
-
(s[0].prim === 'mutez' && s[1].prim === 'nat')) {
|
|
952
|
-
return [annotateVar({ prim: 'mutez' }), ...stack.slice(2)];
|
|
953
|
-
}
|
|
954
|
-
else if (((s[0].prim === 'bls12_381_g1' ||
|
|
955
|
-
s[0].prim === 'bls12_381_g2' ||
|
|
956
|
-
s[0].prim === 'bls12_381_fr') &&
|
|
957
|
-
s[1].prim === 'bls12_381_fr') ||
|
|
958
|
-
((s[0].prim === 'nat' || s[0].prim === 'int') && s[0].prim === s[1].prim)) {
|
|
959
|
-
return [annotateVar(s[0]), ...stack.slice(2)];
|
|
960
|
-
}
|
|
961
|
-
else if (((s[0].prim === 'nat' || s[0].prim === 'int') && s[1].prim === 'bls12_381_fr') ||
|
|
962
|
-
((s[1].prim === 'nat' || s[1].prim === 'int') && s[0].prim === 'bls12_381_fr')) {
|
|
963
|
-
return [annotateVar({ prim: 'bls12_381_fr' }), ...stack.slice(2)];
|
|
964
|
-
}
|
|
965
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: can't multiply ${s[0].prim} by ${s[1].prim}`);
|
|
966
|
-
}
|
|
967
|
-
case 'EDIV': {
|
|
968
|
-
const res = (a, b) => ({
|
|
969
|
-
prim: 'option',
|
|
970
|
-
args: [{ prim: 'pair', args: [{ prim: a }, { prim: b }] }],
|
|
971
|
-
});
|
|
972
|
-
const s = args(0, ['nat', 'int', 'mutez'], ['nat', 'int', 'mutez']);
|
|
973
|
-
if (s[0].prim === 'nat' && s[1].prim === 'nat') {
|
|
974
|
-
return [annotateVar(res('nat', 'nat')), ...stack.slice(2)];
|
|
975
|
-
}
|
|
976
|
-
else if ((s[0].prim === 'nat' || s[0].prim === 'int') &&
|
|
977
|
-
(s[1].prim === 'nat' || s[1].prim === 'int')) {
|
|
978
|
-
return [annotateVar(res('int', 'nat')), ...stack.slice(2)];
|
|
979
|
-
}
|
|
980
|
-
else if (s[0].prim === 'mutez' && s[1].prim === 'nat') {
|
|
981
|
-
return [annotateVar(res('mutez', 'mutez')), ...stack.slice(2)];
|
|
982
|
-
}
|
|
983
|
-
else if (s[0].prim === 'mutez' && s[1].prim === 'mutez') {
|
|
984
|
-
return [annotateVar(res('nat', 'mutez')), ...stack.slice(2)];
|
|
985
|
-
}
|
|
986
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: can't euclideally divide ${s[0].prim} by ${s[1].prim}`);
|
|
987
|
-
}
|
|
988
|
-
case 'ABS':
|
|
989
|
-
args(0, ['int']);
|
|
990
|
-
return [annotateVar({ prim: 'nat' }), ...stack.slice(1)];
|
|
991
|
-
case 'ISNAT':
|
|
992
|
-
args(0, ['int']);
|
|
993
|
-
return [annotateVar({ prim: 'option', args: [{ prim: 'nat' }] }), ...stack.slice(1)];
|
|
994
|
-
case 'INT':
|
|
995
|
-
args(0, ['nat', 'bls12_381_fr', 'bytes']);
|
|
996
|
-
return [annotateVar({ prim: 'int' }), ...stack.slice(1)];
|
|
997
|
-
case 'BYTES':
|
|
998
|
-
args(0, ['nat', 'int']);
|
|
999
|
-
return [annotateVar({ prim: 'bytes' }), ...stack.slice(1)];
|
|
1000
|
-
case 'NAT':
|
|
1001
|
-
args(0, ['bytes']);
|
|
1002
|
-
return [annotateVar({ prim: 'nat' }), ...stack.slice(1)];
|
|
1003
|
-
case 'NEG': {
|
|
1004
|
-
const s = args(0, ['nat', 'int', 'bls12_381_g1', 'bls12_381_g2', 'bls12_381_fr'])[0];
|
|
1005
|
-
if (s.prim === 'nat' || s.prim === 'int') {
|
|
1006
|
-
return [annotateVar({ prim: 'int' }), ...stack.slice(1)];
|
|
1007
|
-
}
|
|
1008
|
-
return [annotateVar(s), ...stack.slice(1)];
|
|
1009
|
-
}
|
|
1010
|
-
case 'LSL':
|
|
1011
|
-
case 'LSR':
|
|
1012
|
-
args(0, ['nat', 'bytes'], ['nat', 'bytes']);
|
|
1013
|
-
return [annotateVar({ prim: 'nat' }), ...stack.slice(2)];
|
|
1014
|
-
case 'OR':
|
|
1015
|
-
case 'XOR': {
|
|
1016
|
-
const s = args(0, ['nat', 'bytes', 'bool'], ['nat', 'bytes', 'bool']);
|
|
1017
|
-
if (s[0].prim !== s[1].prim) {
|
|
1018
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: both arguments must be of the same type: ${s[0].prim}, ${s[1].prim}`);
|
|
1019
|
-
}
|
|
1020
|
-
return [annotateVar(s[1]), ...stack.slice(2)];
|
|
1021
|
-
}
|
|
1022
|
-
case 'AND': {
|
|
1023
|
-
const s = args(0, ['nat', 'bytes', 'bool', 'int'], ['nat', 'bytes', 'bool']);
|
|
1024
|
-
if ((s[0].prim !== 'int' || s[1].prim !== 'nat') && s[0].prim !== s[1].prim) {
|
|
1025
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: both arguments must be of the same type: ${s[0].prim}, ${s[1].prim}`);
|
|
1026
|
-
}
|
|
1027
|
-
return [annotateVar(s[1]), ...stack.slice(2)];
|
|
1028
|
-
}
|
|
1029
|
-
case 'NOT': {
|
|
1030
|
-
const s = args(0, ['nat', 'bytes', 'bool', 'int'])[0];
|
|
1031
|
-
if (s.prim === 'bool') {
|
|
1032
|
-
return [annotateVar({ prim: 'bool' }), ...stack.slice(1)];
|
|
1033
|
-
}
|
|
1034
|
-
return [annotateVar({ prim: 'int' }), ...stack.slice(1)];
|
|
1035
|
-
}
|
|
1036
|
-
case 'COMPARE': {
|
|
1037
|
-
const s = args(0, null, null);
|
|
1038
|
-
ensureComparableType(s[0]);
|
|
1039
|
-
ensureComparableType(s[1]);
|
|
1040
|
-
return [annotateVar({ prim: 'int' }), ...stack.slice(2)];
|
|
1041
|
-
}
|
|
1042
|
-
case 'EQ':
|
|
1043
|
-
case 'NEQ':
|
|
1044
|
-
case 'LT':
|
|
1045
|
-
case 'GT':
|
|
1046
|
-
case 'LE':
|
|
1047
|
-
case 'GE':
|
|
1048
|
-
args(0, ['int']);
|
|
1049
|
-
return [annotateVar({ prim: 'bool' }), ...stack.slice(1)];
|
|
1050
|
-
case 'SELF': {
|
|
1051
|
-
if (ctx?.contract === undefined) {
|
|
1052
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: contract required`);
|
|
1053
|
-
}
|
|
1054
|
-
const ia = instructionAnn({ f: 1, v: 1 });
|
|
1055
|
-
const ep = contractEntryPoint(ctx.contract, ia.f?.[0]);
|
|
1056
|
-
if (ep === null) {
|
|
1057
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: contract has no entrypoint ${ep}`);
|
|
1058
|
-
}
|
|
1059
|
-
return [
|
|
1060
|
-
annotate({ prim: 'contract', args: [ep] }, { v: ia.v ? ia.v : ['@self'] }),
|
|
1061
|
-
...stack,
|
|
1062
|
-
];
|
|
1063
|
-
}
|
|
1064
|
-
case 'TRANSFER_TOKENS': {
|
|
1065
|
-
const s = args(0, null, ['mutez'], ['contract']);
|
|
1066
|
-
ensureTypesEqual(s[0], s[2].args[0]);
|
|
1067
|
-
return [annotateVar({ prim: 'operation' }), ...stack.slice(3)];
|
|
1068
|
-
}
|
|
1069
|
-
case 'SET_DELEGATE': {
|
|
1070
|
-
const s = args(0, ['option'])[0];
|
|
1071
|
-
if (typeID(s.args[0]) !== 'key_hash') {
|
|
1072
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: key hash expected: ${typeID(s.args[0])}`);
|
|
1073
|
-
}
|
|
1074
|
-
return [annotateVar({ prim: 'operation' }), ...stack.slice(1)];
|
|
1075
|
-
}
|
|
1076
|
-
case 'IMPLICIT_ACCOUNT':
|
|
1077
|
-
args(0, ['key_hash']);
|
|
1078
|
-
return [annotateVar({ prim: 'contract', args: [{ prim: 'unit' }] }), ...stack.slice(1)];
|
|
1079
|
-
case 'NOW':
|
|
1080
|
-
return [annotateVar({ prim: 'timestamp' }, '@now'), ...stack];
|
|
1081
|
-
case 'AMOUNT':
|
|
1082
|
-
return [annotateVar({ prim: 'mutez' }, '@amount'), ...stack];
|
|
1083
|
-
case 'BALANCE':
|
|
1084
|
-
return [annotateVar({ prim: 'mutez' }, '@balance'), ...stack];
|
|
1085
|
-
case 'CHECK_SIGNATURE':
|
|
1086
|
-
args(0, ['key'], ['signature'], ['bytes']);
|
|
1087
|
-
return [annotateVar({ prim: 'bool' }), ...stack.slice(3)];
|
|
1088
|
-
case 'BLAKE2B':
|
|
1089
|
-
case 'SHA256':
|
|
1090
|
-
case 'SHA512':
|
|
1091
|
-
case 'KECCAK':
|
|
1092
|
-
case 'SHA3':
|
|
1093
|
-
args(0, ['bytes']);
|
|
1094
|
-
return [annotateVar({ prim: 'bytes' }), ...stack.slice(1)];
|
|
1095
|
-
case 'HASH_KEY':
|
|
1096
|
-
args(0, ['key']);
|
|
1097
|
-
return [annotateVar({ prim: 'key_hash' }), ...stack.slice(1)];
|
|
1098
|
-
case 'SOURCE':
|
|
1099
|
-
return [annotateVar({ prim: 'address' }, '@source'), ...stack];
|
|
1100
|
-
case 'SENDER':
|
|
1101
|
-
return [annotateVar({ prim: 'address' }, '@sender'), ...stack];
|
|
1102
|
-
case 'ADDRESS': {
|
|
1103
|
-
const s = args(0, ['contract'])[0];
|
|
1104
|
-
const ia = instructionAnn({ v: 1 });
|
|
1105
|
-
return [
|
|
1106
|
-
annotate({ prim: 'address', [michelson_types_1.refContract]: s }, { v: ia.v ? ia.v : varSuffix(argAnn(s), 'address') }),
|
|
1107
|
-
...stack.slice(1),
|
|
1108
|
-
];
|
|
1109
|
-
}
|
|
1110
|
-
case 'SELF_ADDRESS': {
|
|
1111
|
-
const addr = { prim: 'address' };
|
|
1112
|
-
if (ctx?.contract !== undefined) {
|
|
1113
|
-
addr[michelson_types_1.refContract] = {
|
|
1114
|
-
prim: 'contract',
|
|
1115
|
-
args: [contractSection(ctx.contract, 'parameter').args[0]],
|
|
1116
|
-
};
|
|
1117
|
-
}
|
|
1118
|
-
return [annotateVar(addr, '@address'), ...stack];
|
|
1119
|
-
}
|
|
1120
|
-
case 'CHAIN_ID':
|
|
1121
|
-
return [annotateVar({ prim: 'chain_id' }), ...stack];
|
|
1122
|
-
case 'DROP': {
|
|
1123
|
-
instructionAnn({});
|
|
1124
|
-
const n = instruction.args !== undefined ? parseInt(instruction.args[0].int, 10) : 1;
|
|
1125
|
-
args(n - 1, null);
|
|
1126
|
-
return stack.slice(n);
|
|
1127
|
-
}
|
|
1128
|
-
case 'DIG': {
|
|
1129
|
-
instructionAnn({});
|
|
1130
|
-
const n = parseInt(instruction.args[0].int, 10);
|
|
1131
|
-
return [args(n, null)[0], ...stack.slice(0, n), ...stack.slice(n + 1)];
|
|
1132
|
-
}
|
|
1133
|
-
case 'DUG': {
|
|
1134
|
-
instructionAnn({});
|
|
1135
|
-
const n = parseInt(instruction.args[0].int, 10);
|
|
1136
|
-
return [...stack.slice(1, n + 1), args(0, null)[0], ...stack.slice(n + 1)];
|
|
1137
|
-
}
|
|
1138
|
-
case 'NONE':
|
|
1139
|
-
assertTypeAnnotationsValid(instruction.args[0]);
|
|
1140
|
-
return [
|
|
1141
|
-
annotate({ prim: 'option', args: [instruction.args[0]] }, instructionAnn({ t: 1, v: 1 })),
|
|
1142
|
-
...stack,
|
|
1143
|
-
];
|
|
1144
|
-
case 'LEFT':
|
|
1145
|
-
case 'RIGHT': {
|
|
1146
|
-
const s = args(0, null)[0];
|
|
1147
|
-
const ia = instructionAnn({ f: 2, t: 1, v: 1 }, { specialFields: true });
|
|
1148
|
-
const va = argAnn(s);
|
|
1149
|
-
const children = [
|
|
1150
|
-
annotate(s, {
|
|
1151
|
-
t: null,
|
|
1152
|
-
v: null,
|
|
1153
|
-
f: ia.f && ia.f.length > 0 && ia.f[0] !== '%'
|
|
1154
|
-
? ia.f[0] === '%@'
|
|
1155
|
-
? va.v
|
|
1156
|
-
? ['%' + va.v[0].slice(1)]
|
|
1157
|
-
: undefined
|
|
1158
|
-
: ia.f
|
|
1159
|
-
: undefined,
|
|
1160
|
-
}),
|
|
1161
|
-
annotate(instruction.args[0], {
|
|
1162
|
-
t: null,
|
|
1163
|
-
f: ia.f && ia.f.length > 1 && ia.f[1] !== '%' ? ia.f : undefined,
|
|
1164
|
-
}),
|
|
1165
|
-
];
|
|
1166
|
-
return [
|
|
1167
|
-
annotate({
|
|
1168
|
-
prim: 'or',
|
|
1169
|
-
args: instruction.prim === 'LEFT' ? children : [children[1], children[0]],
|
|
1170
|
-
}, { t: ia.t, v: ia.v }),
|
|
1171
|
-
...stack.slice(1),
|
|
1172
|
-
];
|
|
1173
|
-
}
|
|
1174
|
-
case 'NIL':
|
|
1175
|
-
assertTypeAnnotationsValid(instruction.args[0]);
|
|
1176
|
-
return [
|
|
1177
|
-
annotate({ prim: 'list', args: [instruction.args[0]] }, instructionAnn({ t: 1, v: 1 })),
|
|
1178
|
-
...stack,
|
|
1179
|
-
];
|
|
1180
|
-
case 'UNPACK':
|
|
1181
|
-
args(0, ['bytes']);
|
|
1182
|
-
assertTypeAnnotationsValid(instruction.args[0]);
|
|
1183
|
-
return [
|
|
1184
|
-
annotateVar({ prim: 'option', args: [instruction.args[0]] }, '@unpacked'),
|
|
1185
|
-
...stack.slice(1),
|
|
1186
|
-
];
|
|
1187
|
-
case 'CONTRACT': {
|
|
1188
|
-
const s = args(0, ['address'])[0];
|
|
1189
|
-
assertTypeAnnotationsValid(instruction.args[0]);
|
|
1190
|
-
const ia = instructionAnn({ v: 1, f: 1 });
|
|
1191
|
-
const contract = s[michelson_types_1.refContract];
|
|
1192
|
-
if (contract !== undefined) {
|
|
1193
|
-
const ep = contractEntryPoint(contract, ia.f?.[0]);
|
|
1194
|
-
if (ep === null) {
|
|
1195
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: contract has no entrypoint ${ep}`);
|
|
1196
|
-
}
|
|
1197
|
-
ensureTypesEqual(ep, instruction.args[0]);
|
|
1198
|
-
}
|
|
1199
|
-
return [
|
|
1200
|
-
annotate({ prim: 'option', args: [{ prim: 'contract', args: [instruction.args[0]] }] }, { v: ia.v ? ia.v : varSuffix(argAnn(s), 'contract') }),
|
|
1201
|
-
...stack.slice(1),
|
|
1202
|
-
];
|
|
1203
|
-
}
|
|
1204
|
-
case 'CAST': {
|
|
1205
|
-
instructionAnn({});
|
|
1206
|
-
const s = args(0, null)[0];
|
|
1207
|
-
assertTypeAnnotationsValid(instruction.args[0]);
|
|
1208
|
-
ensureTypesEqual(instruction.args[0], s);
|
|
1209
|
-
return [instruction.args[0], ...stack.slice(1)];
|
|
1210
|
-
}
|
|
1211
|
-
case 'IF_NONE': {
|
|
1212
|
-
instructionAnn({});
|
|
1213
|
-
const s = args(0, ['option'])[0];
|
|
1214
|
-
const tail = stack.slice(1);
|
|
1215
|
-
const br0 = functionTypeInternal(instruction.args[0], tail, ctx);
|
|
1216
|
-
const br1 = functionTypeInternal(instruction.args[1], [annotate(s.args[0], { t: null, v: varSuffix(argAnn(s), 'some') }), ...tail], ctx);
|
|
1217
|
-
return branchType(br0, br1);
|
|
1218
|
-
}
|
|
1219
|
-
case 'IF_LEFT': {
|
|
1220
|
-
instructionAnn({});
|
|
1221
|
-
const s = args(0, ['or'])[0];
|
|
1222
|
-
const va = argAnn(s);
|
|
1223
|
-
const lefta = argAnn(s.args[0]);
|
|
1224
|
-
const righta = argAnn(s.args[1]);
|
|
1225
|
-
const tail = stack.slice(1);
|
|
1226
|
-
const br0 = functionTypeInternal(instruction.args[0], [
|
|
1227
|
-
annotate(s.args[0], {
|
|
1228
|
-
t: null,
|
|
1229
|
-
v: varSuffix(va, lefta.f ? lefta.f[0].slice(1) : 'left'),
|
|
1230
|
-
}),
|
|
1231
|
-
...tail,
|
|
1232
|
-
], ctx);
|
|
1233
|
-
const br1 = functionTypeInternal(instruction.args[1], [
|
|
1234
|
-
annotate(s.args[1], {
|
|
1235
|
-
t: null,
|
|
1236
|
-
v: varSuffix(va, righta.f ? righta.f[0].slice(1) : 'right'),
|
|
1237
|
-
}),
|
|
1238
|
-
...tail,
|
|
1239
|
-
], ctx);
|
|
1240
|
-
return branchType(br0, br1);
|
|
1241
|
-
}
|
|
1242
|
-
case 'IF_CONS': {
|
|
1243
|
-
instructionAnn({});
|
|
1244
|
-
const s = args(0, ['list'])[0];
|
|
1245
|
-
const va = argAnn(s);
|
|
1246
|
-
const tail = stack.slice(1);
|
|
1247
|
-
const br0 = functionTypeInternal(instruction.args[0], [
|
|
1248
|
-
annotate(s.args[0], { t: null, v: varSuffix(va, 'hd') }),
|
|
1249
|
-
annotate(s, { t: null, v: varSuffix(va, 'tl') }),
|
|
1250
|
-
...tail,
|
|
1251
|
-
], ctx);
|
|
1252
|
-
const br1 = functionTypeInternal(instruction.args[1], tail, ctx);
|
|
1253
|
-
return branchType(br0, br1);
|
|
1254
|
-
}
|
|
1255
|
-
case 'IF': {
|
|
1256
|
-
instructionAnn({});
|
|
1257
|
-
args(0, ['bool']);
|
|
1258
|
-
const tail = stack.slice(1);
|
|
1259
|
-
const br0 = functionTypeInternal(instruction.args[0], tail, ctx);
|
|
1260
|
-
const br1 = functionTypeInternal(instruction.args[1], tail, ctx);
|
|
1261
|
-
return branchType(br0, br1);
|
|
1262
|
-
}
|
|
1263
|
-
case 'MAP': {
|
|
1264
|
-
const s = args(0, ['list', 'map', 'option'])[0];
|
|
1265
|
-
const tail = stack.slice(1);
|
|
1266
|
-
const elt = s.prim === 'map' ? { prim: 'pair', args: s.args } : s.args[0];
|
|
1267
|
-
const body = functionTypeInternal(instruction.args[0], [annotate(elt, { t: null, v: varSuffix(argAnn(s), 'elt') }), ...tail], ctx);
|
|
1268
|
-
if ('failed' in body) {
|
|
1269
|
-
if (!('prim' in body.failed) || body.failed.prim !== 'never') {
|
|
1270
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: FAIL is not allowed in MAP`);
|
|
1271
|
-
}
|
|
1272
|
-
return { failed: body.failed, level: body.level + 1 };
|
|
1273
|
-
}
|
|
1274
|
-
if (body.length < 1) {
|
|
1275
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: function must return a value`);
|
|
1276
|
-
}
|
|
1277
|
-
ensureStacksEqual(body.slice(1), tail);
|
|
1278
|
-
return s.prim === 'list'
|
|
1279
|
-
? [annotateVar({ prim: 'list', args: [body[0]] }), ...tail]
|
|
1280
|
-
: s.prim === 'map'
|
|
1281
|
-
? [annotateVar({ prim: 'map', args: [s.args[0], body[0]] }), ...tail]
|
|
1282
|
-
: [annotateVar({ prim: 'option', args: [body[0]] }), ...tail];
|
|
1283
|
-
}
|
|
1284
|
-
case 'ITER': {
|
|
1285
|
-
instructionAnn({});
|
|
1286
|
-
const s = args(0, ['set', 'list', 'map'])[0];
|
|
1287
|
-
const tail = stack.slice(1);
|
|
1288
|
-
const elt = s.prim === 'map' ? { prim: 'pair', args: s.args } : s.args[0];
|
|
1289
|
-
const body = functionTypeInternal(instruction.args[0], [annotate(elt, { t: null, v: varSuffix(argAnn(s), 'elt') }), ...tail], ctx);
|
|
1290
|
-
if ('failed' in body) {
|
|
1291
|
-
return { failed: body.failed, level: body.level + 1 };
|
|
1292
|
-
}
|
|
1293
|
-
ensureStacksEqual(body, tail);
|
|
1294
|
-
return tail;
|
|
1295
|
-
}
|
|
1296
|
-
case 'LOOP': {
|
|
1297
|
-
instructionAnn({});
|
|
1298
|
-
args(0, ['bool']);
|
|
1299
|
-
const tail = stack.slice(1);
|
|
1300
|
-
const body = functionTypeInternal(instruction.args[0], tail, ctx);
|
|
1301
|
-
if ('failed' in body) {
|
|
1302
|
-
return { failed: body.failed, level: body.level + 1 };
|
|
1303
|
-
}
|
|
1304
|
-
ensureStacksEqual(body, [{ prim: 'bool' }, ...tail]);
|
|
1305
|
-
return tail;
|
|
1306
|
-
}
|
|
1307
|
-
case 'LOOP_LEFT': {
|
|
1308
|
-
instructionAnn({});
|
|
1309
|
-
const s = args(0, ['or'])[0];
|
|
1310
|
-
const tail = stack.slice(1);
|
|
1311
|
-
const body = functionTypeInternal(instruction.args[0], [annotate(s.args[0], { t: null, v: varSuffix(argAnn(s), 'left') }), ...tail], ctx);
|
|
1312
|
-
if ('failed' in body) {
|
|
1313
|
-
return { failed: body.failed, level: body.level + 1 };
|
|
1314
|
-
}
|
|
1315
|
-
ensureStacksEqual(body, [s, ...tail]);
|
|
1316
|
-
return [annotate(s.args[1], { t: null, v: instructionAnn({ v: 1 }).v }), ...tail];
|
|
1317
|
-
}
|
|
1318
|
-
case 'DIP': {
|
|
1319
|
-
instructionAnn({});
|
|
1320
|
-
const n = instruction.args.length === 2 ? parseInt(instruction.args[0].int, 10) : 1;
|
|
1321
|
-
args(n - 1, null);
|
|
1322
|
-
const head = stack.slice(0, n);
|
|
1323
|
-
const tail = stack.slice(n);
|
|
1324
|
-
// ternary operator is a type guard so use it instead of just `instruction.args.length - 1`
|
|
1325
|
-
const body = instruction.args.length === 2
|
|
1326
|
-
? functionTypeInternal(instruction.args[1], tail, ctx)
|
|
1327
|
-
: functionTypeInternal(instruction.args[0], tail, ctx);
|
|
1328
|
-
if ('failed' in body) {
|
|
1329
|
-
return { failed: body.failed, level: body.level + 1 };
|
|
1330
|
-
}
|
|
1331
|
-
return [...head, ...body];
|
|
1332
|
-
}
|
|
1333
|
-
case 'CREATE_CONTRACT': {
|
|
1334
|
-
const ia = instructionAnn({ v: 2 });
|
|
1335
|
-
const s = args(0, ['option'], ['mutez'], null);
|
|
1336
|
-
if (typeID(s[0].args[0]) !== 'key_hash') {
|
|
1337
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: key hash expected: ${typeID(s[0].args[0])}`);
|
|
1338
|
-
}
|
|
1339
|
-
if (ensureStorableType(s[2])) {
|
|
1340
|
-
assertContractValid(instruction.args[0]);
|
|
1341
|
-
assertScalarTypesEqual(contractSection(instruction.args[0], 'storage').args[0], s[2]);
|
|
1342
|
-
}
|
|
1343
|
-
const va = ia.v?.map((v) => (v !== '@' ? [v] : undefined));
|
|
1344
|
-
return [
|
|
1345
|
-
annotate({ prim: 'operation' }, { v: va?.[0] }),
|
|
1346
|
-
annotate({
|
|
1347
|
-
prim: 'address',
|
|
1348
|
-
[michelson_types_1.refContract]: {
|
|
1349
|
-
prim: 'contract',
|
|
1350
|
-
args: [contractSection(instruction.args[0], 'parameter').args[0]],
|
|
1351
|
-
},
|
|
1352
|
-
}, { v: va?.[1] }),
|
|
1353
|
-
...stack.slice(3),
|
|
1354
|
-
];
|
|
1355
|
-
}
|
|
1356
|
-
case 'PUSH':
|
|
1357
|
-
assertTypeAnnotationsValid(instruction.args[0]);
|
|
1358
|
-
assertDataValidInternal(instruction.args[1], instruction.args[0], {
|
|
1359
|
-
...ctx,
|
|
1360
|
-
contract: undefined,
|
|
1361
|
-
});
|
|
1362
|
-
return [annotateVar(instruction.args[0]), ...stack];
|
|
1363
|
-
case 'EMPTY_SET':
|
|
1364
|
-
assertTypeAnnotationsValid(instruction.args[0]);
|
|
1365
|
-
ensureComparableType(instruction.args[0]);
|
|
1366
|
-
return [
|
|
1367
|
-
annotate({ prim: 'set', args: instruction.args }, instructionAnn({ t: 1, v: 1 })),
|
|
1368
|
-
...stack,
|
|
1369
|
-
];
|
|
1370
|
-
case 'EMPTY_MAP':
|
|
1371
|
-
assertTypeAnnotationsValid(instruction.args[0]);
|
|
1372
|
-
ensureComparableType(instruction.args[0]);
|
|
1373
|
-
assertTypeAnnotationsValid(instruction.args[1]);
|
|
1374
|
-
return [
|
|
1375
|
-
annotate({ prim: 'map', args: instruction.args }, instructionAnn({ t: 1, v: 1 })),
|
|
1376
|
-
...stack,
|
|
1377
|
-
];
|
|
1378
|
-
case 'EMPTY_BIG_MAP':
|
|
1379
|
-
assertTypeAnnotationsValid(instruction.args[0]);
|
|
1380
|
-
ensureComparableType(instruction.args[0]);
|
|
1381
|
-
assertTypeAnnotationsValid(instruction.args[1]);
|
|
1382
|
-
ensureBigMapStorableType(instruction.args[0]);
|
|
1383
|
-
return [
|
|
1384
|
-
annotate({ prim: 'big_map', args: instruction.args }, instructionAnn({ t: 1, v: 1 })),
|
|
1385
|
-
...stack,
|
|
1386
|
-
];
|
|
1387
|
-
case 'LAMBDA_REC':
|
|
1388
|
-
case 'LAMBDA': {
|
|
1389
|
-
assertTypeAnnotationsValid(instruction.args[0]);
|
|
1390
|
-
assertTypeAnnotationsValid(instruction.args[1]);
|
|
1391
|
-
const s = [instruction.args[0]];
|
|
1392
|
-
if (instruction.prim === 'LAMBDA_REC') {
|
|
1393
|
-
s.push({ prim: 'lambda', args: [instruction.args[0], instruction.args[1]] });
|
|
1394
|
-
}
|
|
1395
|
-
const body = functionTypeInternal(instruction.args[2], s, {
|
|
1396
|
-
...ctx,
|
|
1397
|
-
contract: undefined,
|
|
1398
|
-
});
|
|
1399
|
-
if ('failed' in body) {
|
|
1400
|
-
return { failed: body.failed, level: body.level + 1 };
|
|
1401
|
-
}
|
|
1402
|
-
if (body.length !== 1) {
|
|
1403
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: function must return a value`);
|
|
1404
|
-
}
|
|
1405
|
-
ensureTypesEqual(instruction.args[1], body[0]);
|
|
1406
|
-
return [
|
|
1407
|
-
annotateVar({ prim: 'lambda', args: [instruction.args[0], instruction.args[1]] }),
|
|
1408
|
-
...stack,
|
|
1409
|
-
];
|
|
1410
|
-
}
|
|
1411
|
-
case 'LEVEL':
|
|
1412
|
-
return [annotateVar({ prim: 'nat' }, '@level'), ...stack];
|
|
1413
|
-
case 'TOTAL_VOTING_POWER':
|
|
1414
|
-
return [annotateVar({ prim: 'nat' }), ...stack];
|
|
1415
|
-
case 'VOTING_POWER':
|
|
1416
|
-
args(0, ['key_hash']);
|
|
1417
|
-
return [annotateVar({ prim: 'nat' }), ...stack.slice(1)];
|
|
1418
|
-
case 'TICKET': {
|
|
1419
|
-
const s = args(0, null, ['nat'])[0];
|
|
1420
|
-
ensureComparableType(s);
|
|
1421
|
-
if ((0, michelson_types_1.ProtoInferiorTo)(proto, michelson_types_1.Protocol.PtLimaPtL)) {
|
|
1422
|
-
return [
|
|
1423
|
-
annotate({ prim: 'ticket', args: [s] }, instructionAnn({ t: 1, v: 1 })),
|
|
1424
|
-
...stack.slice(2),
|
|
1425
|
-
];
|
|
1426
|
-
}
|
|
1427
|
-
else {
|
|
1428
|
-
return [
|
|
1429
|
-
annotateVar({
|
|
1430
|
-
prim: 'option',
|
|
1431
|
-
args: [annotate({ prim: 'ticket', args: [s] }, instructionAnn({ t: 1, v: 1 }))],
|
|
1432
|
-
}),
|
|
1433
|
-
...stack.slice(2),
|
|
1434
|
-
];
|
|
1435
|
-
}
|
|
1436
|
-
}
|
|
1437
|
-
case 'JOIN_TICKETS': {
|
|
1438
|
-
const s = (0, utils_1.unpackComb)('pair', args(0, ['pair'])[0]);
|
|
1439
|
-
if (typeID(s.args[0]) !== 'ticket') {
|
|
1440
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: ticket expected: ${typeID(s.args[0])}`);
|
|
1441
|
-
}
|
|
1442
|
-
ensureTypesEqual(s.args[0], s.args[1]);
|
|
1443
|
-
return [
|
|
1444
|
-
annotateVar({
|
|
1445
|
-
prim: 'option',
|
|
1446
|
-
args: [annotate(s.args[0], { t: null })],
|
|
1447
|
-
}),
|
|
1448
|
-
...stack.slice(1),
|
|
1449
|
-
];
|
|
1450
|
-
}
|
|
1451
|
-
case 'SPLIT_TICKET': {
|
|
1452
|
-
const s = args(0, ['ticket'], ['pair']);
|
|
1453
|
-
const p = (0, utils_1.unpackComb)('pair', s[1]);
|
|
1454
|
-
if (typeID(p.args[0]) !== 'nat') {
|
|
1455
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: nat expected: ${typeID(p.args[0])}`);
|
|
1456
|
-
}
|
|
1457
|
-
ensureTypesEqual(p.args[0], p.args[1]);
|
|
1458
|
-
return [
|
|
1459
|
-
annotateVar({
|
|
1460
|
-
prim: 'option',
|
|
1461
|
-
args: [
|
|
1462
|
-
{
|
|
1463
|
-
prim: 'pair',
|
|
1464
|
-
args: [annotate(s[0], { t: null }), annotate(s[0], { t: null })],
|
|
1465
|
-
},
|
|
1466
|
-
],
|
|
1467
|
-
}),
|
|
1468
|
-
...stack.slice(2),
|
|
1469
|
-
];
|
|
1470
|
-
}
|
|
1471
|
-
case 'READ_TICKET': {
|
|
1472
|
-
const ia = instructionAnn({ v: 2 });
|
|
1473
|
-
const s = args(0, ['ticket'])[0];
|
|
1474
|
-
const va = ia.v?.map((v) => (v !== '@' ? [v] : undefined));
|
|
1475
|
-
return [
|
|
1476
|
-
annotate({
|
|
1477
|
-
prim: 'pair',
|
|
1478
|
-
args: [{ prim: 'address' }, annotate(s.args[0], { t: null }), { prim: 'nat' }],
|
|
1479
|
-
}, { v: va?.[0] }),
|
|
1480
|
-
annotate(s, { v: va?.[1], t: null }),
|
|
1481
|
-
...stack.slice(1),
|
|
1482
|
-
];
|
|
1483
|
-
}
|
|
1484
|
-
case 'PAIRING_CHECK': {
|
|
1485
|
-
const p = args(0, ['list'])[0].args[0];
|
|
1486
|
-
if (!(0, utils_1.isPairType)(p)) {
|
|
1487
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: pair expected: ${typeID(p)}`);
|
|
1488
|
-
}
|
|
1489
|
-
const c = (0, utils_1.unpackComb)('pair', p);
|
|
1490
|
-
if (typeID(c.args[0]) !== 'bls12_381_g1') {
|
|
1491
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: bls12_381_g1 expected: ${typeID(c.args[0])}`);
|
|
1492
|
-
}
|
|
1493
|
-
if (typeID(c.args[1]) !== 'bls12_381_g2') {
|
|
1494
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: bls12_381_g2 expected: ${typeID(c.args[1])}`);
|
|
1495
|
-
}
|
|
1496
|
-
return [annotateVar({ prim: 'bool' }), ...stack.slice(1)];
|
|
1497
|
-
}
|
|
1498
|
-
case 'SAPLING_EMPTY_STATE':
|
|
1499
|
-
return [
|
|
1500
|
-
annotate({ prim: 'sapling_state', args: [instruction.args[0]] }, instructionAnn({ v: 1, t: 1 })),
|
|
1501
|
-
...stack,
|
|
1502
|
-
];
|
|
1503
|
-
case 'SAPLING_VERIFY_UPDATE': {
|
|
1504
|
-
const s = args(0, ['sapling_transaction'], ['sapling_state']);
|
|
1505
|
-
if (parseInt(s[0].args[0].int, 10) !== parseInt(s[1].args[0].int, 10)) {
|
|
1506
|
-
throw new MichelsonInstructionError(instruction, stack, `${instruction.prim}: sapling memo size mismatch: ${s[0].args[0].int} != ${s[1].args[0].int}`);
|
|
1507
|
-
}
|
|
1508
|
-
return (0, michelson_types_1.ProtoInferiorTo)(proto, michelson_types_1.Protocol.PtJakarta)
|
|
1509
|
-
? [
|
|
1510
|
-
annotateVar({
|
|
1511
|
-
prim: 'option',
|
|
1512
|
-
args: [
|
|
1513
|
-
{
|
|
1514
|
-
prim: 'pair',
|
|
1515
|
-
args: [{ prim: 'int' }, annotate(s[1], { t: null })],
|
|
1516
|
-
},
|
|
1517
|
-
],
|
|
1518
|
-
}),
|
|
1519
|
-
...stack.slice(2),
|
|
1520
|
-
]
|
|
1521
|
-
: [
|
|
1522
|
-
annotateVar({
|
|
1523
|
-
prim: 'option',
|
|
1524
|
-
args: [
|
|
1525
|
-
{
|
|
1526
|
-
prim: 'pair',
|
|
1527
|
-
args: [
|
|
1528
|
-
{ prim: 'bytes' },
|
|
1529
|
-
{
|
|
1530
|
-
prim: 'pair',
|
|
1531
|
-
args: [{ prim: 'int' }, annotate(s[1], { t: null })],
|
|
1532
|
-
},
|
|
1533
|
-
],
|
|
1534
|
-
},
|
|
1535
|
-
],
|
|
1536
|
-
}),
|
|
1537
|
-
...stack.slice(2),
|
|
1538
|
-
];
|
|
1539
|
-
}
|
|
1540
|
-
case 'OPEN_CHEST':
|
|
1541
|
-
args(0, ['chest_key'], ['chest'], ['nat']);
|
|
1542
|
-
return [
|
|
1543
|
-
annotateVar({ prim: 'or', args: [{ prim: 'bytes' }, { prim: 'bool' }] }),
|
|
1544
|
-
...stack.slice(3),
|
|
1545
|
-
];
|
|
1546
|
-
case 'VIEW': {
|
|
1547
|
-
const s = args(0, null, ['address']);
|
|
1548
|
-
ensurePushableType(s[0]);
|
|
1549
|
-
return [annotateVar({ prim: 'option', args: [instruction.args[1]] }), ...stack.slice(2)];
|
|
1550
|
-
}
|
|
1551
|
-
case 'MIN_BLOCK_TIME':
|
|
1552
|
-
return [annotateVar({ prim: 'nat' }), ...stack];
|
|
1553
|
-
case 'EMIT': {
|
|
1554
|
-
const ia = instructionAnn({ f: 1, t: 1 });
|
|
1555
|
-
if (instruction.args) {
|
|
1556
|
-
const s = args(0, null);
|
|
1557
|
-
ensureTypesEqual(s[0], instruction.args[0]);
|
|
1558
|
-
return [annotate({ prim: 'operation' }, ia), ...stack.slice(1)];
|
|
1559
|
-
}
|
|
1560
|
-
return [annotate({ prim: 'operation' }, ia), ...stack.slice(1)];
|
|
1561
|
-
}
|
|
1562
|
-
case 'IS_IMPLICIT_ACCOUNT':
|
|
1563
|
-
args(0, ['address']);
|
|
1564
|
-
return [annotateVar({ prim: 'option', args: [{ prim: 'key_hash' }] }), ...stack.slice(1)];
|
|
1565
|
-
case 'INDEX_ADDRESS':
|
|
1566
|
-
args(0, ['address']);
|
|
1567
|
-
return [annotateVar({ prim: 'nat' }), ...stack.slice(1)];
|
|
1568
|
-
case 'GET_ADDRESS_INDEX':
|
|
1569
|
-
args(0, ['address']);
|
|
1570
|
-
return [annotateVar({ prim: 'option', args: [{ prim: 'nat' }] }), ...stack.slice(1)];
|
|
1571
|
-
default:
|
|
1572
|
-
throw new utils_1.MichelsonError(instruction, `unexpected instruction: ${instruction.prim}`);
|
|
1573
|
-
}
|
|
1574
|
-
})(instruction);
|
|
1575
|
-
if (ctx?.traceCallback !== undefined) {
|
|
1576
|
-
const trace = {
|
|
1577
|
-
op: instruction,
|
|
1578
|
-
in: stack,
|
|
1579
|
-
out: retStack,
|
|
1580
|
-
};
|
|
1581
|
-
ctx.traceCallback(trace);
|
|
1582
|
-
}
|
|
1583
|
-
return retStack;
|
|
1584
|
-
}
|
|
1585
|
-
function contractSection(contract, section) {
|
|
1586
|
-
for (const s of contract) {
|
|
1587
|
-
if (s.prim === section) {
|
|
1588
|
-
return s;
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
throw new utils_1.MichelsonError(contract, `missing contract section: ${section}`);
|
|
1592
|
-
}
|
|
1593
|
-
function contractViews(contract) {
|
|
1594
|
-
const views = {};
|
|
1595
|
-
for (const s of contract) {
|
|
1596
|
-
if (s.prim === 'view') {
|
|
1597
|
-
views[s.args[0].string] = s;
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
return views;
|
|
1601
|
-
}
|
|
1602
|
-
function isContract(v) {
|
|
1603
|
-
if (Array.isArray(v)) {
|
|
1604
|
-
for (const s of v) {
|
|
1605
|
-
if ('prim' in s && (s.prim === 'parameter' || s.prim === 'storage' || s.prim === 'code')) {
|
|
1606
|
-
return true;
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
}
|
|
1610
|
-
return false;
|
|
1611
|
-
}
|
|
1612
|
-
function contractEntryPoint(src, ep) {
|
|
1613
|
-
ep = ep || '%default';
|
|
1614
|
-
const entryPoint = contractEntryPoints(src).find((x) => x[0] === ep);
|
|
1615
|
-
if (entryPoint !== undefined) {
|
|
1616
|
-
return entryPoint[1];
|
|
1617
|
-
}
|
|
1618
|
-
else if (ep === '%default') {
|
|
1619
|
-
return isContract(src) ? contractSection(src, 'parameter').args[0] : src;
|
|
1620
|
-
}
|
|
1621
|
-
return null;
|
|
1622
|
-
}
|
|
1623
|
-
function isOrType(t) {
|
|
1624
|
-
return Array.isArray(t) || t.prim === 'or';
|
|
1625
|
-
}
|
|
1626
|
-
function contractEntryPoints(src) {
|
|
1627
|
-
if (isContract(src)) {
|
|
1628
|
-
const param = contractSection(src, 'parameter');
|
|
1629
|
-
const ch = contractEntryPoints(param.args[0]);
|
|
1630
|
-
const a = (0, utils_1.unpackAnnotations)(param);
|
|
1631
|
-
return a.f ? [[a.f[0], param.args[0]], ...ch] : ch;
|
|
1632
|
-
}
|
|
1633
|
-
if (isOrType(src)) {
|
|
1634
|
-
const args = typeArgs(src);
|
|
1635
|
-
const getArg = (n) => {
|
|
1636
|
-
const a = (0, utils_1.unpackAnnotations)(args[n]);
|
|
1637
|
-
if (typeID(args[n]) === 'or') {
|
|
1638
|
-
const ch = contractEntryPoints(args[n]);
|
|
1639
|
-
return a.f ? [[a.f[0], args[n]], ...ch] : ch;
|
|
1640
|
-
}
|
|
1641
|
-
return a.f ? [[a.f[0], args[n]]] : [];
|
|
1642
|
-
};
|
|
1643
|
-
return [...getArg(0), ...getArg(1)];
|
|
1644
|
-
}
|
|
1645
|
-
return [];
|
|
1646
|
-
}
|
|
1647
|
-
// Contract validation
|
|
1648
|
-
function assertContractValid(contract, ctx) {
|
|
1649
|
-
const assertSection = (parameter, storage, ret, code) => {
|
|
1650
|
-
assertTypeAnnotationsValid(parameter, true);
|
|
1651
|
-
assertTypeAnnotationsValid(storage);
|
|
1652
|
-
const arg = {
|
|
1653
|
-
prim: 'pair',
|
|
1654
|
-
args: [
|
|
1655
|
-
{ ...parameter, ...{ annots: ['@parameter'] } },
|
|
1656
|
-
{ ...storage, ...{ annots: ['@storage'] } },
|
|
1657
|
-
],
|
|
1658
|
-
};
|
|
1659
|
-
const out = functionTypeInternal(code, [arg], { ...ctx, ...{ contract } });
|
|
1660
|
-
if ('failed' in out) {
|
|
1661
|
-
return out;
|
|
1662
|
-
}
|
|
1663
|
-
try {
|
|
1664
|
-
assertStacksEqual(out, [ret]);
|
|
1665
|
-
}
|
|
1666
|
-
catch (err) {
|
|
1667
|
-
if (err instanceof utils_1.MichelsonError) {
|
|
1668
|
-
throw new MichelsonInstructionError(code, out, err.message);
|
|
1669
|
-
}
|
|
1670
|
-
else {
|
|
1671
|
-
throw err;
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
return out;
|
|
1675
|
-
};
|
|
1676
|
-
const parameter = contractSection(contract, 'parameter').args[0];
|
|
1677
|
-
const storage = contractSection(contract, 'storage').args[0];
|
|
1678
|
-
const code = contractSection(contract, 'code').args[0];
|
|
1679
|
-
const expected = {
|
|
1680
|
-
prim: 'pair',
|
|
1681
|
-
args: [{ prim: 'list', args: [{ prim: 'operation' }] }, storage],
|
|
1682
|
-
};
|
|
1683
|
-
const ret = assertSection(parameter, storage, expected, code);
|
|
1684
|
-
for (const view of Object.values(contractViews(contract))) {
|
|
1685
|
-
assertSection(view.args[1], storage, view.args[2], view.args[3]);
|
|
1686
|
-
}
|
|
1687
|
-
return ret;
|
|
1688
|
-
}
|
|
1689
|
-
// Exported wrapper functions
|
|
1690
|
-
function assertDataValid(d, t, ctx) {
|
|
1691
|
-
assertTypeAnnotationsValid(t);
|
|
1692
|
-
assertDataValidInternal(d, t, ctx || null);
|
|
1693
|
-
}
|
|
1694
|
-
function functionType(inst, stack, ctx) {
|
|
1695
|
-
for (const t of stack) {
|
|
1696
|
-
assertTypeAnnotationsValid(t);
|
|
1697
|
-
}
|
|
1698
|
-
if (ctx?.contract !== undefined) {
|
|
1699
|
-
for (const typesec of ['parameter', 'storage']) {
|
|
1700
|
-
const sec = contractSection(ctx.contract, typesec).args[0];
|
|
1701
|
-
assertTypeAnnotationsValid(sec);
|
|
1702
|
-
}
|
|
1703
|
-
}
|
|
1704
|
-
return functionTypeInternal(inst, stack, ctx || null);
|
|
1705
|
-
}
|
|
1706
|
-
function assertTypesEqual(a, b, field = false) {
|
|
1707
|
-
if (Array.isArray(a)) {
|
|
1708
|
-
// type guards don't work for parametrized generic types
|
|
1709
|
-
for (const v of a) {
|
|
1710
|
-
assertTypeAnnotationsValid(v);
|
|
1711
|
-
}
|
|
1712
|
-
for (const v of b) {
|
|
1713
|
-
assertTypeAnnotationsValid(v);
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
else {
|
|
1717
|
-
assertTypeAnnotationsValid(a);
|
|
1718
|
-
assertTypeAnnotationsValid(b);
|
|
1719
|
-
}
|
|
1720
|
-
assertScalarTypesEqual(a, b, field);
|
|
1721
|
-
}
|
|
1722
|
-
function isTypeAnnotationsValid(t, field = false) {
|
|
1723
|
-
try {
|
|
1724
|
-
assertTypeAnnotationsValid(t, field);
|
|
1725
|
-
return true;
|
|
1726
|
-
}
|
|
1727
|
-
catch {
|
|
1728
|
-
return false;
|
|
1729
|
-
}
|
|
1730
|
-
}
|
|
1731
|
-
function isContractValid(contract, ctx) {
|
|
1732
|
-
try {
|
|
1733
|
-
return assertContractValid(contract, ctx);
|
|
1734
|
-
}
|
|
1735
|
-
catch {
|
|
1736
|
-
return null;
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
function isDataValid(d, t, ctx) {
|
|
1740
|
-
try {
|
|
1741
|
-
assertDataValid(d, t, ctx);
|
|
1742
|
-
return true;
|
|
1743
|
-
}
|
|
1744
|
-
catch {
|
|
1745
|
-
return false;
|
|
1746
|
-
}
|
|
1747
|
-
}
|
|
1748
|
-
function isTypeEqual(a, b, field = false) {
|
|
1749
|
-
try {
|
|
1750
|
-
assertTypesEqual(a, b, field);
|
|
1751
|
-
return true;
|
|
1752
|
-
}
|
|
1753
|
-
catch {
|
|
1754
|
-
return false;
|
|
1755
|
-
}
|
|
1756
|
-
}
|