コード例 #1
0
ファイル: Block.cs プロジェクト: aboussetta/nethermind
 public object ToJson()
 {
     return(new
     {
         number = Number?.ToJson(),
         hash = Hash?.ToJson(),
         parentHash = ParentHash?.ToJson(),
         nonce = Nonce?.ToJson(),
         MixHash = MixHash?.ToJson(),
         sha3Uncles = Sha3Uncles?.ToJson(),
         logsBloom = LogsBloom?.ToJson(),
         transactionsRoot = TransactionsRoot?.ToJson(),
         stateRoot = StateRoot?.ToJson(),
         receiptsRoot = ReceiptsRoot?.ToJson(),
         miner = Miner?.ToJson(),
         difficulty = Difficulty?.ToJson(),
         totalDifficulty = TotalDifficulty?.ToJson(),
         extraData = ExtraData?.ToJson(),
         size = Size?.ToJson(),
         gasLimit = GasLimit?.ToJson(),
         gasUsed = GasUsed?.ToJson(),
         timestamp = Timestamp?.ToJson(),
         transactions = Transactions?.Select(x => x.ToJson()).ToArray() ?? TransactionHashes?.Select(x => x.ToJson()).ToArray(),
         uncles = Uncles?.Select(x => x.ToJson()).ToArray()
     });
 }
コード例 #2
0
        /// <inheritdoc />
        public async Task <IEventLock?> LockEventForProcessingAsync(EthereumNetwork network,
                                                                    ContractAddress contractAddresses,
                                                                    EventSignature eventSignature,
                                                                    TransactionHash transactionHash,
                                                                    int eventIndex,
                                                                    BlockNumber blockNumber,
                                                                    GasLimit gasUsed,
                                                                    GasPrice gasPrice,
                                                                    EventRetrievalStrategy retrievalStrategy)
        {
            var param = new
            {
                Network         = network.Name,
                ContractAddress = contractAddresses,
                EventSignature  = eventSignature,
                TransactionHash = transactionHash,
                EventIndex      = eventIndex,
                MachineName     = this._machineName,
                BlockNumber     = (int)blockNumber.Value,
                GasUsed         = gasUsed,
                GasPrice        = gasPrice,
                Strategy        = retrievalStrategy.GetName()
            };

            return(await this._database.QuerySingleOrDefaultAsync <object, EventLockEntity>(storedProcedure : @"Ethereum.Event_Lock", param : param));
        }
