コード例 #1
0
        /// <summary>
        /// Creates middleware that adds a nonce to transactions for given public key.
        /// </summary>
        /// <param name="publicKey">Public key for which the nonce should be set.</param>
        /// <param name="client">Client that should be used to retrieve the nonce.</param>
        public NonceTxMiddleware(byte[] publicKey, DAppChainClient client)
        {
            this.PublicKey = publicKey;
            this.Client    = client;

            this.publicKeyHex = CryptoUtils.BytesToHexString(this.PublicKey);
        }
コード例 #2
0
        private async Task <TReturn> StaticCallAsync <TReturn>(string callInput, FunctionBuilderBase functionBuilder, Func <FunctionBuilderBase, string, TReturn> decodeFunc)
        {
            var result = await this.StaticCallAsyncByteArray(callInput);

            var validResult = result != null && result.Length != 0;

            return(validResult ? decodeFunc(functionBuilder, CryptoUtils.BytesToHexString(result)) : default(TReturn));
        }
コード例 #3
0
        private async Task <TReturn> CallAsync <TReturn>(string callInput, FunctionBuilderBase functionBuilder, Func <FunctionBuilderBase, string, TReturn> decodeFunc)
        {
            var result = await CallAsyncBroadcastTxResult(callInput);

            var validResult = result?.DeliverTx.Data != null && result.DeliverTx.Data.Length != 0;

            return(validResult ? decodeFunc(functionBuilder, CryptoUtils.BytesToHexString(result.DeliverTx.Data)) : default(TReturn));
        }
コード例 #4
0
        private async Task <TReturn> CallAsync <TReturn>(string callInput, FunctionBuilderBase functionBuilder, Func <FunctionBuilderBase, string, TReturn> decodeFunc)
        {
            var tx     = this.CreateContractMethodCallTx(callInput, Protobuf.VMType.Evm);
            var result = await this.Client.CommitTxAsync(tx);

            var validResult = result?.DeliverTx.Data != null && result.DeliverTx.Data.Length != 0;

            return(validResult ? decodeFunc(functionBuilder, CryptoUtils.BytesToHexString(result.DeliverTx.Data)) : default(TReturn));
        }
コード例 #5
0
        private static string AddressStringFromPublicKey(byte[] publicKey)
        {
            if (publicKey == null)
            {
                throw new ArgumentNullException(nameof(publicKey));
            }

            if (publicKey.Length != 32)
            {
                throw new ArgumentException("Expected a 32-byte array", nameof(publicKey));
            }

            return(CryptoUtils.BytesToHexString(CryptoUtils.LocalAddressFromPublicKey(publicKey)));
        }
コード例 #6
0
 private static FilterLog ConvertEthFilterLogToFilterLog(EthFilterLog log)
 {
     return(new FilterLog
     {
         Address = Address.FromBytes(log.Address.ToByteArray()).LocalAddress,
         Data = CryptoUtils.BytesToHexString(log.Data.ToByteArray()),
         Removed = log.Removed,
         Topics = log.Topics.Select(t => (object)t.ToStringUtf8()).ToArray(),
         Type = "",
         BlockHash = CryptoBytes.ToHexStringLower(log.BlockHash.ToByteArray()),
         BlockNumber = new HexBigInteger(log.BlockNumber),
         LogIndex = new HexBigInteger(log.LogIndex),
         TransactionHash = CryptoBytes.ToHexStringLower(log.TransactionHash.ToByteArray()),
         TransactionIndex = new HexBigInteger(log.TransactionIndex)
     });
 }
コード例 #7
0
        /// <summary>
        /// Creates an Address instance from a byte array.
        /// </summary>
        /// <param name="address">binary 20-byte array representation of the address</param>
        /// <param name="chainId">Identifier of a DAppChain.</param>
        /// <returns>An address</returns>
        public static Address FromBytes(byte[] address, string chainId = DefaultChainId)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            if (address.Length != AddressLengthBytes)
            {
                throw new ArgumentException("Local address must have a length of 20 bytes", nameof(address));
            }

            return(new Address(
                       CryptoUtils.BytesToHexString(address),
                       chainId
                       ));
        }
コード例 #8
0
ファイル: Address.cs プロジェクト: gofindxr/unity-sdk
        /// <summary>
        /// Creates an Address instance from a Protobuf representation of an address.
        /// </summary>
        /// <param name="protobufAddress"><see cref="Protobuf.Address"/> instance.</param>
        /// <returns>An address</returns>
        public static Address FromProtobufAddress(Protobuf.Address protobufAddress)
        {
            if (protobufAddress == null)
            {
                throw new ArgumentNullException(nameof(protobufAddress));
            }

            if (protobufAddress.Local == null)
            {
                throw new ArgumentNullException(nameof(protobufAddress.Local));
            }

            if (protobufAddress.Local.Length != AddressLengthBytes)
            {
                throw new ArgumentException("Local address must have a length of 20 bytes", nameof(protobufAddress.Local));
            }

            return(new Address(
                       CryptoUtils.BytesToHexString(protobufAddress.Local.ToByteArray()),
                       String.IsNullOrWhiteSpace(protobufAddress.ChainId) ? DefaultChainId : protobufAddress.ChainId
                       ));
        }
コード例 #9
0
        /// <summary>
        /// Decodes event data into event DTO.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns>Decoded event DTO.</returns>
        /// <see href="https://nethereum.readthedocs.io/en/latest/contracts/calling-transactions-events/"/>
        public T DecodeEventDto <T>() where T : new()
        {
            EventTopicDecoder eventTopicDecoder = new EventTopicDecoder();

            return(eventTopicDecoder.DecodeTopics <T>(this.Topics, CryptoUtils.BytesToHexString(this.Data)));
        }