@sentio/sdk 2.42.0-rc.1 → 2.42.0-rc.11

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.
Files changed (46) hide show
  1. package/lib/btc/btc-plugin.d.ts.map +1 -1
  2. package/lib/btc/btc-plugin.js +7 -32
  3. package/lib/btc/btc-plugin.js.map +1 -1
  4. package/lib/btc/btc-processor.d.ts +2 -1
  5. package/lib/btc/btc-processor.d.ts.map +1 -1
  6. package/lib/btc/btc-processor.js +1 -1
  7. package/lib/btc/btc-processor.js.map +1 -1
  8. package/lib/btc/filter.d.ts +44 -0
  9. package/lib/btc/filter.d.ts.map +1 -0
  10. package/lib/btc/filter.js +127 -0
  11. package/lib/btc/filter.js.map +1 -0
  12. package/lib/btc/filter.test.d.ts +2 -0
  13. package/lib/btc/filter.test.d.ts.map +1 -0
  14. package/lib/btc/filter.test.js.map +1 -0
  15. package/lib/btc/index.d.ts +1 -0
  16. package/lib/btc/index.d.ts.map +1 -1
  17. package/lib/btc/index.js +1 -0
  18. package/lib/btc/index.js.map +1 -1
  19. package/lib/btc/types.d.ts +45 -63
  20. package/lib/btc/types.d.ts.map +1 -1
  21. package/lib/btc/types.js +1 -1
  22. package/lib/btc/types.js.map +1 -1
  23. package/lib/fuel/base-processor.d.ts +3 -3
  24. package/lib/fuel/base-processor.d.ts.map +1 -1
  25. package/lib/fuel/base-processor.js +4 -2
  26. package/lib/fuel/base-processor.js.map +1 -1
  27. package/lib/fuel/codegen/codegen.js +10 -12
  28. package/lib/fuel/codegen/codegen.js.map +1 -1
  29. package/lib/fuel/context.d.ts +9 -1
  30. package/lib/fuel/context.d.ts.map +1 -1
  31. package/lib/fuel/context.js +15 -0
  32. package/lib/fuel/context.js.map +1 -1
  33. package/lib/fuel/fuel-processor.d.ts +8 -7
  34. package/lib/fuel/fuel-processor.d.ts.map +1 -1
  35. package/lib/fuel/fuel-processor.js +7 -5
  36. package/lib/fuel/fuel-processor.js.map +1 -1
  37. package/package.json +4 -4
  38. package/src/btc/btc-plugin.ts +7 -40
  39. package/src/btc/btc-processor.ts +3 -2
  40. package/src/btc/filter.ts +206 -0
  41. package/src/btc/index.ts +1 -0
  42. package/src/btc/types.ts +47 -80
  43. package/src/fuel/base-processor.ts +7 -5
  44. package/src/fuel/codegen/codegen.ts +10 -12
  45. package/src/fuel/context.ts +13 -1
  46. package/src/fuel/fuel-processor.ts +15 -10
package/src/btc/types.ts CHANGED
@@ -1,67 +1,64 @@
1
1
  import { BaseContext, Labels, normalizeLabels } from '../core/index.js'
2
2
  import { RecordMetaData } from '@sentio/protos'
3
3
  import { ChainId } from '@sentio/chain'
4
- import { BigDecimal } from '@sentio/bigdecimal'
5
4
 