コード例 #3
0
ファイル: Transaction.cs プロジェクト: Heasn/neb.net
        public override int GetHashCode()
        {
            int hash = 1;

            if (Hash.Length != 0)
            {
                hash ^= Hash.GetHashCode();
            }
            if (From.Length != 0)
            {
                hash ^= From.GetHashCode();
            }
            if (To.Length != 0)
            {
                hash ^= To.GetHashCode();
            }
            if (Value.Length != 0)
            {
                hash ^= Value.GetHashCode();
            }
            if (Nonce != 0UL)
            {
                hash ^= Nonce.GetHashCode();
            }
            if (Timestamp != 0L)
            {
                hash ^= Timestamp.GetHashCode();
            }
            if (data_ != null)
            {
                hash ^= Data.GetHashCode();
            }
            if (ChainId != 0)
            {
                hash ^= ChainId.GetHashCode();
            }
            if (GasPrice.Length != 0)
            {
                hash ^= GasPrice.GetHashCode();
            }
            if (GasLimit.Length != 0)
            {
                hash ^= GasLimit.GetHashCode();
            }
            if (Alg != 0)
            {
                hash ^= Alg.GetHashCode();
            }
            if (Sign.Length != 0)
            {
                hash ^= Sign.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
コード例 #4
0
        public string ToJsonHex()
        {
            var s = "['{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}']";

            return(string.Format(s, Nonce.ToHex(),
                                 GasPrice.ToHex(), GasLimit.ToHex(), ReceiveAddress.ToHex(), Value.ToHex(), ToHex(Data),
                                 Signature.V.ToHex(),
                                 Signature.R.ToHex(),
                                 Signature.S.ToHex()));
        }
コード例 #5
0
        public string ToJsonHex()
        {
            var data =
                $"['{Nonce.ToHex()}','{GasPrice.ToHex()}','{GasLimit.ToHex()}','{ReceiveAddress.ToHex()}','{Value.ToHex()}','{ToHex(Data)}','{ChainId.ToHex()}','{RHash.ToHex()}','{SHash.ToHex()}'";

            if (Signature != null)
            {
                data = data + $", '{Signature.V.ToHex()}', '{Signature.R.ToHex()}', '{Signature.S.ToHex()}'";
            }
            return(data + "]");
        }
コード例 #6
0
        public string ToJsonHex()
        {
            var data =
                "['" + Nonce.ToHex() + "','" + GasPrice.ToHex() + "','" + GasLimit.ToHex() + "','" + ReceiveAddress.ToHex() + "','" + Value.ToHex() + "','" + ToHex(Data) + "','" + ChainId.ToHex() + "','" + RHash.ToHex() + "','" + SHash.ToHex() + "'";

            if (Signature != null)
            {
                data = data + ", '" + Signature.V.ToHex() + "', '" + Signature.R.ToHex() + "', '" + Signature.S.ToHex() + "'";
            }
            return(data + "]");
        }
コード例 #7
0
        public async Task <bool> SignAsync(
            IKeyStorage keyStorage,
            WalletAddress address,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var xtz = (Atomix.Tezos)Currency;

            if (address.KeyIndex == null)
            {
                Log.Error("Can't find private key for address {@address}", address);
                return(false);
            }

            var privateKey = keyStorage
                             .GetPrivateKey(Currency, address.KeyIndex);

            if (privateKey == null)
            {
                Log.Error("Can't find private key for address {@address}", address);
                return(false);
            }

            var publicKey = keyStorage
                            .GetPublicKey(Currency, address.KeyIndex);

            var rpc = new Rpc(xtz.RpcProvider);

            Head = await rpc
                   .GetHeader()
                   .ConfigureAwait(false);

            var managerKey = await rpc
                             .GetManagerKey(From)
                             .ConfigureAwait(false);

            Operations = new JArray();

            var gas     = GasLimit.ToString(CultureInfo.InvariantCulture);
            var storage = StorageLimit.ToString(CultureInfo.InvariantCulture);

            if (managerKey["key"] == null)
            {
                var revealOpCounter = await TezosCounter.Instance
                                      .GetCounter(xtz, From, Head)
                                      .ConfigureAwait(false);

                var revealOp = new JObject
                {
                    ["kind"]          = OperationType.Reveal,
                    ["fee"]           = "0",
                    ["public_key"]    = Base58Check.Encode(publicKey, Prefix.Edpk),
                    ["source"]        = From,
                    ["storage_limit"] = storage,
                    ["gas_limit"]     = gas,
                    ["counter"]       = revealOpCounter.ToString()
                };

                Operations.AddFirst(revealOp);
            }

            var counter = await TezosCounter.Instance
                          .GetCounter(xtz, From, Head)
                          .ConfigureAwait(false);

            var transaction = new JObject
            {
                ["kind"]          = OperationType.Transaction,
                ["source"]        = From,
                ["fee"]           = Fee.ToString(CultureInfo.InvariantCulture),
                ["counter"]       = counter.ToString(),
                ["gas_limit"]     = gas,
                ["storage_limit"] = storage,
                ["amount"]        = Math.Round(Amount, 0).ToString(CultureInfo.InvariantCulture),
                ["destination"]   = To
            };

            Operations.Add(transaction);

            if (Params != null)
            {
                transaction["parameters"] = Params;
            }
            else
            {
                var parameters = new JObject
                {
                    ["prim"] = "Unit",
                    ["args"] = new JArray()
                };

                transaction["parameters"] = parameters;
            }

            var forgedOpGroup = await rpc
                                .ForgeOperations(Head, Operations)
                                .ConfigureAwait(false);

            SignedMessage = TezosSigner.SignHash(
                data: Hex.FromString(forgedOpGroup.ToString()),
                privateKey: privateKey,
                watermark: Watermark.Generic,
                isExtendedKey: privateKey.Length == 64);

            return(true);
        }
コード例 #8
0
        public async Task <(bool result, bool isRunSuccess, bool hasReveal)> FillOperationsAsync(
            SecureBytes securePublicKey,
            TezosConfig tezosConfig,
            int headOffset         = 0,
            bool isAlreadyRevealed = false,
            CancellationToken cancellationToken = default)
        {
            using var publicKey = securePublicKey.ToUnsecuredBytes();

            var rpc = new Rpc(tezosConfig.RpcNodeUri);

            var managerKey = await rpc
                             .GetManagerKey(From)
                             .ConfigureAwait(false);

            var actualHead = await rpc
                             .GetHeader()
                             .ConfigureAwait(false);

            if (Head == null)
            {
                Head = await rpc
                       .GetHeader(headOffset)
                       .ConfigureAwait(false);
            }

            Operations = new JArray();

            var gas      = GasLimit.ToString(CultureInfo.InvariantCulture);
            var storage  = StorageLimit.ToString(CultureInfo.InvariantCulture);
            var revealed = managerKey.Value <string>() != null || isAlreadyRevealed;

            UsedCounters = revealed ? 1 : 2;

            var counter = UseOfflineCounter
                ? await TezosCounter.Instance
                          .GetOfflineCounterAsync(
                address : From,
                head : actualHead["hash"].ToString(),
                rpcNodeUri : tezosConfig.RpcNodeUri,
                numberOfCounters : UsedCounters)
                          .ConfigureAwait(false)
                : await TezosCounter.Instance
                          .GetCounterAsync(
                address : From,
                head : actualHead["hash"].ToString(),
                rpcNodeUri : tezosConfig.RpcNodeUri)
                          .ConfigureAwait(false);

            if (!revealed)
            {
                var revealOp = new JObject
                {
                    ["kind"]          = Internal.OperationType.Reveal,
                    ["fee"]           = "0",
                    ["public_key"]    = Base58Check.Encode(publicKey, Prefix.Edpk),
                    ["source"]        = From,
                    ["storage_limit"] = "0",
                    ["gas_limit"]     = tezosConfig.RevealGasLimit.ToString(),
                    ["counter"]       = counter.ToString()
                };

                Operations.AddFirst(revealOp);

                counter++;
            }

            var operation = new JObject
            {
                ["kind"]          = OperationType,
                ["source"]        = From,
                ["fee"]           = ((int)Fee).ToString(CultureInfo.InvariantCulture),
                ["counter"]       = counter.ToString(),
                ["gas_limit"]     = gas,
                ["storage_limit"] = storage,
            };

            if (OperationType == Internal.OperationType.Transaction)
            {
                operation["amount"]      = Math.Round(Amount, 0).ToString(CultureInfo.InvariantCulture);
                operation["destination"] = To;
            }
            else if (OperationType == Internal.OperationType.Delegation)
            {
                operation["delegate"] = To;
            }
            else
            {
                throw new NotSupportedException($"Operation type {OperationType} not supporeted yet.");
            }

            Operations.Add(operation);

            if (Params != null)
            {
                operation["parameters"] = Params;
            }

            var isRunSuccess = false;

            if (UseRun)
            {
                var fill = await rpc
                           .AutoFillOperations(tezosConfig, Head, Operations, UseSafeStorageLimit)
                           .ConfigureAwait(false);

                if (!fill)
                {
                    Log.Warning("Operation autofilling error");
                }
                else
                {
                    Fee          = Operations.Last["fee"].Value <decimal>().ToTez();
                    isRunSuccess = true;
                }
            }

            return(
                result : true,
                isRunSuccess : isRunSuccess,
                hasReveal : !revealed
                );
        }
コード例 #9
0
        public async Task <bool> AutoFillAsync(
            IKeyStorage keyStorage,
            WalletAddress address,
            bool useDefaultFee)
        {
            var xtz = (Atomex.Tezos)Currency;

            if (address.KeyIndex == null)
            {
                Log.Error("Can't find private key for address {@address}", address);
                return(false);
            }

            using var securePrivateKey = keyStorage
                                         .GetPrivateKey(Currency, address.KeyIndex);

            if (securePrivateKey == null)
            {
                Log.Error("Can't find private key for address {@address}", address);
                return(false);
            }

            using var privateKey = securePrivateKey.ToUnsecuredBytes();

            using var securePublicKey = keyStorage
                                        .GetPublicKey(Currency, address.KeyIndex);

            using var publicKey = securePublicKey.ToUnsecuredBytes();

            var rpc = new Rpc(xtz.RpcNodeUri);

            Head = await rpc
                   .GetHeader()
                   .ConfigureAwait(false);

            var managerKey = await rpc
                             .GetManagerKey(From)
                             .ConfigureAwait(false);

            Operations = new JArray();

            var gas     = GasLimit.ToString(CultureInfo.InvariantCulture);
            var storage = StorageLimit.ToString(CultureInfo.InvariantCulture);

            var counter = await TezosCounter.Instance
                          .GetCounter(xtz, From, Head, ignoreCache : true)
                          .ConfigureAwait(false);

            if (managerKey.Value <string>() == null)
            {
                //var revealOpCounter = await TezosCounter.Instance
                //    .GetCounter(xtz, From, Head, ignoreCache: true)
                //    .ConfigureAwait(false);

                var revealOp = new JObject
                {
                    ["kind"]          = OperationType.Reveal,
                    ["fee"]           = "0",
                    ["public_key"]    = Base58Check.Encode(publicKey, Prefix.Edpk),
                    ["source"]        = From,
                    ["storage_limit"] = storage,
                    ["gas_limit"]     = gas,
                    ["counter"]       = counter.ToString()//revealOpCounter.ToString()
                };

                Operations.AddFirst(revealOp);

                counter++;
            }

            //var counter = await TezosCounter.Instance
            //    .GetCounter(xtz, From, Head)
            //    .ConfigureAwait(false);

            var transaction = new JObject
            {
                ["kind"]          = OperationType.Delegation,
                ["source"]        = From,
                ["fee"]           = ((int)Fee).ToString(CultureInfo.InvariantCulture),
                ["counter"]       = counter.ToString(),
                ["gas_limit"]     = gas,
                ["storage_limit"] = storage,
                ["delegate"]      = To
            };

            Operations.Add(transaction);

            if (Params != null)
            {
                transaction["parameters"] = Params;
            }

            var fill = await rpc
                       .AutoFillOperations(xtz, Head, Operations, useDefaultFee)
                       .ConfigureAwait(false);

            if (!fill)
            {
                Log.Error("Delegation autofilling error");
                return(false);
            }

            // Fee = Operations[0]["fee"].Value<decimal>() / 1_000_000;
            Fee = Operations.Last["fee"].Value <decimal>() / 1_000_000;

            return(true);
        }
コード例 #10
0
        public async Task FillOperationsAsync(
            JObject head,
            SecureBytes securePublicKey,
            bool incrementCounter = true,
            CancellationToken cancellationToken = default)
        {
            using var publicKey = securePublicKey.ToUnsecuredBytes();

            var xtz = (Atomex.Tezos)Currency;

            var rpc = new Rpc(xtz.RpcNodeUri);

            var managerKey = await rpc
                             .GetManagerKey(From)
                             .ConfigureAwait(false);

            Operations = new JArray();

            var gas     = GasLimit.ToString(CultureInfo.InvariantCulture);
            var storage = StorageLimit.ToString(CultureInfo.InvariantCulture);

            var counter = await TezosCounter.Instance
                          .GetCounter(xtz, From, head, ignoreCache : !incrementCounter)
                          .ConfigureAwait(false);

            // if (managerKey["key"] == null)
            if (managerKey.Value <string>() == null)
            {
                //var revealOpCounter = ;

                var revealOp = new JObject
                {
                    ["kind"]          = OperationType.Reveal,
                    ["fee"]           = "0",
                    ["public_key"]    = Base58Check.Encode(publicKey, Prefix.Edpk),
                    ["source"]        = From,
                    ["storage_limit"] = "0",
                    ["gas_limit"]     = xtz.RevealGasLimit.ToString(),
                    ["counter"]       = counter.ToString()
                };

                Operations.AddFirst(revealOp);

                counter++;
            }

            var transaction = new JObject
            {
                ["kind"]          = OperationType.Transaction,
                ["source"]        = From,
                ["fee"]           = ((int)Fee).ToString(CultureInfo.InvariantCulture),
                ["counter"]       = counter.ToString(),
                ["gas_limit"]     = gas,
                ["storage_limit"] = storage,
                ["amount"]        = Math.Round(Amount, 0).ToString(CultureInfo.InvariantCulture),
                ["destination"]   = To
            };

            Operations.Add(transaction);

            if (Params != null)
            {
                transaction["parameters"] = Params;
            }
        }