JSPM

@ocap/tx-protocols

1.8.3
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 8268
    • Score
      100M100P100Q132067F
    • License MIT

    Predefined tx pipeline sets to execute certain type of transactions

    Package Exports

    • @ocap/tx-protocols
    • @ocap/tx-protocols/lib/util

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@ocap/tx-protocols) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    Tx Protocols

    Defines the interface of OCAP query resolver.

    Usage

    yarn add @ocap/tx-pipeline

    Then:

    const TxPipeline = require('@ocap/tx-pipeline');
    const NedbAdapter = require('@ocap/statedb-nedb');
    
    const { DecodeTx, VerifyTx, VerifyBlacklist, VerifyReplay, DecodeItx, VerifySignature, ExtractState } = TxPipeline;
    // Pre-pipelines
    // Check-pipelines: formal
    // Verify-pipelines: against state db
    // Update-pipelines: change state db
    
    // Create pipeline, this should be defined in `@ocap/tx-protocols`
    const pipeline = new TxPipeline('transfer');
    
    // Reuse common pipeline
    pipeline.use(DecodeTx);
    pipeline.use(VerifyTx);
    pipeline.use(VerifyBlacklist);
    pipeline.use(VerifyReplay);
    pipeline.use(DecodeItx);
    pipeline.use(VerifySignature);
    pipeline.use(ExtractState({ from: 'tx.from', to: 'senderState' }));
    
    // Attach custom pipeline
    pipeline.use(async ({ itx, tx, context, states }, options) => {
      // Do something
    });
    
    // Execute transactions
    const transaction = {}; // object or base64 encoded string
    const adapter = new NedbAdapter({ dbPath: '/path/to/db' });
    pipeline
      .execute(pipeline, adapter)
      .then((hash) => {
        console.info('Transaction execution success', hash);
      })
      .catch((err) => {
        console.error('Transaction execution failed', err.message);
      });