@sentio/sdk 3.9.0-rc.9 → 4.0.0-rc.2
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/lib/aptos/aptos-plugin.d.ts +1 -1
- package/lib/aptos/aptos-plugin.d.ts.map +1 -1
- package/lib/aptos/aptos-plugin.js +43 -42
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/aptos/aptos-processor.d.ts +4 -4
- package/lib/aptos/aptos-processor.d.ts.map +1 -1
- package/lib/aptos/aptos-processor.js +25 -25
- package/lib/aptos/aptos-processor.js.map +1 -1
- package/lib/aptos/aptos-resource-processor-template.d.ts +1 -1
- package/lib/aptos/aptos-resource-processor-template.d.ts.map +1 -1
- package/lib/aptos/aptos-resource-processor-template.js +10 -5
- package/lib/aptos/aptos-resource-processor-template.js.map +1 -1
- package/lib/aptos/context.d.ts +1 -1
- package/lib/aptos/context.d.ts.map +1 -1
- package/lib/aptos/context.js +8 -6
- package/lib/aptos/context.js.map +1 -1
- package/lib/aptos/data.d.ts +4 -4
- package/lib/aptos/data.d.ts.map +1 -1
- package/lib/core/base-context.d.ts +3 -2
- package/lib/core/base-context.d.ts.map +1 -1
- package/lib/core/base-context.js +12 -11
- package/lib/core/base-context.js.map +1 -1
- package/lib/core/core-plugin.d.ts.map +1 -1
- package/lib/core/core-plugin.js +6 -4
- package/lib/core/core-plugin.js.map +1 -1
- package/lib/core/event-logger.d.ts +10 -2
- package/lib/core/event-logger.d.ts.map +1 -1
- package/lib/core/event-logger.js +42 -26
- package/lib/core/event-logger.js.map +1 -1
- package/lib/core/exporter.d.ts.map +1 -1
- package/lib/core/exporter.js +5 -3
- package/lib/core/exporter.js.map +1 -1
- package/lib/core/handler-options.d.ts +1 -1
- package/lib/core/handler-options.d.ts.map +1 -1
- package/lib/core/handler-register.d.ts +1 -1
- package/lib/core/handler-register.d.ts.map +1 -1
- package/lib/core/handler-register.js +2 -2
- package/lib/core/handler-register.js.map +1 -1
- package/lib/core/meter.d.ts +4 -3
- package/lib/core/meter.d.ts.map +1 -1
- package/lib/core/meter.js +5 -4
- package/lib/core/meter.js.map +1 -1
- package/lib/core/normalization.d.ts +1 -1
- package/lib/core/normalization.d.ts.map +1 -1
- package/lib/core/normalization.js +41 -31
- package/lib/core/normalization.js.map +1 -1
- package/lib/core/numberish.d.ts +1 -1
- package/lib/core/numberish.d.ts.map +1 -1
- package/lib/core/numberish.js +35 -30
- package/lib/core/numberish.js.map +1 -1
- package/lib/core/partition-handler-manager.d.ts +1 -1
- package/lib/core/partition-handler-manager.d.ts.map +1 -1
- package/lib/core/partition-handler-manager.js +10 -9
- package/lib/core/partition-handler-manager.js.map +1 -1
- package/lib/cosmos/context.d.ts.map +1 -1
- package/lib/cosmos/context.js +4 -2
- package/lib/cosmos/context.js.map +1 -1
- package/lib/cosmos/cosmos-plugin.d.ts.map +1 -1
- package/lib/cosmos/cosmos-plugin.js +11 -10
- package/lib/cosmos/cosmos-plugin.js.map +1 -1
- package/lib/cosmos/cosmos-processor.js.map +1 -1
- package/lib/eth/abi-decoder/decode-worker.js +2 -2
- package/lib/eth/abi-decoder/decode-worker.js.map +1 -1
- package/lib/eth/account-processor.d.ts +2 -2
- package/lib/eth/account-processor.d.ts.map +1 -1
- package/lib/eth/account-processor.js +10 -9
- package/lib/eth/account-processor.js.map +1 -1
- package/lib/eth/base-processor-template.d.ts +3 -3
- package/lib/eth/base-processor-template.d.ts.map +1 -1
- package/lib/eth/base-processor-template.js +14 -8
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/base-processor.d.ts +3 -3
- package/lib/eth/base-processor.d.ts.map +1 -1
- package/lib/eth/base-processor.js +53 -46
- package/lib/eth/base-processor.js.map +1 -1
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js +48 -46
- package/lib/eth/builtin/internal/eacaggregatorproxy-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc1155-processor.js +18 -16
- package/lib/eth/builtin/internal/erc1155-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc20-processor.js +38 -36
- package/lib/eth/builtin/internal/erc20-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc20bytes-processor.js +20 -18
- package/lib/eth/builtin/internal/erc20bytes-processor.js.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/erc721-processor.js +30 -28
- package/lib/eth/builtin/internal/erc721-processor.js.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.d.ts.map +1 -1
- package/lib/eth/builtin/internal/weth9-processor.js +24 -22
- package/lib/eth/builtin/internal/weth9-processor.js.map +1 -1
- package/lib/eth/codegen/file.d.ts.map +1 -1
- package/lib/eth/codegen/file.js +2 -1
- package/lib/eth/codegen/file.js.map +1 -1
- package/lib/eth/codegen/function-calls.js +1 -1
- package/lib/eth/context.d.ts +1 -1
- package/lib/eth/context.d.ts.map +1 -1
- package/lib/eth/context.js +12 -10
- package/lib/eth/context.js.map +1 -1
- package/lib/eth/eth-plugin.d.ts.map +1 -1
- package/lib/eth/eth-plugin.js +83 -75
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/eth/eth.d.ts +6 -6
- package/lib/eth/eth.d.ts.map +1 -1
- package/lib/eth/eth.js +22 -14
- package/lib/eth/eth.js.map +1 -1
- package/lib/eth/index.d.ts +1 -1
- package/lib/eth/index.d.ts.map +1 -1
- package/lib/eth/index.js +0 -1
- package/lib/eth/index.js.map +1 -1
- package/lib/fuel/asset-processor.d.ts +2 -2
- package/lib/fuel/asset-processor.d.ts.map +1 -1
- package/lib/fuel/asset-processor.js +5 -3
- package/lib/fuel/asset-processor.js.map +1 -1
- package/lib/fuel/context.d.ts.map +1 -1
- package/lib/fuel/context.js +4 -2
- package/lib/fuel/context.js.map +1 -1
- package/lib/fuel/fuel-plugin.d.ts.map +1 -1
- package/lib/fuel/fuel-plugin.js +41 -53
- package/lib/fuel/fuel-plugin.js.map +1 -1
- package/lib/fuel/fuel-processor-template.d.ts.map +1 -1
- package/lib/fuel/fuel-processor-template.js +9 -5
- package/lib/fuel/fuel-processor-template.js.map +1 -1
- package/lib/fuel/fuel-processor.d.ts.map +1 -1
- package/lib/fuel/fuel-processor.js +30 -20
- package/lib/fuel/fuel-processor.js.map +1 -1
- package/lib/fuel/global-processor.d.ts.map +1 -1
- package/lib/fuel/global-processor.js +2 -1
- package/lib/fuel/global-processor.js.map +1 -1
- package/lib/fuel/types.d.ts +10 -4
- package/lib/fuel/types.d.ts.map +1 -1
- package/lib/fuel/types.js.map +1 -1
- package/lib/iota/context.d.ts +1 -1
- package/lib/iota/context.d.ts.map +1 -1
- package/lib/iota/context.js +8 -6
- package/lib/iota/context.js.map +1 -1
- package/lib/iota/iota-object-processor-template.d.ts +1 -1
- package/lib/iota/iota-object-processor-template.d.ts.map +1 -1
- package/lib/iota/iota-object-processor-template.js +17 -12
- package/lib/iota/iota-object-processor-template.js.map +1 -1
- package/lib/iota/iota-object-processor.d.ts +1 -1
- package/lib/iota/iota-object-processor.d.ts.map +1 -1
- package/lib/iota/iota-object-processor.js +23 -16
- package/lib/iota/iota-object-processor.js.map +1 -1
- package/lib/iota/iota-plugin-part.d.ts +1 -1
- package/lib/iota/iota-plugin-part.d.ts.map +1 -1
- package/lib/iota/iota-plugin-part.js +16 -15
- package/lib/iota/iota-plugin-part.js.map +1 -1
- package/lib/iota/iota-processor.d.ts +3 -3
- package/lib/iota/iota-processor.d.ts.map +1 -1
- package/lib/iota/iota-processor.js +20 -19
- package/lib/iota/iota-processor.js.map +1 -1
- package/lib/iota/network.js +2 -2
- package/lib/iota/network.js.map +1 -1
- package/lib/move/filter.d.ts +1 -1
- package/lib/move/filter.d.ts.map +1 -1
- package/lib/move/index.d.ts +1 -1
- package/lib/move/index.d.ts.map +1 -1
- package/lib/move/index.js +0 -1
- package/lib/move/index.js.map +1 -1
- package/lib/solana/builtin/types.d.ts +4 -4
- package/lib/solana/codegen/codegen.d.ts +1 -1
- package/lib/solana/codegen/codegen.d.ts.map +1 -1
- package/lib/solana/codegen/codegen.js +2 -2
- package/lib/solana/codegen/codegen.js.map +1 -1
- package/lib/solana/solana-context.d.ts.map +1 -1
- package/lib/solana/solana-context.js +4 -3
- package/lib/solana/solana-context.js.map +1 -1
- package/lib/solana/solana-plugin.d.ts.map +1 -1
- package/lib/solana/solana-plugin.js +19 -18
- package/lib/solana/solana-plugin.js.map +1 -1
- package/lib/solana/solana-processor.d.ts +2 -2
- package/lib/solana/solana-processor.d.ts.map +1 -1
- package/lib/solana/solana-processor.js +8 -3
- package/lib/solana/solana-processor.js.map +1 -1
- package/lib/store/cache.d.ts.map +1 -1
- package/lib/store/cache.js +22 -17
- package/lib/store/cache.js.map +1 -1
- package/lib/store/codegen.js +2 -2
- package/lib/store/codegen.js.map +1 -1
- package/lib/store/convert.d.ts +1 -1
- package/lib/store/convert.d.ts.map +1 -1
- package/lib/store/convert.js +67 -104
- package/lib/store/convert.js.map +1 -1
- package/lib/store/decorators.d.ts +1 -1
- package/lib/store/decorators.d.ts.map +1 -1
- package/lib/store/decorators.js +3 -1
- package/lib/store/decorators.js.map +1 -1
- package/lib/store/store.d.ts.map +1 -1
- package/lib/store/store.js +24 -16
- package/lib/store/store.js.map +1 -1
- package/lib/store/types.js +24 -32
- package/lib/store/types.js.map +1 -1
- package/lib/store/util.d.ts +1 -1
- package/lib/store/util.d.ts.map +1 -1
- package/lib/store/util.js +13 -17
- package/lib/store/util.js.map +1 -1
- package/lib/sui/context.d.ts +1 -1
- package/lib/sui/context.d.ts.map +1 -1
- package/lib/sui/context.js +8 -6
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/sui-object-processor-template.d.ts +1 -1
- package/lib/sui/sui-object-processor-template.d.ts.map +1 -1
- package/lib/sui/sui-object-processor-template.js +17 -12
- package/lib/sui/sui-object-processor-template.js.map +1 -1
- package/lib/sui/sui-object-processor.d.ts +1 -1
- package/lib/sui/sui-object-processor.d.ts.map +1 -1
- package/lib/sui/sui-object-processor.js +23 -16
- package/lib/sui/sui-object-processor.js.map +1 -1
- package/lib/sui/sui-plugin-part.d.ts +1 -1
- package/lib/sui/sui-plugin-part.d.ts.map +1 -1
- package/lib/sui/sui-plugin-part.js +16 -15
- package/lib/sui/sui-plugin-part.js.map +1 -1
- package/lib/sui/sui-plugin.d.ts +1 -1
- package/lib/sui/sui-plugin.d.ts.map +1 -1
- package/lib/sui/sui-plugin.js +35 -34
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +3 -3
- package/lib/sui/sui-processor.d.ts.map +1 -1
- package/lib/sui/sui-processor.js +20 -19
- package/lib/sui/sui-processor.js.map +1 -1
- package/lib/testing/aptos-facet.d.ts.map +1 -1
- package/lib/testing/aptos-facet.js +18 -11
- package/lib/testing/aptos-facet.js.map +1 -1
- package/lib/testing/cosmos-facet.d.ts.map +1 -1
- package/lib/testing/cosmos-facet.js +10 -6
- package/lib/testing/cosmos-facet.js.map +1 -1
- package/lib/testing/eth-facet.d.ts +1 -1
- package/lib/testing/eth-facet.d.ts.map +1 -1
- package/lib/testing/eth-facet.js +34 -18
- package/lib/testing/eth-facet.js.map +1 -1
- package/lib/testing/fuel-facet.d.ts.map +1 -1
- package/lib/testing/fuel-facet.js +28 -18
- package/lib/testing/fuel-facet.js.map +1 -1
- package/lib/testing/iota-facet.d.ts.map +1 -1
- package/lib/testing/iota-facet.js +32 -20
- package/lib/testing/iota-facet.js.map +1 -1
- package/lib/testing/memory-database.d.ts +1 -1
- package/lib/testing/memory-database.d.ts.map +1 -1
- package/lib/testing/memory-database.js +82 -69
- package/lib/testing/memory-database.js.map +1 -1
- package/lib/testing/metric-utils.d.ts +2 -2
- package/lib/testing/metric-utils.d.ts.map +1 -1
- package/lib/testing/metric-utils.js +13 -12
- package/lib/testing/metric-utils.js.map +1 -1
- package/lib/testing/solana-facet.d.ts +3 -2
- package/lib/testing/solana-facet.d.ts.map +1 -1
- package/lib/testing/solana-facet.js +8 -5
- package/lib/testing/solana-facet.js.map +1 -1
- package/lib/testing/sui-facet.d.ts.map +1 -1
- package/lib/testing/sui-facet.js +30 -20
- package/lib/testing/sui-facet.js.map +1 -1
- package/lib/testing/test-processor-server.d.ts +19 -13
- package/lib/testing/test-processor-server.d.ts.map +1 -1
- package/lib/testing/test-processor-server.js +22 -20
- package/lib/testing/test-processor-server.js.map +1 -1
- package/lib/utils/price.d.ts +1 -1
- package/lib/utils/price.d.ts.map +1 -1
- package/lib/utils/price.js +19 -12
- package/lib/utils/price.js.map +1 -1
- package/package.json +10 -12
- package/src/aptos/aptos-plugin.ts +105 -91
- package/src/aptos/aptos-processor.ts +42 -34
- package/src/aptos/aptos-resource-processor-template.ts +15 -6
- package/src/aptos/context.ts +8 -7
- package/src/aptos/data.ts +4 -4
- package/src/core/base-context.ts +19 -12
- package/src/core/core-plugin.ts +10 -7
- package/src/core/event-logger.ts +63 -34
- package/src/core/exporter.ts +5 -4
- package/src/core/handler-options.ts +1 -1
- package/src/core/handler-register.ts +3 -3
- package/src/core/meter.ts +9 -7
- package/src/core/normalization.ts +53 -31
- package/src/core/numberish.ts +46 -30
- package/src/core/partition-handler-manager.ts +13 -11
- package/src/cosmos/context.ts +4 -3
- package/src/cosmos/cosmos-plugin.ts +19 -15
- package/src/cosmos/cosmos-processor.ts +2 -2
- package/src/eth/abi-decoder/decode-worker.ts +2 -2
- package/src/eth/account-processor.ts +21 -12
- package/src/eth/base-processor-template.ts +27 -11
- package/src/eth/base-processor.ts +77 -65
- package/src/eth/builtin/internal/eacaggregatorproxy-processor.ts +177 -116
- package/src/eth/builtin/internal/erc1155-processor.ts +73 -38
- package/src/eth/builtin/internal/erc20-processor.ts +152 -91
- package/src/eth/builtin/internal/erc20bytes-processor.ts +80 -46
- package/src/eth/builtin/internal/erc721-processor.ts +109 -65
- package/src/eth/builtin/internal/weth9-processor.ts +95 -56
- package/src/eth/codegen/file.ts +2 -1
- package/src/eth/codegen/function-calls.ts +1 -1
- package/src/eth/context.ts +18 -11
- package/src/eth/eth-plugin.ts +135 -118
- package/src/eth/eth.ts +29 -20
- package/src/eth/index.ts +1 -1
- package/src/fuel/asset-processor.ts +16 -8
- package/src/fuel/context.ts +4 -3
- package/src/fuel/fuel-plugin.ts +71 -73
- package/src/fuel/fuel-processor-template.ts +10 -7
- package/src/fuel/fuel-processor.ts +35 -23
- package/src/fuel/global-processor.ts +3 -3
- package/src/fuel/types.ts +10 -4
- package/src/iota/context.ts +8 -7
- package/src/iota/iota-object-processor-template.ts +25 -15
- package/src/iota/iota-object-processor.ts +33 -22
- package/src/iota/iota-plugin-part.ts +41 -34
- package/src/iota/iota-processor.ts +35 -27
- package/src/iota/network.ts +2 -2
- package/src/move/filter.ts +1 -1
- package/src/move/index.ts +1 -1
- package/src/solana/codegen/codegen.ts +2 -2
- package/src/solana/solana-context.ts +4 -3
- package/src/solana/solana-plugin.ts +27 -24
- package/src/solana/solana-processor.ts +23 -11
- package/src/store/cache.ts +22 -18
- package/src/store/codegen.ts +2 -2
- package/src/store/convert.ts +68 -104
- package/src/store/decorators.ts +3 -2
- package/src/store/store.ts +31 -23
- package/src/store/types.ts +24 -33
- package/src/store/util.ts +13 -18
- package/src/sui/context.ts +8 -7
- package/src/sui/sui-object-processor-template.ts +25 -15
- package/src/sui/sui-object-processor.ts +33 -22
- package/src/sui/sui-plugin-part.ts +41 -34
- package/src/sui/sui-plugin.ts +49 -47
- package/src/sui/sui-processor.ts +35 -27
- package/src/testing/aptos-facet.ts +18 -11
- package/src/testing/cosmos-facet.ts +10 -6
- package/src/testing/eth-facet.ts +40 -18
- package/src/testing/fuel-facet.ts +28 -18
- package/src/testing/iota-facet.ts +32 -20
- package/src/testing/memory-database.ts +109 -82
- package/src/testing/metric-utils.ts +15 -14
- package/src/testing/solana-facet.ts +11 -6
- package/src/testing/sui-facet.ts +30 -20
- package/src/testing/test-processor-server.ts +64 -58
- package/src/utils/price.ts +20 -13
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { normalizeLabels, Labels, BaseContext, RecordMetaData } from '../index.js'
|
|
1
|
+
import { normalizeLabels, Labels, BaseContext, RecordMetaData, RecordMetaDataSchema } from '../index.js'
|
|
2
2
|
import { SolanaChainId } from '@sentio/chain'
|
|
3
|
+
import { create } from '@bufbuild/protobuf'
|
|
3
4
|
import type { TransactionResponse } from './solana-rpc-types.js'
|
|
4
5
|
|
|
5
6
|
export class SolanaContext extends BaseContext {
|
|
@@ -30,7 +31,7 @@ export class SolanaContext extends BaseContext {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
|
|
33
|
-
return {
|
|
34
|
+
return create(RecordMetaDataSchema, {
|
|
34
35
|
address: this.address,
|
|
35
36
|
contractName: this.programName,
|
|
36
37
|
blockNumber: this.blockNumber,
|
|
@@ -40,6 +41,6 @@ export class SolanaContext extends BaseContext {
|
|
|
40
41
|
chainId: this.getChainId(),
|
|
41
42
|
name: name,
|
|
42
43
|
labels: normalizeLabels(labels)
|
|
43
|
-
}
|
|
44
|
+
})
|
|
44
45
|
}
|
|
45
46
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
ContractConfigSchema,
|
|
4
4
|
DataBinding,
|
|
5
5
|
HandlerType,
|
|
6
6
|
InitResponse,
|
|
7
|
-
|
|
7
|
+
InstructionHandlerConfigSchema,
|
|
8
|
+
OnIntervalConfigSchema,
|
|
8
9
|
ProcessConfigResponse,
|
|
9
10
|
ProcessResult
|
|
10
11
|
} from '@sentio/protos'
|
|
11
|
-
|
|
12
|
-
import {
|
|
12
|
+
import { create } from '@bufbuild/protobuf'
|
|
13
|
+
import { ConnectError, Code } from '@connectrpc/connect'
|
|
13
14
|
|
|
14
15
|
import { SolanaProcessorState } from './solana-processor.js'
|
|
15
16
|
import { Instruction as SolInstruction } from '@anchor-lang/core'
|
|
@@ -32,7 +33,7 @@ export class SolanaPlugin extends Plugin {
|
|
|
32
33
|
continue
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
const contractConfig =
|
|
36
|
+
const contractConfig = create(ContractConfigSchema, {
|
|
36
37
|
processorType: USER_PROCESSOR,
|
|
37
38
|
contract: {
|
|
38
39
|
name: solanaProcessor.contractName,
|
|
@@ -50,17 +51,17 @@ export class SolanaPlugin extends Plugin {
|
|
|
50
51
|
break
|
|
51
52
|
}
|
|
52
53
|
}
|
|
53
|
-
contractConfig.instructionConfig = {
|
|
54
|
+
contractConfig.instructionConfig = create(InstructionHandlerConfigSchema, {
|
|
54
55
|
innerInstruction: solanaProcessor.processInnerInstruction,
|
|
55
56
|
parsedInstruction: solanaProcessor.fromParsedInstruction !== null,
|
|
56
57
|
rawDataInstruction: solanaProcessor.decodeInstruction !== null,
|
|
57
58
|
fetchTx: fetchTx
|
|
58
|
-
}
|
|
59
|
+
})
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
for (const [idx, handler] of solanaProcessor.blockHandlers.entries()) {
|
|
62
63
|
contractConfig.intervalConfigs.push(
|
|
63
|
-
|
|
64
|
+
create(OnIntervalConfigSchema, {
|
|
64
65
|
handlerId: idx,
|
|
65
66
|
minutesInterval: handler.timeIntervalInMinutes,
|
|
66
67
|
slotInterval: handler.slotInterval,
|
|
@@ -82,19 +83,19 @@ export class SolanaPlugin extends Plugin {
|
|
|
82
83
|
case HandlerType.SOL_BLOCK:
|
|
83
84
|
return this.processSolBlock(request)
|
|
84
85
|
default:
|
|
85
|
-
throw new
|
|
86
|
+
throw new ConnectError('No handle type registered ' + request.handlerType, Code.InvalidArgument)
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
async processSolInstruction(request: DataBinding): Promise<ProcessResult> {
|
|
90
91
|
if (!request.data) {
|
|
91
|
-
throw new
|
|
92
|
+
throw new ConnectError('instruction data cannot be empty', Code.InvalidArgument)
|
|
92
93
|
}
|
|
93
|
-
if (
|
|
94
|
-
throw new
|
|
94
|
+
if (request.data.value.case !== 'solInstruction') {
|
|
95
|
+
throw new ConnectError('instruction data cannot be empty', Code.InvalidArgument)
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
const instruction = request.data.
|
|
98
|
+
const instruction = request.data.value.value
|
|
98
99
|
const promises: Promise<ProcessResult>[] = []
|
|
99
100
|
|
|
100
101
|
// Only have instruction handlers for solana processors
|
|
@@ -103,15 +104,17 @@ export class SolanaPlugin extends Plugin {
|
|
|
103
104
|
let parsedInstruction: SolInstruction | null = null
|
|
104
105
|
|
|
105
106
|
try {
|
|
106
|
-
if (instruction.
|
|
107
|
-
parsedInstruction = processor.getParsedInstruction(
|
|
107
|
+
if (instruction.rawParsed) {
|
|
108
|
+
parsedInstruction = processor.getParsedInstruction(
|
|
109
|
+
JSON.parse(instruction.rawParsed) as { type: string; info: any }
|
|
110
|
+
)
|
|
108
111
|
} else if (instruction.instructionData) {
|
|
109
112
|
parsedInstruction = processor.getParsedInstruction(instruction.instructionData)
|
|
110
113
|
}
|
|
111
114
|
} catch (e) {
|
|
112
|
-
throw new
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
throw new ConnectError(
|
|
116
|
+
'Failed to decode instruction: ' + JSON.stringify(instruction) + errorString(e),
|
|
117
|
+
Code.Internal
|
|
115
118
|
)
|
|
116
119
|
}
|
|
117
120
|
if (parsedInstruction == null) {
|
|
@@ -124,9 +127,9 @@ export class SolanaPlugin extends Plugin {
|
|
|
124
127
|
const res = processor
|
|
125
128
|
.handleInstruction(parsedInstruction, instruction.accounts, insHandler, instruction)
|
|
126
129
|
.catch((e) => {
|
|
127
|
-
throw new
|
|
128
|
-
|
|
129
|
-
|
|
130
|
+
throw new ConnectError(
|
|
131
|
+
'Error processing instruction: ' + JSON.stringify(instruction) + '\n' + errorString(e),
|
|
132
|
+
Code.Internal
|
|
130
133
|
)
|
|
131
134
|
})
|
|
132
135
|
|
|
@@ -137,10 +140,10 @@ export class SolanaPlugin extends Plugin {
|
|
|
137
140
|
}
|
|
138
141
|
|
|
139
142
|
async processSolBlock(request: DataBinding): Promise<ProcessResult> {
|
|
140
|
-
if (
|
|
141
|
-
throw new
|
|
143
|
+
if (request.data?.value.case !== 'solBlock') {
|
|
144
|
+
throw new ConnectError('block data cannot be empty', Code.InvalidArgument)
|
|
142
145
|
}
|
|
143
|
-
const block = request.data.
|
|
146
|
+
const block = request.data.value.value
|
|
144
147
|
const promises: Promise<ProcessResult>[] = []
|
|
145
148
|
for (const processor of SolanaProcessorState.INSTANCE.getValues()) {
|
|
146
149
|
for (const handlerId of request.handlerIds) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Data_SolBlock, Data_SolInstruction, HandleInterval, ProcessResult } from '@sentio/protos'
|
|
1
|
+
import { Data_SolBlock, Data_SolInstruction, HandleInterval, HandleIntervalSchema, ProcessResult } from '@sentio/protos'
|
|
2
|
+
import { create } from '@bufbuild/protobuf'
|
|
2
3
|
import { SolanaContext } from './solana-context.js'
|
|
3
4
|
import { Instruction } from '@anchor-lang/core'
|
|
4
5
|
import { SolanaBindOptions, SolanaFetchConfig } from './solana-options.js'
|
|
@@ -18,7 +19,11 @@ export interface InstructionCoder {
|
|
|
18
19
|
decode(ix: Buffer | string, encoding?: 'hex' | 'base58'): Instruction | null
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
export type SolanaInstructionHandler
|
|
22
|
+
export type SolanaInstructionHandler<T extends Instruction = Instruction> = (
|
|
23
|
+
instruction: T,
|
|
24
|
+
ctx: SolanaContext,
|
|
25
|
+
accounts: string[]
|
|
26
|
+
) => void
|
|
22
27
|
|
|
23
28
|
export interface InstructionHandlerEntry {
|
|
24
29
|
handler: SolanaInstructionHandler
|
|
@@ -79,12 +84,12 @@ export class SolanaBaseProcessor {
|
|
|
79
84
|
SolanaProcessorState.INSTANCE.addValue(this)
|
|
80
85
|
}
|
|
81
86
|
|
|
82
|
-
public onInstruction(
|
|
87
|
+
public onInstruction<T extends Instruction = Instruction>(
|
|
83
88
|
instructionName: string,
|
|
84
|
-
handler: SolanaInstructionHandler
|
|
85
|
-
handlerOptions?: HandlerOptions<SolanaFetchConfig,
|
|
89
|
+
handler: SolanaInstructionHandler<T>,
|
|
90
|
+
handlerOptions?: HandlerOptions<SolanaFetchConfig, T>
|
|
86
91
|
) {
|
|
87
|
-
this.instructionHandlerMap.set(instructionName, { handler, handlerOptions })
|
|
92
|
+
this.instructionHandlerMap.set(instructionName, { handler, handlerOptions } as InstructionHandlerEntry)
|
|
88
93
|
return this
|
|
89
94
|
}
|
|
90
95
|
|
|
@@ -95,7 +100,10 @@ export class SolanaBaseProcessor {
|
|
|
95
100
|
): this {
|
|
96
101
|
return this.onInterval(
|
|
97
102
|
handler,
|
|
98
|
-
|
|
103
|
+
create(HandleIntervalSchema, {
|
|
104
|
+
recentInterval: timeIntervalInMinutes,
|
|
105
|
+
backfillInterval: backfillTimeIntervalInMinutes
|
|
106
|
+
}),
|
|
99
107
|
undefined
|
|
100
108
|
)
|
|
101
109
|
}
|
|
@@ -105,10 +113,14 @@ export class SolanaBaseProcessor {
|
|
|
105
113
|
blockInterval = 1000,
|
|
106
114
|
backfillBlockInterval = 4000
|
|
107
115
|
): this {
|
|
108
|
-
return this.onInterval(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
return this.onInterval(
|
|
117
|
+
handler,
|
|
118
|
+
undefined,
|
|
119
|
+
create(HandleIntervalSchema, {
|
|
120
|
+
recentInterval: blockInterval,
|
|
121
|
+
backfillInterval: backfillBlockInterval
|
|
122
|
+
})
|
|
123
|
+
)
|
|
112
124
|
}
|
|
113
125
|
|
|
114
126
|
public onInterval<T>(
|
package/src/store/cache.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { IStoreContext } from '@sentio/runtime'
|
|
2
|
-
import {
|
|
2
|
+
import { type DBResponse, type RichStruct, RichStructSchema } from '@sentio/protos'
|
|
3
|
+
import { create } from '@bufbuild/protobuf'
|
|
3
4
|
import { BaseContext } from '../core/index.js'
|
|
4
5
|
|
|
5
6
|
/** Internal entity name used for cache storage */
|
|
@@ -64,17 +65,20 @@ export class MemoryCache {
|
|
|
64
65
|
*/
|
|
65
66
|
public async get<T>(key: string): Promise<T | null> {
|
|
66
67
|
const promise = this.storeContext.sendRequest({
|
|
67
|
-
|
|
68
|
+
case: 'get',
|
|
69
|
+
value: {
|
|
68
70
|
entity: CacheItemEntityName,
|
|
69
71
|
id: key
|
|
70
72
|
}
|
|
71
73
|
})
|
|
72
74
|
|
|
73
75
|
const data = (await promise) as DBResponse
|
|
74
|
-
if (data.entityList
|
|
75
|
-
const entityData = data.
|
|
76
|
-
const value = entityData
|
|
77
|
-
|
|
76
|
+
if (data.value.case === 'entityList' && data.value.value.entities[0]) {
|
|
77
|
+
const entityData = data.value.value.entities[0]?.data
|
|
78
|
+
const value = entityData?.fields['value']
|
|
79
|
+
if (value?.value.case === 'stringValue') {
|
|
80
|
+
return JSON.parse(value.value.value) as T
|
|
81
|
+
}
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
return null
|
|
@@ -94,24 +98,24 @@ export class MemoryCache {
|
|
|
94
98
|
* ```
|
|
95
99
|
*/
|
|
96
100
|
public async set<T>(key: string, value: T): Promise<void> {
|
|
97
|
-
const entityData: RichStruct = {
|
|
101
|
+
const entityData: RichStruct = create(RichStructSchema, {
|
|
98
102
|
fields: {
|
|
99
103
|
id: {
|
|
100
|
-
stringValue: key
|
|
104
|
+
value: { case: 'stringValue', value: key }
|
|
101
105
|
},
|
|
102
106
|
value: {
|
|
103
|
-
stringValue: JSON.stringify(value)
|
|
107
|
+
value: { case: 'stringValue', value: JSON.stringify(value) }
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
})
|
|
111
|
+
await this.storeContext.sendRequest({
|
|
112
|
+
case: 'upsert',
|
|
113
|
+
value: {
|
|
109
114
|
entity: [CacheItemEntityName],
|
|
110
115
|
id: [key],
|
|
111
116
|
entityData: [entityData]
|
|
112
117
|
}
|
|
113
|
-
}
|
|
114
|
-
await this.storeContext.sendRequest(request)
|
|
118
|
+
})
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
/**
|
|
@@ -125,13 +129,13 @@ export class MemoryCache {
|
|
|
125
129
|
* ```
|
|
126
130
|
*/
|
|
127
131
|
public async delete(key: string): Promise<void> {
|
|
128
|
-
|
|
129
|
-
|
|
132
|
+
await this.storeContext.sendRequest({
|
|
133
|
+
case: 'delete',
|
|
134
|
+
value: {
|
|
130
135
|
entity: [CacheItemEntityName],
|
|
131
136
|
id: [key]
|
|
132
137
|
}
|
|
133
|
-
}
|
|
134
|
-
await this.storeContext.sendRequest(request)
|
|
138
|
+
})
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
/**
|
package/src/store/codegen.ts
CHANGED
|
@@ -210,7 +210,7 @@ async function codegenInternal(schema: GraphQLSchema, source: string, target: st
|
|
|
210
210
|
})
|
|
211
211
|
fields.push({
|
|
212
212
|
name: f.name + 'ID' + (isMany ? 's' : ''),
|
|
213
|
-
type: isMany ? `Array<ID
|
|
213
|
+
type: isMany ? `Array<ID>` : `ID`,
|
|
214
214
|
annotations: []
|
|
215
215
|
})
|
|
216
216
|
if (isMany) {
|
|
@@ -317,7 +317,7 @@ export class ${c.name} ${c.parent ? `extends ${c.parent}` : ''} ${c.interfaces.l
|
|
|
317
317
|
${c.fields
|
|
318
318
|
.map((f) => `${f.annotations.map((a) => `\n\t${a}`).join('')}\n\t${f.name}${f.optional ? '?' : ''}: ${f.type}`)
|
|
319
319
|
.join('\n')}
|
|
320
|
-
${isEntity ? `constructor(data:
|
|
320
|
+
${isEntity ? `constructor(data: Partial<${c.name}ConstructorInput>) {super()}` : ''}
|
|
321
321
|
${(c.methods ?? []).map(genMethod).join('\n')}
|
|
322
322
|
|
|
323
323
|
${
|
package/src/store/convert.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { RichValue, RichValue_NullValue } from '@sentio/protos'
|
|
1
|
+
import { type RichValue, RichValueSchema, RichValue_NullValue, timestampDate, timestampFromDate } from '@sentio/protos'
|
|
2
|
+
import { create } from '@bufbuild/protobuf'
|
|
2
3
|
import type { String, Int, Float, ID, Bytes, Timestamp, Boolean } from './types.js'
|
|
3
4
|
import { BigDecimal } from '@sentio/bigdecimal'
|
|
4
5
|
import { toBigInteger, toBigDecimal } from '../core/numberish.js'
|
|
@@ -14,6 +15,10 @@ export interface ValueConverter<T> {
|
|
|
14
15
|
|
|
15
16
|
export const ValueRequiredError = new Error('Value is required but received null or undefined')
|
|
16
17
|
|
|
18
|
+
function nullRichValue(): RichValue {
|
|
19
|
+
return create(RichValueSchema, { value: { case: 'nullValue', value: RichValue_NullValue.NULL_VALUE } })
|
|
20
|
+
}
|
|
21
|
+
|
|
17
22
|
export function required_<T>(converter: ValueConverter<T | undefined>): ValueConverter<T> {
|
|
18
23
|
const { from, to, ...rest } = converter
|
|
19
24
|
return {
|
|
@@ -24,7 +29,7 @@ export function required_<T>(converter: ValueConverter<T | undefined>): ValueCon
|
|
|
24
29
|
return from(value)
|
|
25
30
|
},
|
|
26
31
|
to: (value: RichValue) => {
|
|
27
|
-
if (value == null || value.nullValue) {
|
|
32
|
+
if (value == null || value.value.case === 'nullValue') {
|
|
28
33
|
throw ValueRequiredError
|
|
29
34
|
}
|
|
30
35
|
return to(value)!
|
|
@@ -37,14 +42,17 @@ export function required_<T>(converter: ValueConverter<T | undefined>): ValueCon
|
|
|
37
42
|
export function array_<T>(converter: ValueConverter<T>): ValueConverter<T[]> {
|
|
38
43
|
return {
|
|
39
44
|
from: (value: T[]) => {
|
|
40
|
-
return {
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
return create(RichValueSchema, {
|
|
46
|
+
value: {
|
|
47
|
+
case: 'listValue',
|
|
48
|
+
value: {
|
|
49
|
+
values: value.map(converter.from)
|
|
50
|
+
}
|
|
43
51
|
}
|
|
44
|
-
}
|
|
52
|
+
})
|
|
45
53
|
},
|
|
46
54
|
to: (value: RichValue) => {
|
|
47
|
-
return value.listValue
|
|
55
|
+
return value.value.case === 'listValue' ? value.value.value.values.map(converter.to) : []
|
|
48
56
|
},
|
|
49
57
|
isArray: true,
|
|
50
58
|
isRelation: converter.isRelation,
|
|
@@ -56,16 +64,14 @@ export function enumerate_<T extends string | number>(values: Record<T, string>)
|
|
|
56
64
|
return {
|
|
57
65
|
from: (value?: T) => {
|
|
58
66
|
if (value == null) {
|
|
59
|
-
return
|
|
60
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
stringValue: values[value]
|
|
67
|
+
return nullRichValue()
|
|
65
68
|
}
|
|
69
|
+
return create(RichValueSchema, {
|
|
70
|
+
value: { case: 'stringValue', value: values[value] }
|
|
71
|
+
})
|
|
66
72
|
},
|
|
67
73
|
to(v: RichValue): T {
|
|
68
|
-
return v.stringValue as T
|
|
74
|
+
return (v.value.case === 'stringValue' ? v.value.value : undefined) as T
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
77
|
}
|
|
@@ -74,28 +80,24 @@ export function objectId_<T>(entityName: string): ValueConverter<T | ID> {
|
|
|
74
80
|
return {
|
|
75
81
|
from: (value: T | ID) => {
|
|
76
82
|
if (typeof value == 'string') {
|
|
77
|
-
return {
|
|
78
|
-
stringValue: value
|
|
79
|
-
}
|
|
83
|
+
return create(RichValueSchema, { value: { case: 'stringValue', value } })
|
|
80
84
|
}
|
|
81
85
|
if (value instanceof Uint8Array) {
|
|
82
|
-
return {
|
|
83
|
-
stringValue: `0x${Buffer.from(value).toString('hex')}`
|
|
84
|
-
}
|
|
86
|
+
return create(RichValueSchema, {
|
|
87
|
+
value: { case: 'stringValue', value: `0x${Buffer.from(value).toString('hex')}` }
|
|
88
|
+
})
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
if (typeof value == 'object') {
|
|
88
92
|
const entity = value as any
|
|
89
|
-
return {
|
|
90
|
-
stringValue: entity.id.toString()
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
93
|
+
return create(RichValueSchema, {
|
|
94
|
+
value: { case: 'stringValue', value: entity.id.toString() }
|
|
95
|
+
})
|
|
95
96
|
}
|
|
97
|
+
return nullRichValue()
|
|
96
98
|
},
|
|
97
99
|
to(v) {
|
|
98
|
-
return v.stringValue as T | ID
|
|
100
|
+
return (v.value.case === 'stringValue' ? v.value.value : undefined) as T | ID
|
|
99
101
|
},
|
|
100
102
|
isRelation: true,
|
|
101
103
|
relationName: entityName
|
|
@@ -105,137 +107,105 @@ export function objectId_<T>(entityName: string): ValueConverter<T | ID> {
|
|
|
105
107
|
export const StringConverter: ValueConverter<String | undefined> = {
|
|
106
108
|
from: (value?: String) => {
|
|
107
109
|
if (value == null) {
|
|
108
|
-
return
|
|
109
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
stringValue: value
|
|
110
|
+
return nullRichValue()
|
|
114
111
|
}
|
|
112
|
+
return create(RichValueSchema, { value: { case: 'stringValue', value } })
|
|
115
113
|
},
|
|
116
114
|
to(v) {
|
|
117
|
-
return v.stringValue
|
|
115
|
+
return v.value.case === 'stringValue' ? v.value.value : undefined
|
|
118
116
|
}
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
export const IntConverter: ValueConverter<Int | undefined> = {
|
|
122
120
|
from: (value?: Int) => {
|
|
123
121
|
if (value == null) {
|
|
124
|
-
return
|
|
125
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return {
|
|
129
|
-
intValue: Math.floor(value)
|
|
122
|
+
return nullRichValue()
|
|
130
123
|
}
|
|
124
|
+
return create(RichValueSchema, { value: { case: 'intValue', value: Math.floor(value) } })
|
|
131
125
|
},
|
|
132
126
|
to(v) {
|
|
133
|
-
return v.intValue as Int
|
|
127
|
+
return (v.value.case === 'intValue' ? v.value.value : undefined) as Int
|
|
134
128
|
}
|
|
135
129
|
}
|
|
136
130
|
|
|
137
131
|
export const Int8Converter: ValueConverter<bigint | undefined> = {
|
|
138
132
|
from: (value?: bigint) => {
|
|
139
133
|
if (value == null) {
|
|
140
|
-
return
|
|
141
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return {
|
|
145
|
-
int64Value: BigInt(value)
|
|
134
|
+
return nullRichValue()
|
|
146
135
|
}
|
|
136
|
+
return create(RichValueSchema, { value: { case: 'int64Value', value: BigInt(value) } })
|
|
147
137
|
},
|
|
148
138
|
to(v) {
|
|
149
|
-
return v.int64Value
|
|
139
|
+
return v.value.case === 'int64Value' ? v.value.value : undefined
|
|
150
140
|
}
|
|
151
141
|
}
|
|
152
142
|
|
|
153
143
|
export const FloatConverter: ValueConverter<Float | undefined> = {
|
|
154
144
|
from: (value?: Float) => {
|
|
155
145
|
if (value == null) {
|
|
156
|
-
return
|
|
157
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
floatValue: value
|
|
146
|
+
return nullRichValue()
|
|
162
147
|
}
|
|
148
|
+
return create(RichValueSchema, { value: { case: 'floatValue', value } })
|
|
163
149
|
},
|
|
164
150
|
to(v) {
|
|
165
|
-
return v.floatValue
|
|
151
|
+
return v.value.case === 'floatValue' ? v.value.value : undefined
|
|
166
152
|
}
|
|
167
153
|
}
|
|
168
154
|
|
|
169
155
|
export const BooleanConverter: ValueConverter<Boolean | undefined> = {
|
|
170
156
|
from: (value?: Boolean) => {
|
|
171
157
|
if (value == null) {
|
|
172
|
-
return
|
|
173
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
boolValue: value
|
|
158
|
+
return nullRichValue()
|
|
178
159
|
}
|
|
160
|
+
return create(RichValueSchema, { value: { case: 'boolValue', value } })
|
|
179
161
|
},
|
|
180
162
|
to(v) {
|
|
181
|
-
return v.boolValue
|
|
163
|
+
return v.value.case === 'boolValue' ? v.value.value : undefined
|
|
182
164
|
}
|
|
183
165
|
}
|
|
184
166
|
|
|
185
167
|
export const TimestampConverter: ValueConverter<Timestamp | undefined> = {
|
|
186
168
|
from: (value: Timestamp | undefined) => {
|
|
187
169
|
if (value == null) {
|
|
188
|
-
return
|
|
189
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
timestampValue: value
|
|
170
|
+
return nullRichValue()
|
|
194
171
|
}
|
|
172
|
+
return create(RichValueSchema, { value: { case: 'timestampValue', value: timestampFromDate(value) } })
|
|
195
173
|
},
|
|
196
174
|
to(v) {
|
|
197
|
-
return v.timestampValue
|
|
175
|
+
return v.value.case === 'timestampValue' ? timestampDate(v.value.value) : undefined
|
|
198
176
|
}
|
|
199
177
|
}
|
|
200
178
|
|
|
201
179
|
export const BytesConverter: ValueConverter<Bytes | undefined> = {
|
|
202
180
|
from: (value?: Bytes) => {
|
|
203
181
|
if (value == null) {
|
|
204
|
-
return
|
|
205
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return {
|
|
209
|
-
bytesValue: value
|
|
182
|
+
return nullRichValue()
|
|
210
183
|
}
|
|
184
|
+
return create(RichValueSchema, { value: { case: 'bytesValue', value } })
|
|
211
185
|
},
|
|
212
186
|
to(v) {
|
|
213
|
-
return v.bytesValue
|
|
187
|
+
return v.value.case === 'bytesValue' ? v.value.value : undefined
|
|
214
188
|
}
|
|
215
189
|
}
|
|
216
190
|
|
|
217
191
|
export const IDConverter: ValueConverter<ID | undefined> = {
|
|
218
192
|
from(value: ID | undefined): RichValue {
|
|
219
193
|
if (typeof value == 'string') {
|
|
220
|
-
return {
|
|
221
|
-
stringValue: value
|
|
222
|
-
}
|
|
194
|
+
return create(RichValueSchema, { value: { case: 'stringValue', value } })
|
|
223
195
|
}
|
|
224
196
|
if (value instanceof Uint8Array) {
|
|
225
|
-
return {
|
|
226
|
-
stringValue: `0x${Buffer.from(value).toString('hex')}`
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return {
|
|
230
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
197
|
+
return create(RichValueSchema, {
|
|
198
|
+
value: { case: 'stringValue', value: `0x${Buffer.from(value).toString('hex')}` }
|
|
199
|
+
})
|
|
231
200
|
}
|
|
201
|
+
return nullRichValue()
|
|
232
202
|
},
|
|
233
203
|
to(value: RichValue): ID | undefined {
|
|
234
|
-
if (value.stringValue) {
|
|
235
|
-
return value.
|
|
204
|
+
if (value.value.case === 'stringValue' && value.value.value) {
|
|
205
|
+
return value.value.value as ID
|
|
236
206
|
}
|
|
237
|
-
if (value.bytesValue) {
|
|
238
|
-
const v = `0x${Buffer.from(value.
|
|
207
|
+
if (value.value.case === 'bytesValue' && value.value.value) {
|
|
208
|
+
const v = `0x${Buffer.from(value.value.value).toString('hex')}`
|
|
239
209
|
return v as ID
|
|
240
210
|
}
|
|
241
211
|
return undefined
|
|
@@ -245,15 +215,13 @@ export const IDConverter: ValueConverter<ID | undefined> = {
|
|
|
245
215
|
export const BigDecimalConverter: ValueConverter<BigDecimal | undefined> = {
|
|
246
216
|
from: (value?: BigDecimal): RichValue => {
|
|
247
217
|
if (value == null) {
|
|
248
|
-
return
|
|
249
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
250
|
-
}
|
|
218
|
+
return nullRichValue()
|
|
251
219
|
}
|
|
252
|
-
return { bigdecimalValue: toBigDecimal(value) }
|
|
220
|
+
return create(RichValueSchema, { value: { case: 'bigdecimalValue', value: toBigDecimal(value) } })
|
|
253
221
|
},
|
|
254
222
|
to(v) {
|
|
255
|
-
|
|
256
|
-
|
|
223
|
+
if (v.value.case === 'bigdecimalValue') {
|
|
224
|
+
const d = v.value.value
|
|
257
225
|
const i = bytesToBigInt(d.value!.data)
|
|
258
226
|
let ret = new BigDecimal(i.toString())
|
|
259
227
|
if (d.exp < 0) {
|
|
@@ -270,18 +238,14 @@ export const BigDecimalConverter: ValueConverter<BigDecimal | undefined> = {
|
|
|
270
238
|
export const BigIntConverter: ValueConverter<bigint | undefined> = {
|
|
271
239
|
from: (value?: bigint) => {
|
|
272
240
|
if (value == null) {
|
|
273
|
-
return
|
|
274
|
-
nullValue: RichValue_NullValue.NULL_VALUE
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
return {
|
|
278
|
-
bigintValue: toBigInteger(value)
|
|
241
|
+
return nullRichValue()
|
|
279
242
|
}
|
|
243
|
+
return create(RichValueSchema, { value: { case: 'bigintValue', value: toBigInteger(value) } })
|
|
280
244
|
},
|
|
281
245
|
to(v) {
|
|
282
|
-
if (v.bigintValue) {
|
|
283
|
-
let res = bytesToBigInt(v.
|
|
284
|
-
if (v.
|
|
246
|
+
if (v.value.case === 'bigintValue') {
|
|
247
|
+
let res = bytesToBigInt(v.value.value.data)
|
|
248
|
+
if (v.value.value.negative) {
|
|
285
249
|
res = -res
|
|
286
250
|
}
|
|
287
251
|
return res
|
package/src/store/decorators.ts
CHANGED
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
TypeConverters,
|
|
17
17
|
ValueConverter
|
|
18
18
|
} from './convert.js'
|
|
19
|
-
import { RichStruct } from '@sentio/protos'
|
|
19
|
+
import { type RichStruct, RichStructSchema } from '@sentio/protos'
|
|
20
|
+
import { create } from '@bufbuild/protobuf'
|
|
20
21
|
import { getStore } from './store.js'
|
|
21
22
|
|
|
22
23
|
type Constructor = { new (...args: any[]): any }
|
|
@@ -90,7 +91,7 @@ export function Entity(entityName: string) {
|
|
|
90
91
|
}
|
|
91
92
|
|
|
92
93
|
return class extends BaseClass {
|
|
93
|
-
readonly _data: RichStruct = { fields: {} }
|
|
94
|
+
readonly _data: RichStruct = create(RichStructSchema, { fields: {} })
|
|
94
95
|
static entityName = entityName
|
|
95
96
|
|
|
96
97
|
constructor(...args: any[]) {
|