import AbiFunction from '../smartcontract/abi/abiFunction' ; import { serializeAbiFunction } from '../transaction/scriptBuilder' ; import { num2hexstring , randomBytes } from '../utils' ; import { Address } from './../crypto/address' ; import { TransactionAttribute , TransactionAttributeUsage } from './../transaction/txAttribute' ; import { InvocationTransaction } from './InvocationTransaction' ; export class SmartContract { static makeInvokeTransaction ( contractAddr , addr , abiFunction ) { let params = serializeAbiFunction ( abiFunction ) ; params += num2hexstring ( 0x67 ) ; params += contractAddr . serialize ( ) ; const tx = this . makeInvocationTransaction ( params , addr ) ; return tx ; } static makeInvocationTransaction ( params , addr ) { const tx = new InvocationTransaction ( ) ; tx . version = 1 ; tx . attributes = [ ] ; const attr1 = new TransactionAttribute ( ) ; attr1 . usage = TransactionAttributeUsage . Script ; attr1 . data = addr . serialize ( ) ; tx . attributes [ 0 ] = attr1 ; const attr2 = new TransactionAttribute ( ) ; attr2 . usage = TransactionAttributeUsage . DescriptionUrl ; attr2 . data = randomBytes ( 16 ) ; tx . attributes [ 1 ] = attr2 ; tx . inputs = [ ] ; tx . outputs = [ ] ; tx . script = params ; tx . gas = 0 ; return tx ; } }