npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ocap/tx-protocols

v1.18.116

Published

Predefined tx pipeline sets to execute certain type of transactions

Downloads

212

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);
  });

Misc

The mysterious delegator/delegatee

Generally, delegator means the party that signed an transaction to allow others to spend his token/asset, and delegatee means the party that received that grant.

In earlier Forge implementation, the Transaction.delegator should be Transaction.delegatee because whether it's delegated transaction or not, the Transaction.from should always point to the account whose balance will be updated on successful transaction execution.

But this will make some transaction protocol logic harder to understand.

  • transfer_v2:
    • balance of tx.from will be reduced
    • balance of tx.delegator does not change at all
  • exchange_v2: a bit more complicated, let's add details for this later
  • acquire_asset_v2:
    • balance of tx.from will be reduced, as payment for purchasing the asset
    • balance of tx.delegator does not change at all
    • owner of minted asset will be set to tx.delegator

The are some inconsistencies in server and client implementation code.

On the server side, delegator must be interpreted as delegatee, but in @ocap/client, delegator is interpreted as delegator. For delegated create-x transactions, the service-fee is charged against tx.from.

How to add a new tx protocol

  • Define the itx proto in core/proto/src/tx.proto
  • Rebuild proto: cd core/proto && make dep && make build
  • Enable the protocol in core/config/lib/default.js and fix the unit test
  • Create the protocol file in core/tx-protocols/lib/protocols
  • Add receipts logic for the protocol at: core/state/lib/states/tx.js
  • Add test case for the protocol: both unit and integration tests
  • Add shortcut method in @ocap/client
  • Support the protocol in block-explorer if needed: https://github.com/ArcBlock/block-explorer
  • Add use cases for the protocol in ocap-playground: https://github.com/blocklet/ocap-playground