コード例 #1
0
        /// <summary>
        /// Makes a 'invokescript' RPC call to the connected node.
        /// Return the gas cost if the contract tx is "simulated" correctly
        /// </summary>
        /// <param name="scriptHash"></param>
        /// <param name="operation"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public async Task <decimal> EstimateGasContractInvocation(byte[] scriptHash, string operation,
                                                                  object[] args)
        {
            var bytes = Utils.GenerateScript(scriptHash.ToScriptHash(), operation, args);

            return(await EstimateGasAsync(bytes.ToHexString()));
        }
コード例 #2
0
        /// <summary>
        /// Creates an InvocationTransactions. Serves to invoke a contract on the blockchain.
        /// It need the contract script hash, operation and operation arguments.
        /// This can be used for the "mintTokens" NEP5 method for example.
        /// </summary>
        /// <param name="contractScriptHash"></param>
        /// <param name="operation"></param>
        /// <param name="args"></param>
        /// <param name="outputs"></param>
        /// <param name="fee"></param>
        /// <param name="attributes"></param>
        /// <returns></returns>
        public override async Task <Transaction> CallContract(string contractScriptHash, string operation,
                                                              object[] args, IEnumerable <TransferOutput> outputs = null,
                                                              decimal fee = 0, List <TransactionAttribute> attributes = null)
        {
            if (string.IsNullOrEmpty(contractScriptHash))
            {
                throw new ArgumentNullException(nameof(contractScriptHash));
            }
            if (string.IsNullOrEmpty(operation))
            {
                throw new ArgumentNullException(nameof(operation));
            }

            var script = Utils.GenerateScript(contractScriptHash, operation, args);

            if (attributes == null)
            {
                attributes = new List <TransactionAttribute>();
            }
            attributes.Add(new TransactionAttribute
            {
                Usage = TransactionAttributeUsage.Script,
                Data  = AddressScriptHash.ToArray()
            });

            var tx = new InvocationTransaction
            {
                Version    = 1,
                Script     = script,
                Attributes = attributes.ToArray(),
                Inputs     = new CoinReference[0],
                Outputs    = outputs == null ? new TransactionOutput[0] : outputs.Where(p => p.IsGlobalAsset).Select(p => p.ToTxOutput()).ToArray(),
                Witnesses  = new Witness[0]
            };

            var gasConsumed = await EstimateGasAsync(tx.Script.ToHexString());

            tx.Gas = InvocationTransaction.GetGas(Fixed8.FromDecimal(gasConsumed));

            tx = MakeTransaction(tx, AddressScriptHash, null, Fixed8.FromDecimal(fee));
            var success = await SignAndSendTransaction(tx);

            return(success ? tx : null);
        }
コード例 #3
0
 /// <summary>
 /// Signs a message using ECDSA algo, with NIST P-256 curve and SHA-256 hash function
 /// </summary>
 /// <param name="messageToSign"></param>
 /// <returns></returns>
 public override string SignMessage(string messageToSign)
 {
     return(Utils.Sign(messageToSign.HexToBytes(), _accountKey.PrivateKey).ToHexString());
 }
コード例 #4
0
ファイル: Transaction.cs プロジェクト: logikonline/NeoModules
 /// <summary>
 /// Serializes a transaction (without witnesses).
 /// Returns a byte array.
 /// </summary>
 /// <returns></returns>
 public byte[] SerializeTransaction()
 {
     return(Utils.GetHashData(this));
 }
コード例 #5
0
ファイル: Transaction.cs プロジェクト: logikonline/NeoModules
 public byte[] Sign(byte[] privateKey, bool signed = true)
 {
     return(Utils.Sign(new KeyPair(privateKey), this, signed));
 }
コード例 #6
0
ファイル: Transaction.cs プロジェクト: logikonline/NeoModules
 /// <summary>
 /// Serializes and sign the transaction with the given private key.
 /// Return a byte array.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="signed"></param>
 /// <returns></returns>
 public byte[] Sign(KeyPair key, bool signed = true)
 {
     return(Utils.Sign(key, this, signed));
 }