@sentio/sdk 2.41.3-rc.3 → 2.41.3-rc.4
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/btc/btc-plugin.d.ts +17 -0
- package/lib/btc/btc-plugin.d.ts.map +1 -0
- package/lib/btc/btc-plugin.js +75 -0
- package/lib/btc/btc-plugin.js.map +1 -0
- package/lib/btc/btc-processor.d.ts +25 -0
- package/lib/btc/btc-processor.d.ts.map +1 -0
- package/lib/btc/btc-processor.js +30 -0
- package/lib/btc/btc-processor.js.map +1 -0
- package/lib/btc/index.d.ts +4 -0
- package/lib/btc/index.d.ts.map +1 -0
- package/lib/btc/index.js +4 -0
- package/lib/btc/index.js.map +1 -0
- package/lib/btc/types.d.ts +71 -0
- package/lib/btc/types.d.ts.map +1 -0
- package/lib/btc/types.js +31 -0
- package/lib/btc/types.js.map +1 -0
- package/lib/testing/btc-facet.d.ts +10 -0
- package/lib/testing/btc-facet.d.ts.map +1 -0
- package/lib/testing/btc-facet.js +38 -0
- package/lib/testing/btc-facet.js.map +1 -0
- package/lib/testing/test-processor-server.d.ts +2 -0
- package/lib/testing/test-processor-server.d.ts.map +1 -1
- package/lib/testing/test-processor-server.js +3 -0
- package/lib/testing/test-processor-server.js.map +1 -1
- package/package.json +6 -5
- package/src/btc/btc-plugin.ts +105 -0
- package/src/btc/btc-processor.ts +50 -0
- package/src/btc/index.ts +3 -0
- package/src/btc/types.ts +93 -0
- package/src/testing/btc-facet.ts +45 -0
- package/src/testing/test-processor-server.ts +3 -0
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            import { Plugin } from '@sentio/runtime';
         | 
| 2 | 
            +
            import { Data_BTCTransaction, DataBinding, HandlerType, ProcessConfigResponse, ProcessResult, StartRequest } from '@sentio/protos';
         | 
| 3 | 
            +
            interface Handlers {
         | 
| 4 | 
            +
                txHandlers: ((trace: Data_BTCTransaction) => Promise<ProcessResult>)[];
         | 
| 5 | 
            +
            }
         | 
| 6 | 
            +
            export declare class BTCPlugin extends Plugin {
         | 
| 7 | 
            +
                name: string;
         | 
| 8 | 
            +
                handlers: Handlers;
         | 
| 9 | 
            +
                configure(config: ProcessConfigResponse): Promise<void>;
         | 
| 10 | 
            +
                supportedHandlers: HandlerType[];
         | 
| 11 | 
            +
                processBinding(request: DataBinding): Promise<ProcessResult>;
         | 
| 12 | 
            +
                start(request: StartRequest): Promise<void>;
         | 
| 13 | 
            +
                stateDiff(config: ProcessConfigResponse): boolean;
         | 
| 14 | 
            +
                processTransaction(binding: DataBinding): Promise<ProcessResult>;
         | 
| 15 | 
            +
            }
         | 
| 16 | 
            +
            export {};
         | 
| 17 | 
            +
            //# sourceMappingURL=btc-plugin.d.ts.map
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"version":3,"file":"btc-plugin.d.ts","sourceRoot":"","sources":["../../src/btc/btc-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmD,MAAM,EAAiC,MAAM,iBAAiB,CAAA;AACxH,OAAO,EAEL,mBAAmB,EACnB,WAAW,EACX,WAAW,EACX,qBAAqB,EACrB,aAAa,EACb,YAAY,EACb,MAAM,gBAAgB,CAAA;AAMvB,UAAU,QAAQ;IAChB,UAAU,EAAE,CAAC,CAAC,KAAK,EAAE,mBAAmB,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC,EAAE,CAAA;CACvE;AAED,qBAAa,SAAU,SAAQ,MAAM;IACnC,IAAI,EAAE,MAAM,CAAc;IAC1B,QAAQ,EAAE,QAAQ,CAEjB;IAEK,SAAS,CAAC,MAAM,EAAE,qBAAqB;IAqC7C,iBAAiB,gBAAgC;IAEjD,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;IAStD,KAAK,CAAC,OAAO,EAAE,YAAY;IAEjC,SAAS,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO;IAI3C,kBAAkB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;CAuBvE"}
         | 
| @@ -0,0 +1,75 @@ | |
| 1 | 
            +
            import { errorString, GLOBAL_CONFIG, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime';
         | 
| 2 | 
            +
            import { ContractConfig, HandlerType } from '@sentio/protos';
         | 
| 3 | 
            +
            import { ServerError, Status } from 'nice-grpc';
         | 
| 4 | 
            +
            import { TemplateInstanceState } from '../core/template.js';
         | 
| 5 | 
            +
            import { BTCProcessorState } from './btc-processor.js';
         | 
| 6 | 
            +
            export class BTCPlugin extends Plugin {
         | 
| 7 | 
            +
                name = 'BTCPlugin';
         | 
| 8 | 
            +
                handlers = {
         | 
| 9 | 
            +
                    txHandlers: []
         | 
| 10 | 
            +
                };
         | 
| 11 | 
            +
                async configure(config) {
         | 
| 12 | 
            +
                    const handlers = {
         | 
| 13 | 
            +
                        txHandlers: []
         | 
| 14 | 
            +
                    };
         | 
| 15 | 
            +
                    for (const processor of BTCProcessorState.INSTANCE.getValues()) {
         | 
| 16 | 
            +
                        const contractConfig = ContractConfig.fromPartial({
         | 
| 17 | 
            +
                            processorType: USER_PROCESSOR,
         | 
| 18 | 
            +
                            contract: {
         | 
| 19 | 
            +
                                name: processor.config.name,
         | 
| 20 | 
            +
                                chainId: processor.config.chainId.toString(),
         | 
| 21 | 
            +
                                address: processor.config.address || '*',
         | 
| 22 | 
            +
                                abi: ''
         | 
| 23 | 
            +
                            },
         | 
| 24 | 
            +
                            startBlock: processor.config.startBlock,
         | 
| 25 | 
            +
                            endBlock: processor.config.endBlock
         | 
| 26 | 
            +
                        });
         | 
| 27 | 
            +
                        for (const callHandler of processor.callHandlers) {
         | 
| 28 | 
            +
                            const handlerId = handlers.txHandlers.push(callHandler.handler) - 1;
         | 
| 29 | 
            +
                            contractConfig.btcTransactionConfigs.push({
         | 
| 30 | 
            +
                                filters: [
         | 
| 31 | 
            +
                                    {
         | 
| 32 | 
            +
                                        address: contractConfig.contract?.address || '*'
         | 
| 33 | 
            +
                                    }
         | 
| 34 | 
            +
                                ],
         | 
| 35 | 
            +
                                handlerId
         | 
| 36 | 
            +
                            });
         | 
| 37 | 
            +
                        }
         | 
| 38 | 
            +
                        // Finish up a contract
         | 
| 39 | 
            +
                        config.contractConfigs.push(contractConfig);
         | 
| 40 | 
            +
                    }
         | 
| 41 | 
            +
                    this.handlers = handlers;
         | 
| 42 | 
            +
                }
         | 
| 43 | 
            +
                supportedHandlers = [HandlerType.BTC_TRANSACTION];
         | 
| 44 | 
            +
                processBinding(request) {
         | 
| 45 | 
            +
                    switch (request.handlerType) {
         | 
| 46 | 
            +
                        case HandlerType.BTC_TRANSACTION:
         | 
| 47 | 
            +
                            return this.processTransaction(request);
         | 
| 48 | 
            +
                        default:
         | 
| 49 | 
            +
                            throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType);
         | 
| 50 | 
            +
                    }
         | 
| 51 | 
            +
                }
         | 
| 52 | 
            +
                async start(request) { }
         | 
| 53 | 
            +
                stateDiff(config) {
         | 
| 54 | 
            +
                    return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length;
         | 
| 55 | 
            +
                }
         | 
| 56 | 
            +
                async processTransaction(binding) {
         | 
| 57 | 
            +
                    if (!binding.data?.btcTransaction) {
         | 
| 58 | 
            +
                        throw new ServerError(Status.INVALID_ARGUMENT, "BTCEvents can't be null");
         | 
| 59 | 
            +
                    }
         | 
| 60 | 
            +
                    const promises = [];
         | 
| 61 | 
            +
                    const result = binding.data?.btcTransaction;
         | 
| 62 | 
            +
                    for (const handlerId of binding.handlerIds) {
         | 
| 63 | 
            +
                        const promise = this.handlers.txHandlers[handlerId](binding.data?.btcTransaction).catch((e) => {
         | 
| 64 | 
            +
                            throw new ServerError(Status.INTERNAL, 'error processing transaction: ' + JSON.stringify(result) + '\n' + errorString(e));
         | 
| 65 | 
            +
                        });
         | 
| 66 | 
            +
                        if (GLOBAL_CONFIG.execution.sequential) {
         | 
| 67 | 
            +
                            await promise;
         | 
| 68 | 
            +
                        }
         | 
| 69 | 
            +
                        promises.push(promise);
         | 
| 70 | 
            +
                    }
         | 
| 71 | 
            +
                    return mergeProcessResults(await Promise.all(promises));
         | 
| 72 | 
            +
                }
         | 
| 73 | 
            +
            }
         | 
