encodeTransactionProto function

Uint8List encodeTransactionProto(
  1. Map<String, dynamic> tx
)

Implementation

Uint8List encodeTransactionProto(Map<String, dynamic> tx) {
  var txnBuffer = zMessage.ProtoTransactionCoreInfo.create();
  txnBuffer.version = tx['version'];
  txnBuffer.nonce = tx['nonce'] is int ? Int64(tx['nonce']) : Int64(0);
  txnBuffer.toaddr =
      numbers.hexToBytes(tx['toAddr'].replaceAll('0x', '').toLowerCase());
  txnBuffer.senderpubkey = zMessage.ByteArray.create();
  txnBuffer.senderpubkey.data =
      numbers.hexToBytes(tx['pubKey'] is String ? tx['pubKey'] : '00');

  txnBuffer.amount = zMessage.ByteArray.create();
  txnBuffer.amount.data = numbers.intToBytes(tx['amount'], length: 16);
  txnBuffer.gasprice = zMessage.ByteArray.create();
  txnBuffer.gasprice.data = numbers.intToBytes(tx['gasPrice'], length: 16);
  txnBuffer.gaslimit = tx['gasLimit'] is int ? Int64(tx['gasLimit']) : Int64(0);

  if (null != tx['code'] &&
      tx['code'] is String &&
      tx['code'].toString().isNotEmpty) {
    txnBuffer.code = toArray(tx['code']);
  }
  if (null != tx['data'] &&
      tx['data'] is String &&
      tx['data'].toString().isNotEmpty) {
    txnBuffer.data = toArray(tx['data']);
  }
  return txnBuffer.writeToBuffer();
}