Example #1
0
        public static string DoSignVETTx(List <string[]> transactions, string privateKey, bool isSend)
        {
            byte chainTag = 0;

            byte[] blockRef = null;

            var clauses = new List <ToClause>();

            foreach (var transaction in transactions)
            {
                var amount = Amount.CreateFromToken(AbstractToken.VET);
                amount.SetDecimalAmount(transaction[1]);
                clauses.Add(TransactionClient.BuildVETToClause(Address.FromHexString(transaction[0]), amount, ToData.ZERO));
                chainTag = ByteUtils.ToByteArray(transaction[2])[0];
                if (transaction[3] == null)
                {
                    blockRef = BlockchainClient.GetBlockRef(null).ToByteArray();
                }
                else
                {
                    blockRef = ByteUtils.ToByteArray(transaction[3]);
                }
            }
            int gas            = clauses.Count * 21000;
            var rawTransaction = RawTransactionFactory.Instance.CreateRawTransaction(chainTag, blockRef,
                                                                                     720, gas, (byte)0x0, CryptoUtils.GenerateTxNonce(), clauses.ToArray());

            if (isSend)
            {
                var result = TransactionClient.SignThenTransfer(rawTransaction, ECKeyPair.Create(privateKey));
                return(JsonConvert.SerializeObject(result));
            }
            else
            {
                var result = TransactionClient.Sign(rawTransaction, ECKeyPair.Create(privateKey));
                return(ByteUtils.ToHexString(result.Encode(), Prefix.ZeroLowerX));
            }
        }