| 74 | 
            +
            PluginManager.INSTANCE.register(new BTCPlugin());
         | 
| 75 | 
            +
            //# sourceMappingURL=btc-plugin.js.map
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"version":3,"file":"btc-plugin.js","sourceRoot":"","sources":["../../src/btc/btc-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACxH,OAAO,EACL,cAAc,EAGd,WAAW,EAIZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAMtD,MAAM,OAAO,SAAU,SAAQ,MAAM;IACnC,IAAI,GAAW,WAAW,CAAA;IAC1B,QAAQ,GAAa;QACnB,UAAU,EAAE,EAAE;KACf,CAAA;IAED,KAAK,CAAC,SAAS,CAAC,MAA6B;QAC3C,MAAM,QAAQ,GAAa;YACzB,UAAU,EAAE,EAAE;SACf,CAAA;QAED,KAAK,MAAM,SAAS,IAAI,iBAAiB,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC;YAC/D,MAAM,cAAc,GAAG,cAAc,CAAC,WAAW,CAAC;gBAChD,aAAa,EAAE,cAAc;gBAC7B,QAAQ,EAAE;oBACR,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,IAAI;oBAC3B,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE;oB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IAC9F,CAAC;IAED,KAAK,CAAC,kBAAkB,CAAC,OAAoB;QAC3C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,CAAC;YAClC,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,yBAAyB,CAAC,CAAA;QAC3E,CAAC;QAED,MAAM,QAAQ,GAA6B,EAAE,CAAA;QAE7C,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,cAAc,CAAA;QAE3C,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC5F,MAAM,IAAI,WAAW,CACnB,MAAM,CAAC,QAAQ,EACf,gCAAgC,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAClF,CAAA;YACH,CAAC,CAAC,CAAA;YACF,IAAI,aAAa,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;gBACvC,MAAM,OAAO,CAAA;YACf,CAAC;YACD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACxB,CAAC;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA"}
         | 
| @@ -0,0 +1,25 @@ | |
| 1 | 
            +
            import { ListStateStorage } from '@sentio/runtime';
         | 
| 2 | 
            +
            import { BTCContext, Transaction } from './types.js';
         | 
| 3 | 
            +
            import { Data_BTCTransaction, ProcessResult } from '@sentio/protos';
         | 
| 4 | 
            +
            export declare class BTCProcessorState extends ListStateStorage<BTCProcessor> {
         | 
| 5 | 
            +
                static INSTANCE: BTCProcessorState;
         | 
| 6 | 
            +
            }
         | 
| 7 | 
            +
            export declare class BTCProcessor {
         | 
| 8 | 
            +
                readonly config: BTCProcessorConfig;
         | 
| 9 | 
            +
                callHandlers: CallHandler<Data_BTCTransaction>[];
         | 
| 10 | 
            +
                constructor(config: BTCProcessorConfig);
         | 
| 11 | 
            +
                static bind(config: BTCProcessorConfig): BTCProcessor;
         | 
| 12 | 
            +
                onTransaction(handler: (transaction: Transaction, ctx: BTCContext) => void | Promise<void>): this;
         | 
| 13 | 
            +
            }
         | 
| 14 | 
            +
            interface BTCProcessorConfig {
         | 
| 15 | 
            +
                chainId: string;
         | 
| 16 | 
            +
                name?: string;
         | 
| 17 | 
            +
                address: string;
         | 
| 18 | 
            +
                startBlock?: bigint;
         | 
| 19 | 
            +
                endBlock?: bigint;
         | 
| 20 | 
            +
            }
         | 
| 21 | 
            +
            export type CallHandler<T> = {
         | 
| 22 | 
            +
                handler: (call: T) => Promise<ProcessResult>;
         | 
| 23 | 
            +
            };
         | 
| 24 | 
            +
            export {};
         | 
| 25 | 
            +
            //# sourceMappingURL=btc-processor.d.ts.map
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"version":3,"file":"btc-processor.d.ts","sourceRoot":"","sources":["../../src/btc/btc-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACpD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnE,qBAAa,iBAAkB,SAAQ,gBAAgB,CAAC,YAAY,CAAC;IACnE,MAAM,CAAC,QAAQ,oBAA0B;CAC1C;AAED,qBAAa,YAAY;IAGX,QAAQ,CAAC,MAAM,EAAE,kBAAkB;IAF/C,YAAY,EAAE,WAAW,CAAC,mBAAmB,CAAC,EAAE,CAAK;gBAEhC,MAAM,EAAE,kBAAkB;IAE/C,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY;IAM9C,aAAa,CAAC,OAAO,EAAE,CAAC,WAAW,EAAE,WAAW,EAAE,GAAG,EAAE,UAAU,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CAkBlG;AAED,UAAU,kBAAkB;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;IAC3B,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,aAAa,CAAC,CAAA;CAC7C,CAAA"}
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            import { ListStateStorage } from '@sentio/runtime';
         | 
| 2 | 
            +
            import { BTCContext } from './types.js';
         | 
| 3 | 
            +
            export class BTCProcessorState extends ListStateStorage {
         | 
| 4 | 
            +
                static INSTANCE = new BTCProcessorState();
         | 
| 5 | 
            +
            }
         | 
