예제 #1
0
 public Transaction MakeTransaction(SignedTransactionBase ethTx)
 {
     return(new Transaction
     {
         // this is special case where empty uint160 is allowed
         To = ethTx.ReceiveAddress?.ToUInt160() ?? UInt160Utils.Empty,
         Value = ethTx.Value.ToUInt256(true),
         From = ethTx.Key.GetPublicAddress().HexToBytes().ToUInt160(),
         Nonce = Convert.ToUInt64(ethTx.Nonce.ToHex(), 16),
         GasPrice = Convert.ToUInt64(ethTx.GasPrice.ToHex(), 16),
         GasLimit = Convert.ToUInt64(ethTx.GasLimit.ToHex(), 16),
         Invocation = ethTx.Data is null ? ByteString.Empty : ByteString.CopyFrom(ethTx.Data),
     });
예제 #2
0
        public IActionResult SignRawTx([FromBody] SignRequest sourceTx)
        {
            if (sourceTx.PrivateKeys.Count != 1)
            {
                BadRequest("One private key expected");
            }

            var unsignedTransaction = sourceTx.TransactionContext;

            RLPSigner rlpEncoder;

            byte[] transactionRawBytes;

            try
            {
                transactionRawBytes = unsignedTransaction.HexToByteArray();
            }
            catch (FormatException)
            {
                return(BadRequest(ErrorResponse.Create($"Unsigned transaction is not a hex string: {unsignedTransaction}")));
            }

            try
            {
                rlpEncoder = SignedTransactionBase.CreateDefaultRLPSigner(transactionRawBytes);
            }
            catch (Exception)
            {
                return(BadRequest(ErrorResponse.Create($"Invalid unsigned transaction format: {unsignedTransaction}")));
            }

            var secret = new EthECKey(sourceTx.PrivateKeys.First());

            rlpEncoder.Sign(secret);

            var signedTx = new Transaction(rlpEncoder);

            return(Ok(new SignResponse
            {
                SignedTransaction = signedTx.GetRLPEncoded().ToHex()
            }));
        }