6
- type Vin = {
5
+ export type Transaction = {
7
6
  txid: string
8
- vout: number
9
- is_coinbase: boolean
10
- scriptsig: string
11
- scriptsig_asm: string
12
- inner_redeemscript_asm?: string
13
- inner_witnessscript_asm?: string
7
+ hash: string
8
+ txindex: number
9
+ blockhash: string
10
+ blockheight: number
11
+ blocktime: number
12
+ size: number
13
+ vsize: number
14
+ version: number
15
+ locktime: number
16
+ vin: Vin[]
17
+ vout: Vout[]
18
+ }
19
+
20
+ export type Vin = {
21
+ vin_index: number
22
+ coinbase?: string
23
+ txid?: string
24
+ vout?: number
14
25
  sequence: number
15
- witness: string[]
16
- prevout: Vout
17
- is_pegin?: boolean
18
- issuance?: {
19
- asset_id: string
20
- is_reissuance: boolean
21
- asset_blinding_nonce: string
22
- asset_entropy: string
23
- contract_hash: string
24
- assetamount?: number
25
- assetamountcommitment?: string
26
- tokenamount?: number
27
- tokenamountcommitment?: string
26
+ witness?: string[]
27
+ scriptSig: {
28
+ asm: string
29
+ hex: string
28
30
  }
31
+ pre_vout?: Vout
32
+ pre_transaction?: Transaction
29
33
  }
30
34
 
31
- type Vout = {
32
- scriptpubkey: string
33
- scriptpubkey_asm: string
34
- scriptpubkey_type: string
35
- scriptpubkey_address: string
35
+ export type Vout = {
36
36
  value: number
37
- valuecommitment?: string
38
- asset?: string
39
- assetcommitment?: string
40
- pegout?: {
41
- genesis_hash: string
42
- scriptpubkey: string
43
- scriptpubkey_asm: string
44
- scriptpubkey_address: string
37
+ n: number
38
+ scriptPubKey: {
39
+ asm: string
40
+ hex: string
41
+ reqSigs: number
42
+ type: string
43
+ address: string
45
44
  }
46
45
  }
47
46
 
48
- type Status = {
49
- confirmed: boolean
50
- block_height?: number
51
- block_hash?: string
52
- block_time?: number
53
- }
54
-
55
- export type Transaction = {
56
- txid: string
57
- version: number
58
- locktime: number
47
+ export type Block = {
48
+ block_hash: string
49
+ block_number: number
50
+ block_timestamp: Date
59
51
  size: number
52
+ stripped_size: number
60
53
  weight: number
61
- fee: number
62
- vin: Vin[]
63
- vout: Vout[]
64
- status: Status
54
+ version: number
55
+ merkle_root: string
56
+ nonce: number
57
+ bits: string
58
+ difficulty: number
59
+ previous_hash: string
60
+ next_hash: string
61
+ transaction_count: number
65
62
  }
66
63
 
67
64
  export class BTCContext extends BaseContext {
@@ -78,7 +75,7 @@ export class BTCContext extends BaseContext {
78
75
  return {
79
76
  address: this.address,
80
77
  contractName: this.name,
81
- blockNumber: BigInt(this.tx.status?.block_time ?? 0),
78
+ blockNumber: BigInt(this.tx.blockheight ?? 0),
82
79
  transactionIndex: 0,
83
80
  transactionHash: this.tx.txid,
84
81
  chainId: this.getChainId(),
@@ -92,33 +89,3 @@ export class BTCContext extends BaseContext {
92
89
  return this.chainId as ChainId
93
90
  }
94
91
  }
95
-
96
- export type TransactionFilter = {
97
- field:
98
- | 'vin.txid'
99
- | 'vin.vout'
100
- | 'vin.is_coinbase'
101
- | 'vin.scriptsig'
102
- | 'vin.scriptsig_asm'
103
- | 'vout.scriptpubkey'
104
- | 'vout.scriptpubkey_asm'
105
- | 'vout.scriptpubkey_type'
106
- | 'vout.scriptpubkey_address'
107
- | 'vout.value'
108
- | 'status.block_height'
109
- | 'status.block_hash'
110
- | 'status.block_time'
111
- prefix?: string
112
- equals?: Comparable
113
- gt?: Comparable
114
- gte?: Comparable
115
- lt?: Comparable
116
- lte?: Comparable
117
- ne?: Comparable
118
- contains?: string
119
- not_contains?: string
120
- }
121
-
122
- type Comparable = number | BigDecimal | bigint | Date
123
-
124
- export type TransactionFilters = TransactionFilter | TransactionFilter[]
@@ -1,19 +1,21 @@
1
1
  import { FuelProcessor, FuelProcessorConfig } from './fuel-processor.js'
2
- import { JsonAbi } from 'fuels'
2
+ import { Contract, JsonAbi } from 'fuels'
3
3
  // import { FuelCall } from './context.js'
4
4
  import { FuelChainId } from '@sentio/chain'
5
5
  import { FuelLog, FuelProcessorState } from './types.js'
6
6
 
7
- export abstract class FuelAbstractProcessor extends FuelProcessor {
8
- protected constructor(abi: JsonAbi, config?: FuelProcessorConfig) {
7
+ export abstract class FuelAbstractProcessor<TContract extends Contract> extends FuelProcessor<TContract> {
8
+ protected constructor(abi: JsonAbi, config?: Omit<FuelProcessorConfig, 'abi'>) {
9
9
  if (!config) {
10
10
  config = {
11
11
  chainId: FuelChainId.FUEL_MAINNET,
12
12
  address: '*'
13
13
  }
14
14
  }
15
- config.abi = abi
16
- super(config)
15
+ super({
16
+ ...config,
17
+ abi
18
+ })
17
19
  FuelProcessorState.INSTANCE.addValue(this)
18
20
  }
19
21
  }
@@ -115,7 +115,7 @@ async function codegenInternal(abisDir: string, outDir: string): Promise<number>
115
115
  /* tslint:disable */
116
116
  /* eslint-disable */
117
117
 
118
- import { FuelAbstractProcessor, FuelContext, FuelProcessorConfig, TypedCall, FuelFetchConfig, FuelCall, FuelLog} from '@sentio/sdk/fuel'
118
+ import { FuelAbstractProcessor, FuelContractContext, FuelProcessorConfig, TypedCall, FuelFetchConfig, FuelCall, FuelLog} from '@sentio/sdk/fuel'
119
119
  import {${abi.commonTypesInUse.join(',')}} from './common.js'
120
120
  import {${importedTypes.join(',')}, ${abi.capitalizedName}} from './${abi.capitalizedName}.js'
121
121
 
@@ -144,13 +144,9 @@ ${
144
144
  }
145
145
  }
146
146
 
147
- export class ${name}Processor extends FuelAbstractProcessor {
148
- constructor(config?: FuelProcessorConfig) {
149
- super(${abi.capitalizedName}.abi, config)
150
- }
151
-
152
- static bind(config: FuelProcessorConfig) {
153
- return new ${name}Processor({
147
+ export class ${name}Processor extends FuelAbstractProcessor<${name}> {
148
+ static bind(config: Omit<FuelProcessorConfig, 'abi'>) {
149
+ return new ${name}Processor(${abi.capitalizedName}.abi, {
154
150
  name: '${name}',
155
151
  ...config,
156
152
  })
@@ -162,7 +158,9 @@ ${
162
158
  abi.functions.map((f) => genOnCallFunction(name, f)).join('\n') */
163
159
  }
164
160
 
165
- ${Object.entries(logByTypes).map(genOnLogFunction).join('\n')}
161
+ ${Object.entries(logByTypes)
162
+ .map((e) => genOnLogFunction(name, e))
163
+ .join('\n')}
166
164
 
167
165
  }
168
166
  `
@@ -200,7 +198,7 @@ function genCallType(f: IFunction) {
200
198
  function genOnCallFunction(contractName: string, f: IFunction) {
201
199
  const name = upperFirst(f.name)
202
200
  return `
203
- onCall${name}(handler: (call: ${contractName}.${name}Call, ctx: FuelContext) => void | Promise<void>, config?: FuelFetchConfig) {
201
+ onCall${name}(handler: (call: ${contractName}.${name}Call, ctx: FuelContractContext<${contractName}>) => void | Promise<void>, config?: FuelFetchConfig) {
204
202
  return super.onCall('${f.name}', (call, ctx) => handler(new ${contractName}.${name}Call(call), ctx), config)
205
203
  }`
206
204
  }
@@ -217,10 +215,10 @@ function collectImportedTypes(types: any[]): string[] {
217
215
  return Array.from(ret)
218
216
  }
219
217
 
220
- function genOnLogFunction([type, ids]: [string, string[]]) {
218
+ function genOnLogFunction(contractName: string, [type, ids]: [string, string[]]) {
221
219
  const name = getTypeName(type)
222
220
  return `
223
- onLog${name}(handler: (log: FuelLog<${type}>, ctx: FuelContext) => void | Promise<void>, logIdFilter?: string | string[]) {
221
+ onLog${name}(handler: (log: FuelLog<${type}>, ctx: FuelContractContext<${contractName}>) => void | Promise<void>, logIdFilter?: string | string[]) {
224
222
  return super.onLog<${type}>(logIdFilter ?? [${ids.map((id) => `"${id}"`).join(', ')}], (log, ctx) => handler(log, ctx))
225
223
  }`
226
224
  }
@@ -1,7 +1,7 @@
1
1
  import { BaseContext, Labels, normalizeLabels } from '../core/index.js'
2
2
  import { ChainId } from '@sentio/chain'
3
3
  import { RecordMetaData } from '@sentio/protos'
4
- import type { CallResult } from 'fuels'
4
+ import type { CallResult, Contract } from 'fuels'
5
5
  import { InvocationScopeLike } from 'fuels'
6
6
  import { FuelTransaction } from './transaction.js'
7
7
  import { FuelLog } from './types.js'
@@ -51,3 +51,15 @@ export class FuelContext extends BaseContext {
51
51
  }
52
52
  }
53
53
  }
54
+
55
+ export class FuelContractContext<TContract extends Contract> extends FuelContext {
56
+ constructor(
57
+ readonly chainId: ChainId,
58
+ readonly contract: TContract,
59
+ readonly contractAddress: string,
60
+ readonly contractName: string,
61
+ readonly transaction: FuelTransaction | null
62
+ ) {
63
+ super(chainId, contractAddress, contractName, transaction)
64
+ }
65
+ }
@@ -1,5 +1,5 @@
1
1
  import { Data_FuelCall, FuelCallFilter, ProcessResult } from '@sentio/protos'
2
- import { FuelCall, FuelContext } from './context.js'
2
+ import { FuelCall, FuelContext, FuelContractContext } from './context.js'
3
3
  import { bn, Contract, Interface, JsonAbi, Provider } from 'fuels'
4
4
  import { FuelNetwork, getRpcEndpoint } from './network.js'
5
5
  import {
@@ -11,12 +11,13 @@ import {
11
11
  import { CallHandler, FuelBaseProcessor, FuelLog, FuelProcessorState } from './types.js'
12
12
  import { mergeProcessResults } from '@sentio/runtime'
13
13
 
14
- export class FuelProcessor implements FuelBaseProcessor<FuelProcessorConfig> {
14
+ export class FuelProcessor<TContract extends Contract> implements FuelBaseProcessor<FuelProcessorConfig> {
15
15
  callHandlers: CallHandler<Data_FuelCall>[] = []
16
16
 
17
17
  private provider: Provider
18
+ private contract: TContract
18
19
 
19
- static bind(config: FuelProcessorConfig): FuelProcessor {
20
+ static bind(config: FuelProcessorConfig): FuelProcessor<any> {
20
21
  const processor = new FuelProcessor(config)
21
22
  FuelProcessorState.INSTANCE.addValue(processor)
22
23
  return processor
@@ -37,10 +38,12 @@ export class FuelProcessor implements FuelBaseProcessor<FuelProcessorConfig> {
37
38
  this.latestGasPrice = latestGasPrice?.gasPrice
38
39
  return bn(latestGasPrice.gasPrice)
39
40
  }
41
+
42
+ this.contract = new Contract(this.config.address, this.config.abi!, this.provider) as TContract
40
43
  }
41
44
 
42
45
  public onTransaction(
43
- handler: (transaction: FuelTransaction, ctx: FuelContext) => void | Promise<void>,
46
+ handler: (transaction: FuelTransaction, ctx: FuelContractContext<TContract>) => void | Promise<void>,
44
47
  config: FuelFetchConfig = DEFAULT_FUEL_FETCH_CONFIG
45
48
  ) {
46
49
  const callHandler = {
@@ -52,8 +55,9 @@ export class FuelProcessor implements FuelBaseProcessor<FuelProcessorConfig> {
52
55
  : {}
53
56
  const tx = await decodeFuelTransactionWithAbi(call.transaction, abiMap, this.provider)
54
57
 
55
- const ctx = new FuelContext(
58
+ const ctx = new FuelContractContext(
56
59
  this.config.chainId,
60
+ this.contract,
57
61
  this.config.address,
58
62
  this.config.name ?? this.config.address,
59
63
  tx
@@ -101,7 +105,7 @@ export class FuelProcessor implements FuelBaseProcessor<FuelProcessorConfig> {
101
105
  const callHandler = {
102
106
  handler: async (call: Data_FuelCall) => {
103
107
  try {
104
- const contract = new Contract(this.config.address, abi, this.provider)
108
+ // const contract = new Contract(this.config.address, abi, this.provider)
105
109
  const gqlTransaction = call.transaction
106
110
  const tx = await decodeFuelTransactionWithAbi(gqlTransaction, { [this.config.address]: abi }, this.provider)
107
111
 
@@ -114,7 +118,7 @@ export class FuelProcessor implements FuelBaseProcessor<FuelProcessorConfig> {
114
118
  for (const op of tx.operations) {
115
119
  for (const call of op.calls || []) {
116
120
  if (names.has(call.functionName)) {
117
- const fn = contract.functions[call.functionName]
121
+ const fn = this.contract.functions[call.functionName]
118
122
  const args = Object.values(call.argumentsProvided || {})
119
123
  const scope = fn(...args)
120
124
  const invocationResult = new FuelCall(scope, tx, false, call.argumentsProvided, tx.logs)
@@ -147,7 +151,7 @@ export class FuelProcessor implements FuelBaseProcessor<FuelProcessorConfig> {
147
151
 
148
152
  public onLog<T>(
149
153
  logIdFilter: string | string[],
150
- handler: (logs: FuelLog<T>, ctx: FuelContext) => void | Promise<void>
154
+ handler: (logs: FuelLog<T>, ctx: FuelContractContext<TContract>) => void | Promise<void>
151
155
  ) {
152
156
  const logIds = new Set(Array.isArray(logIdFilter) ? logIdFilter : [logIdFilter])
153
157
 
@@ -164,8 +168,9 @@ export class FuelProcessor implements FuelBaseProcessor<FuelProcessorConfig> {
164
168
  const results: ProcessResult[] = []
165
169
  const logs = (tx.logs || []).filter((log) => logIds.has(log.logId))
166
170
  for (const log of logs) {
167
- const ctx = new FuelContext(
171
+ const ctx = new FuelContractContext(
168
172
  this.config.chainId,
173
+ this.contract,
169
174
  this.config.address,
170
175
  this.config.name ?? this.config.address,
171
176
  tx
@@ -203,5 +208,5 @@ export type FuelProcessorConfig = {
203
208
  chainId: FuelNetwork
204
209
  startBlock?: bigint
205
210
  endBlock?: bigint
206
- abi?: JsonAbi
211
+ abi: JsonAbi
207
212
  }