| 6 | 
            +
            export class BTCProcessor {
         | 
| 7 | 
            +
                config;
         | 
| 8 | 
            +
                callHandlers = [];
         | 
| 9 | 
            +
                constructor(config) {
         | 
| 10 | 
            +
                    this.config = config;
         | 
| 11 | 
            +
                }
         | 
| 12 | 
            +
                static bind(config) {
         | 
| 13 | 
            +
                    const processor = new BTCProcessor(config);
         | 
| 14 | 
            +
                    BTCProcessorState.INSTANCE.addValue(processor);
         | 
| 15 | 
            +
                    return processor;
         | 
| 16 | 
            +
                }
         | 
| 17 | 
            +
                onTransaction(handler) {
         | 
| 18 | 
            +
                    const callHandler = {
         | 
| 19 | 
            +
                        handler: async (call) => {
         | 
| 20 | 
            +
                            const tx = call.transaction;
         | 
| 21 | 
            +
                            const ctx = new BTCContext(this.config.chainId, this.config.name ?? this.config.address ?? '', tx, this.config.address);
         | 
| 22 | 
            +
                            await handler(tx, ctx);
         | 
| 23 | 
            +
                            return ctx.stopAndGetResult();
         | 
| 24 | 
            +
                        }
         | 
| 25 | 
            +
                    };
         | 
| 26 | 
            +
                    this.callHandlers.push(callHandler);
         | 
| 27 | 
            +
                    return this;
         | 
| 28 | 
            +
                }
         | 
| 29 | 
            +
            }
         | 
| 30 | 
            +
            //# sourceMappingURL=btc-processor.js.map
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"version":3,"file":"btc-processor.js","sourceRoot":"","sources":["../../src/btc/btc-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,UAAU,EAAe,MAAM,YAAY,CAAA;AAGpD,MAAM,OAAO,iBAAkB,SAAQ,gBAA8B;IACnE,MAAM,CAAC,QAAQ,GAAG,IAAI,iBAAiB,EAAE,CAAA;;AAG3C,MAAM,OAAO,YAAY;IAGF;IAFrB,YAAY,GAAuC,EAAE,CAAA;IAErD,YAAqB,MAA0B;QAA1B,WAAM,GAAN,MAAM,CAAoB;IAAG,CAAC;IAEnD,MAAM,CAAC,IAAI,CAAC,MAA0B;QACpC,MAAM,SAAS,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAA;QAC1C,iBAAiB,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;QAC9C,OAAO,SAAS,CAAA;IAClB,CAAC;IAEM,aAAa,CAAC,OAA4E;QAC/F,MAAM,WAAW,GAAG;YAClB,OAAO,EAAE,KAAK,EAAE,IAAyB,EAAE,EAAE;gBAC3C,MAAM,EAAE,GAAG,IAAI,CAAC,WAA0B,CAAA;gBAE1C,MAAM,GAAG,GAAG,IAAI,UAAU,CACxB,IAAI,CAAC,MAAM,CAAC,OAAO,EACnB,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,EAC7C,EAAE,EACF,IAAI,CAAC,MAAM,CAAC,OAAO,CACpB,CAAA;gBACD,MAAM,OAAO,CAAC,EAAE,EAAE,GAAG,CAAC,CAAA;gBACtB,OAAO,GAAG,CAAC,gBAAgB,EAAE,CAAA;YAC/B,CAAC;SACF,CAAA;QACD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;QACnC,OAAO,IAAI,CAAA;IACb,CAAC;CACF"}
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA"}
         | 
    
        package/lib/btc/index.js
    ADDED
    
    
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/btc/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA"}
         | 
| @@ -0,0 +1,71 @@ | |
| 1 | 
            +
            import { BaseContext, Labels } from '../core/index.js';
         | 
| 2 | 
            +
            import { RecordMetaData } from '@sentio/protos';
         | 
| 3 | 
            +
            import { ChainId } from '@sentio/chain';
         | 
| 4 | 
            +
            type Vin = {
         | 
| 5 | 
            +
                txid: string;
         | 
| 6 | 
            +
                vout: number;
         | 
| 7 | 
            +
                is_coinbase: boolean;
         | 
| 8 | 
            +
                scriptsig: string;
         | 
| 9 | 
            +
                scriptsig_asm: string;
         | 
| 10 | 
            +
                inner_redeemscript_asm?: string;
         | 
| 11 | 
            +
                inner_witnessscript_asm?: string;
         | 
| 12 | 
            +
                sequence: number;
         | 
| 13 | 
            +
                witness: string[];
         | 
| 14 | 
            +
                prevout: Vout;
         | 
| 15 | 
            +
                is_pegin?: boolean;
         | 
| 16 | 
            +
                issuance?: {
         | 
| 17 | 
            +
                    asset_id: string;
         | 
| 18 | 
            +
                    is_reissuance: boolean;
         | 
| 19 | 
            +
                    asset_blinding_nonce: string;
         | 
| 20 | 
            +
                    asset_entropy: string;
         | 
| 21 | 
            +
                    contract_hash: string;
         | 
| 22 | 
            +
                    assetamount?: number;
         | 
| 23 | 
            +
                    assetamountcommitment?: string;
         | 
| 24 | 
            +
                    tokenamount?: number;
         | 
| 25 | 
            +
                    tokenamountcommitment?: string;
         | 
| 26 | 
            +
                };
         | 
| 27 | 
            +
            };
         | 
| 28 | 
            +
            type Vout = {
         | 
| 29 | 
            +
                scriptpubkey: string;
         | 
| 30 | 
            +
                scriptpubkey_asm: string;
         | 
| 31 | 
            +
                scriptpubkey_type: string;
         | 
| 32 | 
            +
                scriptpubkey_address: string;
         | 
| 33 | 
            +
                value: number;
         | 
| 34 | 
            +
                valuecommitment?: string;
         | 
| 35 | 
            +
                asset?: string;
         | 
| 36 | 
            +
                assetcommitment?: string;
         | 
| 37 | 
            +
                pegout?: {
         | 
| 38 | 
            +
                    genesis_hash: string;
         | 
| 39 | 
            +
                    scriptpubkey: string;
         | 
| 40 | 
            +
                    scriptpubkey_asm: string;
         | 
| 41 | 
            +
                    scriptpubkey_address: string;
         | 
| 42 | 
            +
                };
         | 
| 43 | 
            +
            };
         | 
| 44 | 
            +
            type Status = {
         | 
| 45 | 
            +
                confirmed: boolean;
         | 
| 46 | 
            +
                block_height?: number;
         | 
| 47 | 
            +
                block_hash?: string;
         | 
| 48 | 
            +
                block_time?: number;
         | 
| 49 | 
            +
            };
         | 
| 50 | 
            +
            export type Transaction = {
         | 
| 51 | 
            +
                txid: string;
         | 
| 52 | 
            +
                version: number;
         | 
| 53 | 
            +
                locktime: number;
         | 
| 54 | 
            +
                size: number;
         | 
| 55 | 
            +
                weight: number;
         | 
| 56 | 
            +
                fee: number;
         | 
| 57 | 
            +
                vin: Vin[];
         | 
| 58 | 
            +
                vout: Vout[];
         | 
| 59 | 
            +
                status: Status;
         | 
| 60 | 
            +
            };
         | 
| 61 | 
            +
            export declare class BTCContext extends BaseContext {
         | 
| 62 | 
            +
                readonly chainId: string;
         | 
| 63 | 
            +
                readonly name: string;
         | 
| 64 | 
            +
                readonly tx: Transaction;
         | 
| 65 | 
            +
                readonly address: string;
         | 
| 66 | 
            +
                constructor(chainId: string, name: string, tx: Transaction, address: string);
         | 
| 67 | 
            +
                protected getMetaDataInternal(name: string, labels: Labels): RecordMetaData;
         | 
| 68 | 
            +
                getChainId(): ChainId;
         | 
| 69 | 
            +
            }
         | 
