0.5.0 • Published 2 years ago

@cardano-sdk/cip2 v0.5.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Cardano JS SDK | CIP2 | Input Selection

This package implements concepts from the draft specification being developed in CIP-0002.

Currently there is only 1 input selection algorithm: RoundRobinRandomImprove, which is a Random-Improve adaptation that handles asset selection.

Usage Example

import { roundRobinRandomImprove, defaultSelectionConstraints, InputSelector, SelectionResult, SelectionSkeleton } from '@cardano-sdk/cip2';
import { loadCardanoSerializationLib, CSL, CardanoSerializationLib, ProtocolParametersRequiredByWallet } from '@cardano-sdk/core';

const demo = async (protocolParameters: ProtocolParametersRequiredByWallet): Promise<SelectionResult> => {
  const csl: CardanoSerializationLib = await loadCardanoSerializationLib();
  const selector: InputSelector = roundRobinRandomImprove(coinsPerUtxoWord);
  // It is important that you use the same instance of cardano-serialization-lib across your application.
  // Bad: TransactionUnspentOutput.new(...)
  // Good: CSL.TransactionUnspentOutput.new(...)
  const utxo: CSL.TransactionUnspentOutput[] = [CSL.TransactionUnspentOutput.new(...), ...];
  const outputs: CSL.TransactionOutput[] = [CSL.TransactionOutput.new(...), ...];
  // Used to estimate min fee and validate transaction size
  const buildTx = (inputSelection: SelectionSkeleton): Promise<CSL.Transaction> => {...};
  const constraints = defaultSelectionConstraints({
    protocolParameters, buildTx,
  });

  return selector.select({
    utxo,
    outputs,
    constraints,
  });
};

Tests

Input selection is tested with property-based tests using fast-check, as well as a few regular example-based tests.

Due to nature of property-based tests, code coverage report is slightly different on each build.

RoundRobinRandomImprove has 100% code coverage when using high numRuns option (e.g. 100_000).

Note that to run it with high numRuns you need to increase Jest and fast-check timeout.

See code coverage report.

0.5.1-nightly.0

2 years ago

0.5.1-nightly.1

2 years ago

0.5.1-nightly.2

2 years ago

0.5.1-nightly.3

2 years ago

0.5.1-nightly.8

2 years ago

0.5.1-nightly.10

2 years ago

0.5.1-nightly.9

2 years ago

0.5.1-nightly.7

2 years ago

0.5.0-nightly.5

2 years ago

0.6.0-nightly.0

2 years ago

0.5.0-nightly.6

2 years ago

0.5.0-nightly.7

2 years ago

0.5.0

2 years ago

0.5.0-nightly.0

2 years ago

0.5.0-nightly.1

2 years ago

0.5.0-nightly.2

2 years ago

0.5.0-nightly.3

2 years ago

0.5.0-nightly.4

2 years ago

0.3.0

2 years ago

0.4.0

2 years ago

0.2.0

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago