예제 #1
0
        public UInt256 ReadDepositBalance(Address onBehalfOf, Keccak depositId)
        {
            var         txData      = _abiEncoder.Encode(AbiEncodingStyle.IncludeSignature, ContractData.DepositBalanceAbiSig, depositId.Bytes);
            Transaction transaction = new Transaction();

            transaction.Value         = 0;
            transaction.Data          = txData;
            transaction.To            = _contractAddress;
            transaction.SenderAddress = onBehalfOf;
            transaction.GasLimit      = 100000;
            transaction.GasPrice      = 0.GWei();
            transaction.Nonce         = (UInt256)_blockchainBridge.GetNonce(onBehalfOf);
            _wallet.Sign(transaction, _blockchainBridge.GetNetworkId());
            BlockchainBridge.CallOutput callOutput = _blockchainBridge.Call(_blockchainBridge.Head, transaction);
            return((callOutput.OutputData ?? new byte[] { 0 }).ToUInt256());
        }
예제 #2
0
        public async Task get_nonce_should_invoke_blockchain_bridge_get_nonce()
        {
            UInt256 nonce   = 1;
            var     address = TestItem.AddressA;

            _blockchainBridge.GetNonce(address).Returns(nonce);
            var result = await _ndmBridge.GetNonceAsync(address);

            _blockchainBridge.Received().GetNonce(address);
            result.Should().Be(nonce);
        }
예제 #3
0
        public ResultWrapper <Keccak> eth_sendTransaction(TransactionForRpc transactionForRpc)
        {
            try
            {
                _readerWriterLockSlim.EnterWriteLock();
                Transaction tx = transactionForRpc.ToTransaction();
                if (tx.Signature == null)
                {
                    tx.Nonce = (UInt256)_blockchainBridge.GetNonce(tx.SenderAddress);
                    _blockchainBridge.Sign(tx);
                }

                Keccak txHash = _blockchainBridge.SendTransaction(tx);
                return(ResultWrapper <Keccak> .Success(txHash));
            }
            finally
            {
                _readerWriterLockSlim.ExitWriteLock();
            }
        }
예제 #4
0
        public Keccak ClaimRefund(Address onBehalfOf, RefundClaim refundClaim)
        {
            byte[]      txData      = _abiEncoder.Encode(AbiEncodingStyle.IncludeSignature, ContractData.ClaimRefundSig, refundClaim.HeaderId.Bytes, refundClaim.Units, refundClaim.Value, refundClaim.ExpiryTime, refundClaim.Pepper, refundClaim.Provider, onBehalfOf);
            Transaction transaction = new Transaction();

            transaction.Value         = 0;
            transaction.Data          = txData;
            transaction.To            = new Address(_ndmConfig.ContractAddress);
            transaction.SenderAddress = onBehalfOf;
            transaction.GasLimit      = 90000; // check
            transaction.GasPrice      = 20.GWei();
            transaction.Nonce         = (UInt256)_blockchainBridge.GetNonce(onBehalfOf);
            _wallet.Sign(transaction, _blockchainBridge.GetNetworkId());

            if (_logger.IsInfo)
            {
                _logger.Info($"Sending a refund claim transaction for {refundClaim.DepositId} to be refunded to {refundClaim.RefundTo}");
            }

            return(_blockchainBridge.SendTransaction(transaction));
        }
예제 #5
0
        public ResultWrapper <Keccak> eth_sendTransaction(TransactionForRpc transactionForRpc)
        {
            Transaction tx = transactionForRpc.ToTransaction();

            if (tx.Signature == null)
            {
                tx.Nonce = _blockchainBridge.GetNonce(tx.SenderAddress);
                _blockchainBridge.Sign(tx);
            }

            Keccak txHash = _blockchainBridge.SendTransaction(tx, true);

            return(ResultWrapper <Keccak> .Success(txHash));
        }
예제 #6
0
        private ResultWrapper <Quantity> GetAccountNonce(Address address, BlockParameter blockParameter)
        {
            if (blockParameter.Type == BlockParameterType.Pending)
            {
                var nonce = _blockchainBridge.GetNonce(address);
                return(ResultWrapper <Quantity> .Success(new Quantity(nonce)));
            }

            var block = GetBlock(blockParameter);

            if (block.Result.ResultType == ResultType.Failure)
            {
                return(ResultWrapper <Quantity> .Fail(block.Result.Error));
            }
            return(GetAccountNonce(address, block.Data.Header.StateRoot));
        }
예제 #7
0
 public Task <UInt256> GetNonceAsync(Address address) => Task.FromResult(_blockchainBridge.GetNonce(address));