import { ERROR_CODE } from '../error' ; import { hex2VarBytes , num2hexstring , StringReader } from '../utils' ; export enum TransactionAttributeUsage { Nonce = 0x00 , Script = 0x20 , DescriptionUrl = 0x81 , Description = 0x90 } deprecated property property export class TransactionAttribute { usage : TransactionAttributeUsage ; data : string ; serialize ( ) { let result = '' ; result += num2hexstring ( this . usage ) ; if ( this . usage === TransactionAttributeUsage . Script ) { result += this . data ; } else if ( this . usage === TransactionAttributeUsage . DescriptionUrl || this . usage === TransactionAttributeUsage . Description || this . usage === TransactionAttributeUsage . Nonce ) { result += hex2VarBytes ( this . data ) ; } else { throw ERROR_CODE . INVALID_PARAMS ; } return result ; } deserialize ( ss ) { const usage = parseInt ( ss . read ( 1 ) , 16 ) ; const dataLen = ss . readNextLen ( ) ; const data = ss . read ( dataLen ) ; this . usage = usage ; this . data = data ; } }