stacks-archive / stacks-transactions-js

The JavaScript library for generating Stacks 2.0 transactions
19 stars 17 forks source link

Support strings for contract principals and asset info IDs #61

Closed zone117x closed 4 years ago

zone117x commented 4 years ago

Description

Improves the DX for creating a post-conditions. Previously, several functions had to be discovered (e.g. makeStandardNonFungiblePostCondition, makeContractNonFungiblePostCondition, createNonFungiblePostCondition, createAssetInfo).

And the resulting code pretty verbose:

  const postCondition = createNonFungiblePostCondition(
    createContractPrincipal(
      'SP2JXKMSH007NPYAQHKJPQMAQYAD90NQGTVJVQ02B', 
      'contract-name'),
    NonFungibleConditionCode.Owns,
    createAssetInfo('SP2ZP4GJDZJ1FDHTQ963F0292PE9J9752TZJ68F21', 
      'contract_name', 
      'asset_name'),
    bufferCVFromString('nft_asset_name')
  );

// Note: more verbose when the inputs are strings that need to be split
// (e.g. `SP2JXKMSH007NPYAQHKJPQMAQYAD90NQGTVJVQ02B.contract-name`)

These post conditions can now be constructed without distinguishing between principal types or requiring construction of the AssetInfo object:

  const postCondition = createNonFungiblePostCondition(
    'SP2JXKMSH007NPYAQHKJPQMAQYAD90NQGTVJVQ02B.contract-name',
    NonFungibleConditionCode.Owns,
    'SP2ZP4GJDZJ1FDHTQ963F0292PE9J9752TZJ68F21.contract_name::asset_name',
    bufferCVFromString('nft_asset_name')
  );

Type of Change

Does this introduce a breaking change?

Backwards compatible

Are documentation updates required?

Testing information

Checklist