import { H160 , H256 } from "codechain-primitives" ; import { blake256 } from "../../utils" ; import { PlatformAddress } from "../classes" ; import { Transaction } from "../Transaction" ; import { NetworkId } from "../types" ; const RLP = require ( "rlp" ) ; export interface AssetSchemeChangeTransactionJSON { networkId : string ; shardId : number ; assetType : string ; seq : number ; metadata : string ; approver : string | null ; registrar : string | null ; allowedScriptHashes : string [ ] ; } export interface ChangeAssetSchemeActionJSON extends AssetSchemeChangeTransactionJSON { approvals : string [ ] ; } export class ChangeAssetScheme extends Transaction { private readonly _transaction : AssetSchemeChangeTransaction ; private readonly approvals : string [ ] ; public constructor ( input ) { super ( input . networkId ) ; this . _transaction = new AssetSchemeChangeTransaction ( input ) ; this . approvals = input . approvals ; } returns public tracker ( ) { return new H256 ( blake256 ( this . _transaction . rlpBytes ( ) ) ) ; } param approval public addApproval ( approval ) { this . approvals . push ( approval ) ; } public type ( ) { return "changeAssetScheme" ; } 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 } ; } } /**
 * Change asset scheme
 */ class AssetSchemeChangeTransaction { public readonly networkId : NetworkId ; public readonly shardId : number ; public readonly assetType : H160 ; public readonly seq : number ; public readonly metadata : string ; public readonly approver : PlatformAddress | null ; public readonly registrar : PlatformAddress | null ; public readonly allowedScriptHashes : H160 [ ] ; param params . networkId param params . shardId param params . assetType param params . metadata param params . approver param params . registrar param params . allowedScriptHashes constructor ( params ) { const { networkId , shardId , assetType , seq , metadata , approver , registrar , allowedScriptHashes } = params ; this . networkId = networkId ; this . shardId = shardId ; this . assetType = assetType ; this . seq = seq ; this . metadata = typeof metadata === "string" ? metadata : JSON . stringify ( metadata ) ; this . approver = approver == null ? null : PlatformAddress . ensure ( approver ) ; this . registrar = registrar == null ? null : PlatformAddress . ensure ( registrar ) ; this . allowedScriptHashes = allowedScriptHashes ; } returns public toJSON ( ) { return { networkId : this . networkId , shardId : this . shardId , assetType : this . assetType . toEncodeObject ( ) , seq : this . seq , metadata : this . metadata , approver : this . approver == null ? null : this . approver . toString ( ) , registrar : this . registrar == null ? null : this . registrar . toString ( ) , allowedScriptHashes : this . allowedScriptHashes . map ( hash => hash . toJSON ( ) ) } ; } /**
     * Convert to an object for RLP encoding.
     */ public toEncodeObject ( ) { const { networkId , shardId , assetType , seq , metadata , approver , registrar , allowedScriptHashes } = this ; return [ 0x15 , networkId , shardId , assetType . toEncodeObject ( ) , seq , metadata , approver ? [ approver . getAccountId ( ) . toEncodeObject ( ) ] : [ ] , registrar ? [ registrar . getAccountId ( ) . toEncodeObject ( ) ] : [ ] , allowedScriptHashes . map ( hash => hash . toEncodeObject ( ) ) ] ; } /**
     * Convert to RLP bytes.
     */ public rlpBytes ( ) { return RLP . encode ( this . toEncodeObject ( ) ) ; } }