Ejemplo n.º 1
0
        private static async Task <UInt256> DeployDataAsync(string nodeAddress, PrivateKey initiatorPrivateKey, UInt256 witness, params DataAction[] actions)
        {
            var initiatorAddress = initiatorPrivateKey.GetAddress(signAlgorithm);
            var tran             = new DataTransaction(initiatorAddress, null, witness, actions);
            var unlockscript     = signAlgorithm.Sign((byte[])tran.GetLockHash(), initiatorPrivateKey);

            tran.UnlockScripts = new UnlockScripts(new[] { new ScriptToken(unlockscript.ToString()) });

            tran.Sign(signAlgorithm, initiatorPrivateKey);
            var signature = tran.Signature.ToString();

            var response = await new JsonRpcRequest
            {
                Method     = Commands.CreateDataTransaction,
                Parameters = new CreateDataTransactionRpcRequest
                {
                    Initiator     = initiatorAddress.ToString(),
                    Signature     = signature.ToString(),
                    WitnessBlock  = witness,
                    UnlockScripts = tran.UnlockScripts,
                    Actions       = actions,
                }
            }.ConnectAndRequest <CreateTransactionRpcResponse>(nodeAddress);

            if (response.Error != null)
            {
                throw new EvaluateException($"error when deploy transaction: [{response.Error.Code}]{response.Error.Message}");
            }

            return(response.Result.TransactionId);
        }