示例#1
0
        async Task <UInt256> SubmitTransactionAsync(Transaction tx)
        {
            if (disposedValue)
            {
                throw new ObjectDisposedException(nameof(OfflineNode));
            }

            var transactions = new[] { tx };

            // Verify the provided transactions. When running, Blockchain class does verification in two steps: VerifyStateIndependent and VerifyStateDependent.
            // However, Verify does both parts and there's no point in verifying dependent/independent in separate steps here
            var verificationContext = new TransactionVerificationContext();

            for (int i = 0; i < transactions.Length; i++)
            {
                if (transactions[i].Verify(neoSystem.Settings, neoSystem.StoreView, verificationContext) != VerifyResult.Succeed)
                {
                    throw new Exception("Verification failed");
                }
            }

            var prevHash   = NativeContract.Ledger.CurrentHash(neoSystem.StoreView);
            var prevHeader = NativeContract.Ledger.GetHeader(neoSystem.StoreView, prevHash);
            var block      = ExpressOracle.CreateSignedBlock(prevHeader,
                                                             consensusNodesKeys.Value,
                                                             neoSystem.Settings.Network,
                                                             transactions);

            await RelayBlockAsync(block).ConfigureAwait(false);

            return(block.Hash);
        }
示例#2
0
        public static async Task FastForwardAsync(Header prevHeader, uint blockCount, TimeSpan timestampDelta, KeyPair[] keyPairs, uint network, Func <Block, Task> submitBlockAsync)
        {
            if (timestampDelta.TotalSeconds < 0)
            {
                throw new ArgumentException($"Negative {nameof(timestampDelta)} not supported");
            }
            if (blockCount == 0)
            {
                return;
            }

            var timestamp = Math.Max(Neo.Helper.ToTimestampMS(DateTime.UtcNow), prevHeader.Timestamp + 1);
            var delta     = (ulong)timestampDelta.TotalMilliseconds;

            if (blockCount == 1)
            {
                var block = ExpressOracle.CreateSignedBlock(
                    prevHeader, keyPairs, network, timestamp: timestamp + delta);
                await submitBlockAsync(block).ConfigureAwait(false);
            }
            else
            {
                var period = delta / (blockCount - 1);
                for (int i = 0; i < blockCount; i++)
                {
                    var block = ExpressOracle.CreateSignedBlock(
                        prevHeader, keyPairs, network, timestamp: timestamp);
                    await submitBlockAsync(block).ConfigureAwait(false);

                    prevHeader = block.Header;
                    timestamp += period;
                }
            }
        }
示例#3
0
        public async Task <UInt256> SubmitOracleResponseAsync(OracleResponse response, ECPoint[] oracleNodes)
        {
            var jsonTx = await rpcClient.RpcSendAsync("expresscreateoracleresponsetx", response.ToJson()).ConfigureAwait(false);

            var tx = Convert.FromBase64String(jsonTx.AsString()).AsSerializable <Transaction>();

            ExpressOracle.SignOracleResponseTransaction(chain, tx, oracleNodes);
            return(await SubmitTransactionAsync(tx));
        }
示例#4
0
        public async Task FastForwardAsync(uint blockCount, TimeSpan timestampDelta)
        {
            var prevHash = await rpcClient.GetBestBlockHashAsync().ConfigureAwait(false);

            var prevHeaderHex = await rpcClient.GetBlockHeaderHexAsync($"{prevHash}").ConfigureAwait(false);

            var prevHeader = Convert.FromBase64String(prevHeaderHex).AsSerializable <Header>();

            await ExpressOracle.FastForwardAsync(prevHeader,
                                                 blockCount,
                                                 timestampDelta,
                                                 consensusNodesKeys.Value,
                                                 ProtocolSettings.Network,
                                                 block => rpcClient.SubmitBlockAsync(block.ToArray()));
        }
示例#5
0
        public async Task FastForwardAsync(uint blockCount, TimeSpan timestampDelta)
        {
            if (disposedValue)
            {
                throw new ObjectDisposedException(nameof(OfflineNode));
            }

            var prevHash   = NativeContract.Ledger.CurrentHash(neoSystem.StoreView);
            var prevHeader = NativeContract.Ledger.GetHeader(neoSystem.StoreView, prevHash);

            await ExpressOracle.FastForwardAsync(prevHeader,
                                                 blockCount,
                                                 timestampDelta,
                                                 consensusNodesKeys.Value,
                                                 ProtocolSettings.Network,
                                                 block => RelayBlockAsync(block));
        }
示例#6
0
        public JObject?ExpressCreateOracleResponseTx(JArray @params)
        {
            var jsonResponse = @params[0];
            var response     = new OracleResponse
            {
                Id     = (ulong)jsonResponse["id"].AsNumber(),
                Code   = (OracleResponseCode)jsonResponse["code"].AsNumber(),
                Result = Convert.FromBase64String(jsonResponse["result"].AsString())
            };

            using var snapshot = neoSystem.GetSnapshot();
            var height      = NativeContract.Ledger.CurrentIndex(snapshot) + 1;
            var oracleNodes = NativeContract.RoleManagement.GetDesignatedByRole(snapshot, Role.Oracle, height);
            var request     = NativeContract.Oracle.GetRequest(snapshot, response.Id);
            var tx          = ExpressOracle.CreateResponseTx(snapshot, request, response, oracleNodes, neoSystem.Settings);

            return(tx == null ? null : Convert.ToBase64String(tx.ToArray()));
        }
示例#7
0
        public async Task <UInt256> SubmitOracleResponseAsync(OracleResponse response, IReadOnlyList <ECPoint> oracleNodes)
        {
            if (disposedValue)
            {
                throw new ObjectDisposedException(nameof(OfflineNode));
            }

            using var snapshot = neoSystem.GetSnapshot();
            var height  = NativeContract.Ledger.CurrentIndex(snapshot) + 1;
            var request = NativeContract.Oracle.GetRequest(snapshot, response.Id);
            var tx      = ExpressOracle.CreateResponseTx(snapshot, request, response, oracleNodes, ProtocolSettings);

            if (tx == null)
            {
                throw new Exception("Failed to create Oracle Response Tx");
            }
            ExpressOracle.SignOracleResponseTransaction(ProtocolSettings, chain, tx, oracleNodes);

            return(await SubmitTransactionAsync(tx));
        }