open-index/open-npm huggingface dataset:
npm package: @ocap/tx-pipeline
Description: Pipeline runner and common pipelines to process transactions
Author: wangshijun
Latest version: 1.29.24

# OCAP Adapter

Defines the interface of OCAP query resolver.

## Usage

```shell
bun install @ocap/tx-pipeline
```

Then:

```js
const TxPipeline = require('@ocap/tx-pipeline');
const NedbAdapter = require('@ocap/statedb-nedb');

const { DecodeTx, VerifyTx, VerifyBlacklist, 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(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);
  });
```

## Pipes not supported

- [ ] VerifyModerator: chain administration
- [ ] CheckError: log info on error
- [ ] AntiReplayExchangeAttack