| 70 | 
            +
            export {};
         | 
| 71 | 
            +
            //# sourceMappingURL=types.d.ts.map
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAmB,MAAM,kBAAkB,CAAA;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,KAAK,GAAG,GAAG;IACT,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,OAAO,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,sBAAsB,CAAC,EAAE,MAAM,CAAA;IAC/B,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,OAAO,EAAE,IAAI,CAAA;IACb,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,QAAQ,CAAC,EAAE;QACT,QAAQ,EAAE,MAAM,CAAA;QAChB,aAAa,EAAE,OAAO,CAAA;QACtB,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AAQ,WAAW;IAEvC,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM;IACrB,QAAQ,CAAC,EAAE,EAAE,WAAW;IACxB,QAAQ,CAAC,OAAO,EAAE,MAAM;gBAHf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,WAAW,EACf,OAAO,EAAE,MAAM;IAK1B,SAAS,CAAC,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc;IAc3E,UAAU,IAAI,OAAO;CAGtB"}
         | 
    
        package/lib/btc/types.js
    ADDED
    
    | @@ -0,0 +1,31 @@ | |
| 1 | 
            +
            import { BaseContext, normalizeLabels } from '../core/index.js';
         | 
| 2 | 
            +
            export class BTCContext extends BaseContext {
         | 
| 3 | 
            +
                chainId;
         | 
| 4 | 
            +
                name;
         | 
| 5 | 
            +
                tx;
         | 
| 6 | 
            +
                address;
         | 
| 7 | 
            +
                constructor(chainId, name, tx, address) {
         | 
| 8 | 
            +
                    super({});
         | 
| 9 | 
            +
                    this.chainId = chainId;
         | 
| 10 | 
            +
                    this.name = name;
         | 
| 11 | 
            +
                    this.tx = tx;
         | 
| 12 | 
            +
                    this.address = address;
         | 
| 13 | 
            +
                }
         | 
| 14 | 
            +
                getMetaDataInternal(name, labels) {
         | 
| 15 | 
            +
                    return {
         | 
| 16 | 
            +
                        address: this.address,
         | 
| 17 | 
            +
                        contractName: this.name,
         | 
| 18 | 
            +
                        blockNumber: BigInt(this.tx.status?.block_time ?? 0),
         | 
| 19 | 
            +
                        transactionIndex: 0,
         | 
| 20 | 
            +
                        transactionHash: this.tx.txid,
         | 
| 21 | 
            +
                        chainId: this.getChainId(),
         | 
| 22 | 
            +
                        name: name,
         | 
| 23 | 
            +
                        logIndex: 0,
         | 
| 24 | 
            +
                        labels: normalizeLabels(labels)
         | 
| 25 | 
            +
                    };
         | 
| 26 | 
            +
                }
         | 
| 27 | 
            +
                getChainId() {
         | 
| 28 | 
            +
                    return this.chainId;
         | 
| 29 | 
            +
                }
         | 
| 30 | 
            +
            }
         | 
| 31 | 
            +
            //# sourceMappingURL=types.js.map
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/btc/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAU,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAiEvE,MAAM,OAAO,UAAW,SAAQ,WAAW;IAE9B;IACA;IACA;IACA;IAJX,YACW,OAAe,EACf,IAAY,EACZ,EAAe,EACf,OAAe;QAExB,KAAK,CAAC,EAAE,CAAC,CAAA;QALA,YAAO,GAAP,OAAO,CAAQ;QACf,SAAI,GAAJ,IAAI,CAAQ;QACZ,OAAE,GAAF,EAAE,CAAa;QACf,YAAO,GAAP,OAAO,CAAQ;IAG1B,CAAC;IAES,mBAAmB,CAAC,IAAY,EAAE,MAAc;QACxD,OAAO;YACL,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,YAAY,EAAE,IAAI,CAAC,IAAI;YACvB,WAAW,EAAE,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,IAAI,CAAC,CAAC;YACpD,gBAAgB,EAAE,CAAC;YACnB,eAAe,EAAE,IAAI,CAAC,EAAE,CAAC,IAAI;YAC7B,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YAC1B,IAAI,EAAE,IAAI;YACV,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;SAChC,CAAA;IACH,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,OAAkB,CAAA;IAChC,CAAC;CACF"}
         | 
| @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            import { TestProcessorServer } from './test-processor-server.js';
         | 
| 2 | 
            +
            import { BTCChainId } from '@sentio/chain';
         | 
| 3 | 
            +
            import '../btc/btc-plugin.js';
         | 
| 4 | 
            +
            export declare class BTCFacet {
         | 
| 5 | 
            +
                server: TestProcessorServer;
         | 
| 6 | 
            +
                constructor(server: TestProcessorServer);
         | 
| 7 | 
            +
                testOnTransactions(events: any, network?: BTCChainId): Promise<import("@sentio/protos").ProcessBindingResponse>;
         | 
| 8 | 
            +
                private buildBinding;
         | 
| 9 | 
            +
            }
         | 
| 10 | 
            +
            //# sourceMappingURL=btc-facet.d.ts.map
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"version":3,"file":"btc-facet.d.ts","sourceRoot":"","sources":["../../src/testing/btc-facet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,sBAAsB,CAAA;AAE7B,qBAAa,QAAQ;IACnB,MAAM,EAAE,mBAAmB,CAAA;gBAEf,MAAM,EAAE,mBAAmB;IAIvC,kBAAkB,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,GAAE,UAAmC;IAW5E,OAAO,CAAC,YAAY;CAqBrB"}
         | 
| @@ -0,0 +1,38 @@ | |
| 1 | 
            +
            import { HandlerType } from '@sentio/protos';
         | 
| 2 | 
            +
            import { BTCChainId } from '@sentio/chain';
         | 
| 3 | 
            +
            import '../btc/btc-plugin.js';
         | 
| 4 | 
            +
            export class BTCFacet {
         | 
| 5 | 
            +
                server;
         | 
| 6 | 
            +
                constructor(server) {
         | 
| 7 | 
            +
                    this.server = server;
         | 
| 8 | 
            +
                }
         | 
| 9 | 
            +
                testOnTransactions(events, network = BTCChainId.BTC_TESTNET) {
         | 
| 10 | 
            +
                    const bindings = this.buildBinding(events, network);
         | 
| 11 | 
            +
                    if (!bindings) {
         | 
| 12 | 
            +
                        throw Error('Invalid test : ' + JSON.stringify(events));
         | 
| 13 | 
            +
                    }
         | 
| 14 | 
            +
                    return this.server.processBindings({
         | 
| 15 | 
            +
                        bindings
         | 
| 16 | 
            +
                    });
         | 
| 17 | 
            +
                }
         | 
| 18 | 
            +
                buildBinding(data, network) {
         | 
| 19 | 
            +
                    const res = [];
         | 
| 20 | 
            +
                    for (const config of this.server.contractConfigs) {
         | 
| 21 | 
            +
                        if (config.contract?.chainId !== network) {
         | 
| 22 | 
            +
                            continue;
         | 
| 23 | 
            +
                        }
         | 
| 24 | 
            +
                        for (const txConfig of config.btcTransactionConfigs) {
         | 
| 25 | 
            +
                            const binding = {
         | 
| 26 | 
            +
                                data: {
         | 
| 27 | 
            +
                                    btcTransaction: data
         | 
| 28 | 
            +
                                },
         | 
| 29 | 
            +
                                handlerIds: [txConfig.handlerId],
         | 
| 30 | 
            +
                                handlerType: HandlerType.BTC_TRANSACTION
         | 
| 31 | 
            +
                            };
         | 
| 32 | 
            +
                            res.push(binding);
         | 
| 33 | 
            +
                        }
         | 
| 34 | 
            +
                    }
         | 
| 35 | 
            +
                    return res;
         | 
| 36 | 
            +
                }
         | 
| 37 | 
            +
            }
         | 
