Ejemplo n.º 1
0
        public static string DoSignVTHOTx(List <string[]> transactions, string privateKey, bool isSend, int?gasLimit)
        {
            byte chainTag = 0;

            byte[] blockRef = null;

            var clauses = new List <ToClause>();

            foreach (var transaction in transactions)
            {
                var amount = Amount.VTHO();
                amount.SetDecimalAmount(transaction[1]);
                clauses.Add(
                    ERC20Contract.BuildTranferToClause(ERC20Token.VTHO, Address.FromHexString(transaction[0]), amount));
                chainTag = ByteUtils.ToByteArray(transaction[2])[0];
                blockRef = transaction[3] == null?BlockchainClient.GetBlockRef(null).ToByteArray() : ByteUtils.ToByteArray(transaction[3]);
            }
            int gas            = clauses.Count * gasLimit ?? 80000;
            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));
            }
        }