import { Buffer } from "buffer" ; import { AssetAddress , H160 , U64 } from "codechain-primitives" ; import { P2PKH } from "../../key/P2PKH" ; import { P2PKHBurn } from "../../key/P2PKHBurn" ; export interface AssetMintOutputJSON { lockScriptHash : string ; parameters : string [ ] ; supply : string ; } export class AssetMintOutput { param data returns public static fromJSON ( data ) { const { lockScriptHash , parameters , supply } = data ; return new this ( { lockScriptHash : H160 . ensure ( lockScriptHash ) , parameters : parameters . map ( p => Buffer . from ( p , "hex" ) ) , supply : U64 . ensure ( supply ) } ) ; } public readonly lockScriptHash : H160 ; public readonly parameters : Buffer [ ] ; public readonly supply : U64 ; param data . lockScriptHash param data . parameters param data . supply constructor ( data ) { if ( "recipient" in data ) { const { type , payload } = data . recipient ; if ( "pubkeys" in payload ) { throw Error ( `Multisig payload is not supported yet` ) ; } switch ( type ) { case 0x00 : this . lockScriptHash = payload ; this . parameters = [ ] ; break ; case 0x01 : this . lockScriptHash = P2PKH . getLockScriptHash ( ) ; this . parameters = [ Buffer . from ( payload . value , "hex" ) ] ; break ; case 0x02 : this . lockScriptHash = P2PKHBurn . getLockScriptHash ( ) ; this . parameters = [ Buffer . from ( payload . value , "hex" ) ] ; break ; default : throw Error ( `Unexpected type of AssetAddress: ${ type }, ${ data . recipient }` ) ; } } else { const { lockScriptHash , parameters } = data ; this . lockScriptHash = lockScriptHash ; this . parameters = parameters ; } this . supply = data . supply ; } returns public toJSON ( ) { return { lockScriptHash : this . lockScriptHash . toJSON ( ) , parameters : this . parameters . map ( ( p ) => p . toString ( "hex" ) ) , supply : this . supply . toJSON ( ) } ; } }