| 38 | 
            +
            //# sourceMappingURL=btc-facet.js.map
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"version":3,"file":"btc-facet.js","sourceRoot":"","sources":["../../src/testing/btc-facet.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,WAAW,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,sBAAsB,CAAA;AAE7B,MAAM,OAAO,QAAQ;IACnB,MAAM,CAAqB;IAE3B,YAAY,MAA2B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,kBAAkB,CAAC,MAAW,EAAE,UAAsB,UAAU,CAAC,WAAW;QAC1E,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACnD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,KAAK,CAAC,iBAAiB,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;QACzD,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YACjC,QAAQ;SACT,CAAC,CAAA;IACJ,CAAC;IAEO,YAAY,CAAC,IAAS,EAAE,OAAmB;QACjD,MAAM,GAAG,GAAkB,EAAE,CAAA;QAE7B,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,EAAE,CAAC;YACjD,IAAI,MAAM,CAAC,QAAQ,EAAE,OAAO,KAAK,OAAO,EAAE,CAAC;gBACzC,SAAQ;YACV,CAAC;YAED,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,qBAAqB,EAAE,CAAC;gBACpD,MAAM,OAAO,GAAG;oBACd,IAAI,EAAE;wBACJ,cAAc,EAAE,IAAI;qBACrB;oBACD,UAAU,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;oBAChC,WAAW,EAAE,WAAW,CAAC,eAAe;iBAC1B,CAAA;gBAChB,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC;CACF"}
         | 
| @@ -8,6 +8,7 @@ import { SuiFacet } from './sui-facet.js'; | |
| 8 8 | 
             
            import { FuelFacet } from './fuel-facet.js';
         | 
| 9 9 | 
             
            import { CosmosFacet } from './cosmos-facet.js';
         | 
| 10 10 | 
             
            import { StarknetFacet } from './starknet-facet.js';
         | 
| 11 | 
            +
            import { BTCFacet } from './btc-facet.js';
         | 
| 11 12 | 
             
            export declare const TEST_CONTEXT: CallContext;
         | 
| 12 13 | 
             
            export declare function cleanTest(): void;
         | 
