import { BigDecimal } from '../common/numbers' import { Bytes, TypedMapEntry, Entity, TypedMap, Result, Wrapped, } from '../common/collections' import { JSONValue, Value } from '../common/value' import { arweave } from '../chain/arweave' import { ethereum } from '../chain/ethereum' import { near } from '../chain/near' import { cosmos } from '../chain/cosmos' /** * Contains type IDs and their discriminants for every blockchain supported by Graph-Node. * * Each variant corresponds to the unique ID of an AssemblyScript concrete class used by * Graph-Node's runtime. * * # Rules for updating this enum * * 1. The discriminants must have the same value as their counterparts in `IndexForAscTypeId` enum * from `graph-node`'s `graph::runtime` module. If not, the runtime will fail to determine the * correct class during allocation. * 2. Each supported blockchain has a reserved space of 1,000 * contiguous variants. * 3. Once defined, items and their discriminants cannot be changed, as this would break running * subgraphs compiled in previous versions of this representation. */ export enum TypeId { String = 0, ArrayBuffer = 1, Int8Array = 2, Int16Array = 3, Int32Array = 4, Int64Array = 5, Uint8Array = 6, Uint16Array = 7, Uint32Array = 8, Uint64Array = 9, Float32Array = 10, Float64Array = 11, BigDecimal = 12, ArrayBool = 13, ArrayUint8Array = 14, ArrayEthereumValue = 15, ArrayStoreValue = 16, ArrayJsonValue = 17, ArrayString = 18, ArrayEventParam = 19, ArrayTypedMapEntryStringJsonValue = 20, ArrayTypedMapEntryStringStoreValue = 21, SmartContractCall = 22, EventParam = 23, EthereumTransaction = 24, EthereumBlock = 25, EthereumCall = 26, WrappedTypedMapStringJsonValue = 27, WrappedBool = 28, WrappedJsonValue = 29, EthereumValue = 30, StoreValue = 31, JsonValue = 32, EthereumEvent = 33, TypedMapEntryStringStoreValue = 34, TypedMapEntryStringJsonValue = 35, TypedMapStringStoreValue = 36, TypedMapStringJsonValue = 37, TypedMapStringTypedMapStringJsonValue = 38, ResultTypedMapStringJsonValueBool = 39, ResultJsonValueBool = 40, ArrayU8 = 41, ArrayU16 = 42, ArrayU32 = 43, ArrayU64 = 44, ArrayI8 = 45, ArrayI16 = 46, ArrayI32 = 47, ArrayI64 = 48, ArrayF32 = 49, ArrayF64 = 50, ArrayBigDecimal = 51, // Near types NearArrayDataReceiver = 52, NearArrayCryptoHash = 53, NearArrayActionValue = 54, NearMerklePath = 55, // or NearArrayMerklePathItem NearArrayValidatorStake = 56, NearArraySlashedValidator = 57, NearArraySignature = 58, NearArrayChunkHeader = 59, NearAccessKeyPermissionValue = 60, NearActionValue = 61, NearDirection = 62, // not used in graph-node anymore. Can be ignored. NearPublicKey = 63, NearSignature = 64, NearFunctionCallPermission = 65, NearFullAccessPermission = 66, NearAccessKey = 67, NearDataReceiver = 68, NearCreateAccountAction = 69, NearDeployContractAction = 70, NearFunctionCallAction = 71, NearTransferAction = 72, NearStakeAction = 73, NearAddKeyAction = 74, NearDeleteKeyAction = 75, NearDeleteAccountAction = 76, NearActionReceipt = 77, NearSuccessStatus = 78, NearMerklePathItem = 79, NearExecutionOutcome = 80, NearSlashedValidator = 81, NearBlockHeader = 82, NearValidatorStake = 83, NearChunkHeader = 84, NearBlock = 85, NearReceiptWithOutcome = 86, /* Reserved discriminant space for more Near type IDs: [87, 999]: Continue to add more Near type IDs here. e.g.: ``` NextNearType = 87, AnotherNearType = 88, ... LastNearType = 999, ``` */ // Reserved discriminant space for more Ethereum type IDs: [1000, 1499] TransactionReceipt = 1000, Log = 1001, ArrayH256 = 1002, ArrayLog = 1003, /* Continue to add more Ethereum type IDs here. e.g.: ``` NextEthereumType = 1004, AnotherEthereumType = 1005, ... LastEthereumType = 1499, ``` */ // Reserved discriminant space for Cosmos type IDs: [1,500, 2,499] CosmosAny = 1500, CosmosArrayAny = 1501, CosmosArrayBytes = 1502, CosmosArrayCoin = 1503, CosmosArrayCommitSig = 1504, CosmosArrayEvent = 1505, CosmosArrayEventAttribute = 1506, CosmosArrayEvidence = 1507, CosmosArrayModeInfo = 1508, CosmosArraySignerInfo = 1509, CosmosArrayTxResult = 1510, CosmosArrayValidator = 1511, CosmosArrayValidatorUpdate = 1512, CosmosAuthInfo = 1513, CosmosBlock = 1514, CosmosBlockID = 1515, CosmosBlockIDFlagEnum = 1516, CosmosBlockParams = 1517, CosmosCoin = 1518, CosmosCommit = 1519, CosmosCommitSig = 1520, CosmosCompactBitArray = 1521, CosmosConsensus = 1522, CosmosConsensusParams = 1523, CosmosDuplicateVoteEvidence = 1524, CosmosDuration = 1525, CosmosEvent = 1526, CosmosEventAttribute = 1527, CosmosEventData = 1528, CosmosEventVote = 1529, CosmosEvidence = 1530, CosmosEvidenceList = 1531, CosmosEvidenceParams = 1532, CosmosFee = 1533, CosmosHeader = 1534, CosmosHeaderOnlyBlock = 1535, CosmosLightBlock = 1536, CosmosLightClientAttackEvidence = 1537, CosmosModeInfo = 1538, CosmosModeInfoMulti = 1539, CosmosModeInfoSingle = 1540, CosmosPartSetHeader = 1541, CosmosPublicKey = 1542, CosmosResponseBeginBlock = 1543, CosmosResponseDeliverTx = 1544, CosmosResponseEndBlock = 1545, CosmosSignModeEnum = 1546, CosmosSignedHeader = 1547, CosmosSignedMsgTypeEnum = 1548, CosmosSignerInfo = 1549, CosmosTimestamp = 1550, CosmosTip = 1551, CosmosTransactionData = 1552, CosmosTx = 1553, CosmosTxBody = 1554, CosmosTxResult = 1555, CosmosValidator = 1556, CosmosValidatorParams = 1557, CosmosValidatorSet = 1558, CosmosValidatorSetUpdates = 1559, CosmosValidatorUpdate = 1560, CosmosVersionParams = 1561, /* Continue to add more Cosmos type IDs here. e.g.: ``` NextCosmosType = 1562, AnotherCosmosType = 1563, ... LastCosmosType = 2499, ``` */ // Reserved discriminant space for Tendermint type IDs: [2,500, 3,499] ArweaveBlock = 2500, ArweaveProofOfAccess = 2501, ArweaveTag = 2502, ArweaveTagArray = 2503, ArweaveTransaction = 2504, ArweaveTransactionArray = 2505, ArweaveTransactionWithBlockPtr = 2506, /* Continue to add more Arweave type IDs here. e.g.: ``` NextArweaveType = 2507, AnotherArweaveType = 2508, ... LastArweaveType = 3499, ``` */ // Reserved discriminant space for a future blockchain type IDs: [3,500, 4,499] } export function id_of_type(typeId: TypeId): usize { switch (typeId) { case TypeId.String: return idof() case TypeId.ArrayBuffer: return idof() case TypeId.Int8Array: return idof() case TypeId.Int16Array: return idof() case TypeId.Int32Array: return idof() case TypeId.Int64Array: return idof() case TypeId.Uint8Array: return idof() case TypeId.Uint16Array: return idof() case TypeId.Uint32Array: return idof() case TypeId.Uint64Array: return idof() case TypeId.Float32Array: return idof() case TypeId.Float64Array: return idof() case TypeId.BigDecimal: return idof() case TypeId.ArrayBool: return idof>() case TypeId.ArrayUint8Array: return idof>() case TypeId.ArrayEthereumValue: return idof>() case TypeId.ArrayStoreValue: return idof>() case TypeId.ArrayJsonValue: return idof>() case TypeId.ArrayString: return idof>() case TypeId.ArrayEventParam: return idof>() case TypeId.ArrayTypedMapEntryStringJsonValue: return idof>>() case TypeId.ArrayTypedMapEntryStringStoreValue: return idof>() case TypeId.WrappedTypedMapStringJsonValue: return idof>>() case TypeId.WrappedBool: return idof>() case TypeId.WrappedJsonValue: return idof>() case TypeId.SmartContractCall: return idof() case TypeId.EventParam: return idof() case TypeId.EthereumTransaction: return idof() case TypeId.EthereumBlock: return idof() case TypeId.EthereumCall: return idof() case TypeId.EthereumValue: return idof() case TypeId.StoreValue: return idof() case TypeId.JsonValue: return idof() case TypeId.EthereumEvent: return idof() case TypeId.TypedMapEntryStringStoreValue: return idof() case TypeId.TypedMapEntryStringJsonValue: return idof>() case TypeId.TypedMapStringStoreValue: return idof>() case TypeId.TypedMapStringJsonValue: return idof>() case TypeId.TypedMapStringTypedMapStringJsonValue: return idof>>() case TypeId.ResultTypedMapStringJsonValueBool: return idof, boolean>>() case TypeId.ResultJsonValueBool: return idof>() case TypeId.ArrayU8: return idof>() case TypeId.ArrayU16: return idof>() case TypeId.ArrayU32: return idof>() case TypeId.ArrayU64: return idof>() case TypeId.ArrayI8: return idof>() case TypeId.ArrayI16: return idof>() case TypeId.ArrayI32: return idof>() case TypeId.ArrayI64: return idof>() case TypeId.ArrayF32: return idof>() case TypeId.ArrayF64: return idof>() case TypeId.ArrayBigDecimal: return idof>() case TypeId.NearArrayDataReceiver: return idof>() case TypeId.NearArrayCryptoHash: return idof>() case TypeId.NearArrayActionValue: return idof>() case TypeId.NearMerklePath: return idof() case TypeId.NearArrayValidatorStake: return idof>() case TypeId.NearArraySlashedValidator: return idof>() case TypeId.NearArraySignature: return idof>() case TypeId.NearArrayChunkHeader: return idof>() case TypeId.NearAccessKeyPermissionValue: return idof() case TypeId.NearActionValue: return idof() // Commented out because it's an enum, there's no type_id // case TypeId.NearDirection: // return idof() case TypeId.NearPublicKey: return idof() case TypeId.NearSignature: return idof() case TypeId.NearFunctionCallPermission: return idof() case TypeId.NearFullAccessPermission: return idof() case TypeId.NearAccessKey: return idof() case TypeId.NearDataReceiver: return idof() case TypeId.NearCreateAccountAction: return idof() case TypeId.NearDeployContractAction: return idof() case TypeId.NearFunctionCallAction: return idof() case TypeId.NearTransferAction: return idof() case TypeId.NearStakeAction: return idof() case TypeId.NearAddKeyAction: return idof() case TypeId.NearDeleteKeyAction: return idof() case TypeId.NearDeleteAccountAction: return idof() case TypeId.NearActionReceipt: return idof() case TypeId.NearSuccessStatus: return idof() case TypeId.NearMerklePathItem: return idof() case TypeId.NearExecutionOutcome: return idof() case TypeId.NearSlashedValidator: return idof() case TypeId.NearBlockHeader: return idof() case TypeId.NearValidatorStake: return idof() case TypeId.NearChunkHeader: return idof() case TypeId.NearBlock: return idof() case TypeId.NearReceiptWithOutcome: return idof() case TypeId.TransactionReceipt: return idof() case TypeId.Log: return idof() case TypeId.ArrayH256: return idof>() case TypeId.ArrayLog: return idof>() case TypeId.CosmosAny: return idof() case TypeId.CosmosArrayAny: return idof>() case TypeId.CosmosArrayBytes: return idof>() case TypeId.CosmosArrayCoin: return idof>() case TypeId.CosmosArrayCommitSig: return idof>() case TypeId.CosmosArrayEvent: return idof>() case TypeId.CosmosArrayEventAttribute: return idof>() case TypeId.CosmosArrayEvidence: return idof>() case TypeId.CosmosArrayModeInfo: return idof>() case TypeId.CosmosArraySignerInfo: return idof>() case TypeId.CosmosArrayTxResult: return idof>() case TypeId.CosmosArrayValidator: return idof>() case TypeId.CosmosArrayValidatorUpdate: return idof>() case TypeId.CosmosAuthInfo: return idof() case TypeId.CosmosBlock: return idof() case TypeId.CosmosBlockID: return idof() case TypeId.CosmosBlockIDFlagEnum: return idof>() case TypeId.CosmosBlockParams: return idof() case TypeId.CosmosCoin: return idof() case TypeId.CosmosCommit: return idof() case TypeId.CosmosCommitSig: return idof() case TypeId.CosmosCompactBitArray: return idof() case TypeId.CosmosConsensus: return idof() case TypeId.CosmosConsensusParams: return idof() case TypeId.CosmosDuplicateVoteEvidence: return idof() case TypeId.CosmosDuration: return idof() case TypeId.CosmosEvent: return idof() case TypeId.CosmosEventAttribute: return idof() case TypeId.CosmosEventData: return idof() case TypeId.CosmosEventVote: return idof() case TypeId.CosmosEvidence: return idof() case TypeId.CosmosEvidenceList: return idof() case TypeId.CosmosEvidenceParams: return idof() case TypeId.CosmosFee: return idof() case TypeId.CosmosHeader: return idof() case TypeId.CosmosHeaderOnlyBlock: return idof() case TypeId.CosmosLightBlock: return idof() case TypeId.CosmosLightClientAttackEvidence: return idof() case TypeId.CosmosModeInfo: return idof() case TypeId.CosmosModeInfoMulti: return idof() case TypeId.CosmosModeInfoSingle: return idof() case TypeId.CosmosPartSetHeader: return idof() case TypeId.CosmosPublicKey: return idof() case TypeId.CosmosResponseBeginBlock: return idof() case TypeId.CosmosResponseDeliverTx: return idof() case TypeId.CosmosResponseEndBlock: return idof() case TypeId.CosmosSignModeEnum: return idof>() case TypeId.CosmosSignedHeader: return idof() case TypeId.CosmosSignedMsgTypeEnum: return idof>() case TypeId.CosmosSignerInfo: return idof() case TypeId.CosmosTimestamp: return idof() case TypeId.CosmosTip: return idof() case TypeId.CosmosTransactionData: return idof() case TypeId.CosmosTx: return idof() case TypeId.CosmosTxBody: return idof() case TypeId.CosmosTxResult: return idof() case TypeId.CosmosValidator: return idof() case TypeId.CosmosValidatorParams: return idof() case TypeId.CosmosValidatorSet: return idof() case TypeId.CosmosValidatorSetUpdates: return idof() case TypeId.CosmosValidatorUpdate: return idof() case TypeId.CosmosVersionParams: return idof() /** * Arweave type ids */ case TypeId.ArweaveBlock: return idof() case TypeId.ArweaveProofOfAccess: return idof() case TypeId.ArweaveTag: return idof() case TypeId.ArweaveTagArray: return idof>() case TypeId.ArweaveTransaction: return idof() case TypeId.ArweaveTransactionArray: return idof>() case TypeId.ArweaveTransactionWithBlockPtr: return idof() default: return 0 } } export function allocate(size: usize): usize { // @ts-ignore We do not want to expose __alloc, hence why we just ignore the error return __alloc(size) }