import { H160 , H256 } from "codechain-primitives" ; import { blake256 } from "../../utils" ; import { Asset } from "../Asset" ; import { AssetTransaction , Transaction } from "../Transaction" ; import { NetworkId } from "../types" ; import { AssetMintOutput , AssetMintOutputJSON } from "./AssetMintOutput" ; const RLP = require ( "rlp" ) ; export interface IncreaseAssetSupplyTransactionJSON { networkId : string ; shardId : number ; assetType : string ; seq : number ; output : AssetMintOutputJSON ; } export interface IncreaseAssetSupplyActionJSON extends IncreaseAssetSupplyTransactionJSON { approvals : string [ ] ; } export class IncreaseAssetSupply extends Transaction implements AssetTransaction { private readonly transaction : IncreaseAssetSupplyTransaction ; private readonly approvals : string [ ] ; constructor ( params ) { super ( params . networkId ) ; this . transaction = new IncreaseAssetSupplyTransaction ( params ) ; this . approvals = params . approvals ; } public tracker ( ) { return new H256 ( blake256 ( this . transaction . rlpBytes ( ) ) ) ; } param approval public addApproval ( approval ) { this . approvals . push ( approval ) ; } public output ( ) { return this . transaction . output ; } returns public getMintedAsset ( ) { const { assetType , shardId , output } = this . transaction ; const { lockScriptHash , parameters , supply } = output ; return new Asset ( { assetType , shardId , lockScriptHash , parameters , quantity : supply , tracker : this . tracker ( ) , transactionOutputIndex : 0 } ) ; } public type ( ) { return "increaseAssetSupply" ; } protected actionToEncodeObject ( ) { const encoded = this . transaction . toEncodeObject ( ) ; encoded . push ( this . approvals ) ; return encoded ; } protected actionToJSON ( ) { const json = this . transaction . toJSON ( ) ; return { ... json , approvals : this . approvals } ; } } class IncreaseAssetSupplyTransaction { public readonly shardId : number ; public readonly assetType : H160 ; public readonly seq : number ; public readonly output : AssetMintOutput ; private readonly networkId : NetworkId ; constructor ( params ) { this . networkId = params . networkId ; this . shardId = params . shardId ; this . seq = params . seq ; this . assetType = params . assetType ; this . output = new AssetMintOutput ( params . output ) ; } public toJSON ( ) { return { networkId : this . networkId , shardId : this . shardId , assetType : this . assetType . toEncodeObject ( ) , seq : this . seq , output : this . output . toJSON ( ) } ; } public toEncodeObject ( ) { return [ 0x18 , this . networkId , this . shardId , this . assetType . toEncodeObject ( ) , this . seq , this . output . lockScriptHash . toEncodeObject ( ) , this . output . parameters . map ( parameter => Buffer . from ( parameter ) ) , this . output . supply . toEncodeObject ( ) ] ; } public rlpBytes ( ) { return RLP . encode ( this . toEncodeObject ( ) ) ; } }