| 13 14 | 
             
            export declare class TestProcessorServer implements ProcessorServiceImplementation {
         | 
| @@ -21,6 +22,7 @@ export declare class TestProcessorServer implements ProcessorServiceImplementati | |
| 21 22 | 
             
                fuel: FuelFacet;
         | 
| 22 23 | 
             
                cosmos: CosmosFacet;
         | 
| 23 24 | 
             
                starknet: StarknetFacet;
         | 
| 25 | 
            +
                btc: BTCFacet;
         | 
| 24 26 | 
             
                constructor(loader: () => Promise<any>, httpEndpoints?: Record<string, string>);
         | 
| 25 27 | 
             
                start(request?: StartRequest, context?: CallContext): Promise<Empty>;
         | 
| 26 28 | 
             
                stop(request: Empty, context?: CallContext): Promise<Empty>;
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"file":"test-processor-server.d.ts","sourceRoot":"","sources":["../../src/testing/test-processor-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,WAAW,EACX,WAAW,EACX,KAAK,EACL,uBAAuB,EACvB,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,8BAA8B,EAC9B,oBAAoB,EACpB,qBAAqB,EACrB,2BAA2B,EAC3B,YAAY,EACb,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAa,oBAAoB,EAAS,MAAM,iBAAiB,CAAA;AAGxE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA; | 
| 1 | 
            +
            {"version":3,"file":"test-processor-server.d.ts","sourceRoot":"","sources":["../../src/testing/test-processor-server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,WAAW,EACX,WAAW,EACX,KAAK,EACL,uBAAuB,EAC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AAM,CAAM;IAmB5E,KAAK,CAAC,OAAO,GAAE,YAAwC,EAAE,OAAO,cAAe,GAAG,OAAO,CAAC,KAAK,CAAC;IAQtG,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,cAAe,GAAG,OAAO,CAAC,KAAK,CAAC;IAI5D,SAAS,CAAC,OAAO,EAAE,oBAAoB,EAAE,OAAO,cAAe,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAIhG,eAAe,CACb,OAAO,EAAE,sBAAsB,EAC/B,OAAO,GAAE,WAA0B,GAClC,OAAO,CAAC,sBAAsB,CAAC;IAIlC,cAAc,CAAC,OAAO,EAAE,WAAW,EAAE,OAAO,GAAE,WAA0B,GAAG,OAAO,CAAC,sBAAsB,CAAC;IAI1G,qBAAqB,CACnB,QAAQ,EAAE,aAAa,CAAC,oBAAoB,CAAC,EAC7C,OAAO,EAAE,WAAW,GACnB,2BAA2B,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;IAIlE,wBAAwB,CACtB,QAAQ,EAAE,aAAa,CAAC,uBAAuB,CAAC,EAChD,OAAO,EAAE,WAAW,GACnB,2BAA2B,CAAC,WAAW,CAAC,wBAAwB,CAAC,CAAC;CAOtE"}
         | 
| @@ -7,6 +7,7 @@ import { SuiFacet } from './sui-facet.js'; | |
| 7 7 | 
             
            import { FuelFacet } from './fuel-facet.js';
         | 
| 8 8 | 
             
            import { CosmosFacet } from './cosmos-facet.js';
         | 
| 9 9 | 
             
            import { StarknetFacet } from './starknet-facet.js';
         | 
| 10 | 
            +
            import { BTCFacet } from './btc-facet.js';
         | 
| 10 11 | 
             
            export const TEST_CONTEXT = {};
         | 
| 11 12 | 
             
            export function cleanTest() {
         | 
| 12 13 | 
             
                State.reset();
         | 
| @@ -22,6 +23,7 @@ export class TestProcessorServer { | |
| 22 23 | 
             
                fuel;
         | 
| 23 24 | 
             
                cosmos;
         | 
| 24 25 | 
             
                starknet;
         | 
| 26 | 
            +
                btc;
         | 
| 25 27 | 
             
                constructor(loader, httpEndpoints = {}) {
         | 
| 26 28 | 
             
                    cleanTest();
         | 
| 27 29 | 
             
                    this.service = new ProcessorServiceImpl(loader);
         | 
| @@ -32,6 +34,7 @@ export class TestProcessorServer { | |
| 32 34 | 
             
                    this.fuel = new FuelFacet(this);
         | 
| 33 35 | 
             
                    this.cosmos = new CosmosFacet(this);
         | 
| 34 36 | 
             
                    this.starknet = new StarknetFacet(this);
         | 
| 37 | 
            +
                    this.btc = new BTCFacet(this);
         | 
| 35 38 | 
             
                    for (const k in CHAIN_MAP) {
         | 
| 36 39 | 
             
                        const http = httpEndpoints[k] || '';
         | 
| 37 40 | 
             
                        Endpoints.INSTANCE.chainServer.set(k, http);
         | 
| @@ -1 +1 @@ | |
| 1 | 
            -
            {"version":3,"file":"test-processor-server.js","sourceRoot":"","sources":["../../src/testing/test-processor-server.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA; | 
| 1 | 
            +
            {"version":3,"file":"test-processor-server.js","sourceRoot":"","sources":["../../src/testing/test-processor-server.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AACxE,OAAO,EAAE,SAAS,EAAE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,EAAE,OAAO,CAAC,CAAA;IACvD,CAAC;IAED,cAAc,CAAC,OAAoB,EAAE,UAAuB,YAAY;QACtE,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,CAAC,CAAA;IACvE,CAAC;IAED,qBAAqB,CACnB,QAA6C,EAC7C,OAAoB;QAEpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAC5C,CAAC;IAED,wBAAwB,CACtB,QAAgD,EAChD,OAAoB;QAEpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAC5C,CAAC;CAKF"}
         | 
    
        package/package.json
    CHANGED
    
    | @@ -1,6 +1,6 @@ | |
| 1 1 | 
             
            {
         | 
| 2 2 | 
             
              "name": "@sentio/sdk",
         | 
| 3 | 
            -
              "version": "2.41.3-rc. | 
| 3 | 
            +
              "version": "2.41.3-rc.4",
         | 
| 4 4 | 
             
              "license": "Apache-2.0",
         | 
| 5 5 | 
             
              "type": "module",
         | 
| 6 6 | 
             
              "exports": {
         | 
| @@ -39,7 +39,8 @@ | |
| 39 39 | 
             
                "./fuel": "./lib/fuel/index.js",
         | 
| 40 40 | 
             
                "./fuel/codegen": "./lib/fuel/codegen/index.js",
         | 
| 41 41 | 
             
                "./store": "./lib/store/index.js",
         | 
| 42 | 
            -
                "./store/codegen": "./lib/store/codegen.js"
         | 
| 42 | 
            +
                "./store/codegen": "./lib/store/codegen.js",
         | 
| 43 | 
            +
                "./btc": "./lib/btc/index.js"
         | 
| 43 44 | 
             
              },
         | 
| 44 45 | 
             
              "files": [
         | 
| 45 46 | 
             
                "{lib,src}",
         | 
| @@ -54,7 +55,7 @@ | |
| 54 55 | 
             
                "@project-serum/anchor": "^0.26.0",
         | 
| 55 56 | 
             
                "@sentio/abi-wan-kanabi": "2.2.2-1",
         | 
| 56 57 | 
             
                "@sentio/bigdecimal": "9.1.1-patch.3",
         | 
| 57 | 
            -
                "@sentio/chain": "^2.1. | 
| 58 | 
            +
                "@sentio/chain": "^2.1.6",
         | 
| 58 59 | 
             
                "@sentio/ethers-v6": "^1.0.29",
         | 
| 59 60 | 
             
                "@solana/web3.js": "1.91.8",
         | 
| 60 61 | 
             
                "@typemove/aptos": "~1.6.3",
         | 
| @@ -83,8 +84,8 @@ | |
| 83 84 | 
             
                "typechain": "^8.3.2",
         | 
| 84 85 | 
             
                "utility-types": "^3.11.0",
         | 
| 85 86 | 
             
                "yaml": "^2.3.4",
         | 
| 86 | 
            -
                "@sentio/ | 
| 87 | 
            -
                "@sentio/ | 
| 87 | 
            +
                "@sentio/runtime": "^2.41.3-rc.4",
         | 
| 88 | 
            +
                "@sentio/protos": "2.41.3-rc.4"
         | 
| 88 89 | 
             
              },
         | 
| 89 90 | 
             
              "peerDependencies": {
         | 
| 90 91 | 
             
                "tsup": "npm:@sentio/tsup@^6.7.2"
         | 
| @@ -0,0 +1,105 @@ | |
| 1 | 
            +
            import { errorString, GLOBAL_CONFIG, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'
         | 
| 2 | 
            +
            import {
         | 
| 3 | 
            +
              ContractConfig,
         | 
| 4 | 
            +
              Data_BTCTransaction,
         | 
| 5 | 
            +
              DataBinding,
         | 
| 6 | 
            +
              HandlerType,
         | 
| 7 | 
            +
              ProcessConfigResponse,
         | 
| 8 | 
            +
              ProcessResult,
         | 
| 9 | 
            +
              StartRequest
         | 
| 10 | 
            +
            } from '@sentio/protos'
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            import { ServerError, Status } from 'nice-grpc'
         | 
| 13 | 
            +
            import { TemplateInstanceState } from '../core/template.js'
         | 
| 14 | 
            +
            import { BTCProcessorState } from './btc-processor.js'
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            interface Handlers {
         | 
| 17 | 
            +
              txHandlers: ((trace: Data_BTCTransaction) => Promise<ProcessResult>)[]
         | 
| 18 | 
            +
            }
         | 
| 19 | 
            +
             | 
| 20 | 
            +
            export class BTCPlugin extends Plugin {
         | 
| 21 | 
            +
              name: string = 'BTCPlugin'
         | 
| 22 | 
            +
              handlers: Handlers = {
         | 
| 23 | 
            +
                txHandlers: []
         | 
| 24 | 
            +
              }
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              async configure(config: ProcessConfigResponse) {
         | 
| 27 | 
            +
                const handlers: Handlers = {
         | 
| 28 | 
            +
                  txHandlers: []
         | 
| 29 | 
            +
                }
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                for (const processor of BTCProcessorState.INSTANCE.getValues()) {
         | 
| 32 | 
            +
                  const contractConfig = ContractConfig.fromPartial({
         | 
| 33 | 
            +
                    processorType: USER_PROCESSOR,
         | 
| 34 | 
            +
                    contract: {
         | 
| 35 | 
            +
                      name: processor.config.name,
         | 
| 36 | 
            +
                      chainId: processor.config.chainId.toString(),
         | 
| 37 | 
            +
                      address: processor.config.address || '*',
         | 
| 38 | 
            +
                      abi: ''
         | 
| 39 | 
            +
                    },
         | 
| 40 | 
            +
                    startBlock: processor.config.startBlock,
         | 
| 41 | 
            +
                    endBlock: processor.config.endBlock
         | 
| 42 | 
            +
                  })
         | 
| 43 | 
            +
                  for (const callHandler of processor.callHandlers) {
         | 
| 44 | 
            +
                    const handlerId = handlers.txHandlers.push(callHandler.handler) - 1
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                    contractConfig.btcTransactionConfigs.push({
         | 
| 47 | 
            +
                      filters: [
         | 
| 48 | 
            +
                        {
         | 
| 49 | 
            +
                          address: contractConfig.contract?.address || '*'
         | 
| 50 | 
            +
                        }
         | 
| 51 | 
            +
                      ],
         | 
| 52 | 
            +
                      handlerId
         | 
| 53 | 
            +
                    })
         | 
| 54 | 
            +
                  }
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  // Finish up a contract
         | 
| 57 | 
            +
                  config.contractConfigs.push(contractConfig)
         | 
| 58 | 
            +
                }
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                this.handlers = handlers
         | 
| 61 | 
            +
              }
         | 
| 62 | 
            +
             | 
| 63 | 
            +
              supportedHandlers = [HandlerType.BTC_TRANSACTION]
         | 
| 64 | 
            +
             | 
| 65 | 
            +
              processBinding(request: DataBinding): Promise<ProcessResult> {
         | 
| 66 | 
            +
                switch (request.handlerType) {
         | 
| 67 | 
            +
                  case HandlerType.BTC_TRANSACTION:
         | 
| 68 | 
            +
                    return this.processTransaction(request)
         | 
| 69 | 
            +
                  default:
         | 
| 70 | 
            +
                    throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)
         | 
| 71 | 
            +
                }
         | 
| 72 | 
            +
              }
         | 
| 73 | 
            +
             | 
| 74 | 
            +
              async start(request: StartRequest) {}
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              stateDiff(config: ProcessConfigResponse): boolean {
         | 
| 77 | 
            +
                return TemplateInstanceState.INSTANCE.getValues().length !== config.templateInstances.length
         | 
| 78 | 
            +
              }
         | 
| 79 | 
            +
             | 
| 80 | 
            +
              async processTransaction(binding: DataBinding): Promise<ProcessResult> {
         | 
| 81 | 
            +
                if (!binding.data?.btcTransaction) {
         | 
| 82 | 
            +
                  throw new ServerError(Status.INVALID_ARGUMENT, "BTCEvents can't be null")
         | 
| 83 | 
            +
                }
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                const promises: Promise<ProcessResult>[] = []
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                const result = binding.data?.btcTransaction
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                for (const handlerId of binding.handlerIds) {
         | 
| 90 | 
            +
                  const promise = this.handlers.txHandlers[handlerId](binding.data?.btcTransaction).catch((e) => {
         | 
| 91 | 
            +
                    throw new ServerError(
         | 
| 92 | 
            +
                      Status.INTERNAL,
         | 
| 93 | 
            +
                      'error processing transaction: ' + JSON.stringify(result) + '\n' + errorString(e)
         | 
| 94 | 
            +
                    )
         | 
| 95 | 
            +
                  })
         | 
| 96 | 
            +
                  if (GLOBAL_CONFIG.execution.sequential) {
         | 
| 97 | 
            +
                    await promise
         | 
| 98 | 
            +
                  }
         | 
| 99 | 
            +
                  promises.push(promise)
         | 
| 100 | 
            +
                }
         | 
| 101 | 
            +
                return mergeProcessResults(await Promise.all(promises))
         | 
| 102 | 
            +
              }
         | 
| 103 | 
            +
            }
         | 
| 104 | 
            +
             | 
| 105 | 
            +
            PluginManager.INSTANCE.register(new BTCPlugin())
         | 
| @@ -0,0 +1,50 @@ | |
| 1 | 
            +
            import { ListStateStorage } from '@sentio/runtime'
         | 
| 2 | 
            +
            import { BTCContext, Transaction } from './types.js'
         | 
| 3 | 
            +
            import { Data_BTCTransaction, ProcessResult } from '@sentio/protos'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            export class BTCProcessorState extends ListStateStorage<BTCProcessor> {
         | 
| 6 | 
            +
              static INSTANCE = new BTCProcessorState()
         | 
| 7 | 
            +
            }
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            export class BTCProcessor {
         | 
| 10 | 
            +
              callHandlers: CallHandler<Data_BTCTransaction>[] = []
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              constructor(readonly config: BTCProcessorConfig) {}
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              static bind(config: BTCProcessorConfig): BTCProcessor {
         | 
| 15 | 
            +
                const processor = new BTCProcessor(config)
         | 
| 16 | 
            +
                BTCProcessorState.INSTANCE.addValue(processor)
         | 
| 17 | 
            +
                return processor
         | 
| 18 | 
            +
              }
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              public onTransaction(handler: (transaction: Transaction, ctx: BTCContext) => void | Promise<void>) {
         | 
| 21 | 
            +
                const callHandler = {
         | 
| 22 | 
            +
                  handler: async (call: Data_BTCTransaction) => {
         | 
| 23 | 
            +
                    const tx = call.transaction as Transaction
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    const ctx = new BTCContext(
         | 
| 26 | 
            +
                      this.config.chainId,
         | 
| 27 | 
            +
                      this.config.name ?? this.config.address ?? '',
         | 
| 28 | 
            +
                      tx,
         | 
| 29 | 
            +
                      this.config.address
         | 
| 30 | 
            +
                    )
         | 
| 31 | 
            +
                    await handler(tx, ctx)
         | 
| 32 | 
            +
                    return ctx.stopAndGetResult()
         | 
| 33 | 
            +
                  }
         | 
| 34 | 
            +
                }
         | 
| 35 | 
            +
                this.callHandlers.push(callHandler)
         | 
| 36 | 
            +
                return this
         | 
| 37 | 
            +
              }
         | 
| 38 | 
            +
            }
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            interface BTCProcessorConfig {
         | 
| 41 | 
            +
              chainId: string
         | 
| 42 | 
            +
              name?: string
         | 
| 43 | 
            +
              address: string
         | 
| 44 | 
            +
              startBlock?: bigint
         | 
| 45 | 
            +
              endBlock?: bigint
         | 
| 46 | 
            +
            }
         | 
| 47 | 
            +
             | 
| 48 | 
            +
            export type CallHandler<T> = {
         | 
| 49 | 
            +
              handler: (call: T) => Promise<ProcessResult>
         | 
| 50 | 
            +
            }
         | 
    
        package/src/btc/index.ts
    ADDED
    
    
    
        package/src/btc/types.ts
    ADDED
    
    | @@ -0,0 +1,93 @@ | |
| 1 | 
            +
            import { BaseContext, Labels, normalizeLabels } from '../core/index.js'
         | 
| 2 | 
            +
            import { RecordMetaData } from '@sentio/protos'
         | 
| 3 | 
            +
            import { ChainId } from '@sentio/chain'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            type Vin = {
         | 
| 6 | 
            +
              txid: string
         | 
| 7 | 
            +
              vout: number
         | 
| 8 | 
            +
              is_coinbase: boolean
         | 
| 9 | 
            +
              scriptsig: string
         | 
| 10 | 
            +
              scriptsig_asm: string
         | 
| 11 | 
            +
              inner_redeemscript_asm?: string
         | 
| 12 | 
            +
              inner_witnessscript_asm?: string
         | 
| 13 | 
            +
              sequence: number
         | 
| 14 | 
            +
              witness: string[]
         | 
| 15 | 
            +
              prevout: Vout
         | 
| 16 | 
            +
              is_pegin?: boolean
         | 
| 17 | 
            +
              issuance?: {
         | 
| 18 | 
            +
                asset_id: string
         | 
| 19 | 
            +
                is_reissuance: boolean
         | 
| 20 | 
            +
                asset_blinding_nonce: string
         | 
| 21 | 
            +
                asset_entropy: string
         | 
| 22 | 
            +
                contract_hash: string
         | 
| 23 | 
            +
                assetamount?: number
         | 
| 24 | 
            +
                assetamountcommitment?: string
         | 
| 25 | 
            +
                tokenamount?: number
         | 
| 26 | 
            +
                tokenamountcommitment?: string
         | 
| 27 | 
            +
              }
         | 
| 28 | 
            +
            }
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            type Vout = {
         | 
| 31 | 
            +
              scriptpubkey: string
         | 
| 32 | 
            +
              scriptpubkey_asm: string
         | 
| 33 | 
            +
              scriptpubkey_type: string
         | 
| 34 | 
            +
              scriptpubkey_address: string
         | 
| 35 | 
            +
              value: number
         | 
| 36 | 
            +
              valuecommitment?: string
         | 
| 37 | 
            +
              asset?: string
         | 
| 38 | 
            +
              assetcommitment?: string
         | 
| 39 | 
            +
              pegout?: {
         | 
| 40 | 
            +
                genesis_hash: string
         | 
| 41 | 
            +
                scriptpubkey: string
         | 
| 42 | 
            +
                scriptpubkey_asm: string
         | 
| 43 | 
            +
                scriptpubkey_address: string
         | 
| 44 | 
            +
              }
         | 
| 45 | 
            +
            }
         | 
| 46 | 
            +
             | 
| 47 | 
            +
            type Status = {
         | 
| 48 | 
            +
              confirmed: boolean
         | 
| 49 | 
            +
              block_height?: number
         | 
| 50 | 
            +
              block_hash?: string
         | 
| 51 | 
            +
              block_time?: number
         | 
| 52 | 
            +
            }
         | 
| 53 | 
            +
             | 
| 54 | 
            +
            export type Transaction = {
         | 
| 55 | 
            +
              txid: string
         | 
| 56 | 
            +
              version: number
         | 
| 57 | 
            +
              locktime: number
         | 
| 58 | 
            +
              size: number
         | 
| 59 | 
            +
              weight: number
         | 
| 60 | 
            +
              fee: number
         | 
| 61 | 
            +
              vin: Vin[]
         | 
| 62 | 
            +
              vout: Vout[]
         | 
| 63 | 
            +
              status: Status
         | 
| 64 | 
            +
            }
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            export class BTCContext extends BaseContext {
         | 
| 67 | 
            +
              constructor(
         | 
| 68 | 
            +
                readonly chainId: string,
         | 
| 69 | 
            +
                readonly name: string,
         | 
| 70 | 
            +
                readonly tx: Transaction,
         | 
| 71 | 
            +
                readonly address: string
         | 
| 72 | 
            +
              ) {
         | 
| 73 | 
            +
                super({})
         | 
| 74 | 
            +
              }
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              protected getMetaDataInternal(name: string, labels: Labels): RecordMetaData {
         | 
| 77 | 
            +
                return {
         | 
| 78 | 
            +
                  address: this.address,
         | 
| 79 | 
            +
                  contractName: this.name,
         | 
| 80 | 
            +
                  blockNumber: BigInt(this.tx.status?.block_time ?? 0),
         | 
| 81 | 
            +
                  transactionIndex: 0,
         | 
| 82 | 
            +
                  transactionHash: this.tx.txid,
         | 
| 83 | 
            +
                  chainId: this.getChainId(),
         | 
| 84 | 
            +
                  name: name,
         | 
| 85 | 
            +
                  logIndex: 0,
         | 
| 86 | 
            +
                  labels: normalizeLabels(labels)
         | 
| 87 | 
            +
                }
         | 
| 88 | 
            +
              }
         | 
| 89 | 
            +
             | 
| 90 | 
            +
              getChainId(): ChainId {
         | 
| 91 | 
            +
                return this.chainId as ChainId
         | 
| 92 | 
            +
              }
         | 
| 93 | 
            +
            }
         | 
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            import { TestProcessorServer } from './test-processor-server.js'
         | 
| 2 | 
            +
            import { DataBinding, HandlerType } from '@sentio/protos'
         | 
| 3 | 
            +
            import { BTCChainId } from '@sentio/chain'
         | 
| 4 | 
            +
            import '../btc/btc-plugin.js'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            export class BTCFacet {
         | 
| 7 | 
            +
              server: TestProcessorServer
         | 
| 8 | 
            +
             | 
| 9 | 
            +
              constructor(server: TestProcessorServer) {
         | 
| 10 | 
            +
                this.server = server
         | 
| 11 | 
            +
              }
         | 
| 12 | 
            +
             | 
| 13 | 
            +
              testOnTransactions(events: any, network: BTCChainId = BTCChainId.BTC_TESTNET) {
         | 
| 14 | 
            +
                const bindings = this.buildBinding(events, network)
         | 
| 15 | 
            +
                if (!bindings) {
         | 
| 16 | 
            +
                  throw Error('Invalid test : ' + JSON.stringify(events))
         | 
| 17 | 
            +
                }
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                return this.server.processBindings({
         | 
| 20 | 
            +
                  bindings
         | 
| 21 | 
            +
                })
         | 
| 22 | 
            +
              }
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              private buildBinding(data: any, network: BTCChainId): DataBinding[] {
         | 
| 25 | 
            +
                const res: DataBinding[] = []
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                for (const config of this.server.contractConfigs) {
         | 
| 28 | 
            +
                  if (config.contract?.chainId !== network) {
         | 
| 29 | 
            +
                    continue
         | 
| 30 | 
            +
                  }
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  for (const txConfig of config.btcTransactionConfigs) {
         | 
| 33 | 
            +
                    const binding = {
         | 
| 34 | 
            +
                      data: {
         | 
| 35 | 
            +
                        btcTransaction: data
         | 
| 36 | 
            +
                      },
         | 
| 37 | 
            +
                      handlerIds: [txConfig.handlerId],
         | 
| 38 | 
            +
                      handlerType: HandlerType.BTC_TRANSACTION
         | 
| 39 | 
            +
                    } as DataBinding
         | 
| 40 | 
            +
                    res.push(binding)
         | 
| 41 | 
            +
                  }
         | 
| 42 | 
            +
                }
         | 
| 43 | 
            +
                return res
         | 
| 44 | 
            +
              }
         | 
| 45 | 
            +
            }
         | 
| @@ -27,6 +27,7 @@ import { SuiFacet } from './sui-facet.js' | |
| 27 27 | 
             
            import { FuelFacet } from './fuel-facet.js'
         | 
| 28 28 | 
             
            import { CosmosFacet } from './cosmos-facet.js'
         | 
| 29 29 | 
             
            import { StarknetFacet } from './starknet-facet.js'
         | 
| 30 | 
            +
            import { BTCFacet } from './btc-facet.js'
         | 
| 30 31 |  | 
| 31 32 | 
             
            export const TEST_CONTEXT: CallContext = <CallContext>{}
         | 
| 32 33 |  | 
| @@ -46,6 +47,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation { | |
| 46 47 | 
             
              fuel: FuelFacet
         | 
| 47 48 | 
             
              cosmos: CosmosFacet
         | 
| 48 49 | 
             
              starknet: StarknetFacet
         | 
| 50 | 
            +
              btc: BTCFacet
         | 
| 49 51 |  | 
| 50 52 | 
             
              constructor(loader: () => Promise<any>, httpEndpoints: Record<string, string> = {}) {
         | 
| 51 53 | 
             
                cleanTest()
         | 
| @@ -58,6 +60,7 @@ export class TestProcessorServer implements ProcessorServiceImplementation { | |
| 58 60 | 
             
                this.fuel = new FuelFacet(this)
         | 
| 59 61 | 
             
                this.cosmos = new CosmosFacet(this)
         | 
| 60 62 | 
             
                this.starknet = new StarknetFacet(this)
         | 
| 63 | 
            +
                this.btc = new BTCFacet(this)
         | 
| 61 64 |  | 
| 62 65 | 
             
                for (const k in CHAIN_MAP) {
         | 
| 63 66 | 
             
                  const http = httpEndpoints[k] || ''
         |