Exemple #1
0
 /// <summary>
 /// TransactionManager Constructor
 /// </summary>
 /// <param name="rpc">the RPC client to call NEO RPC API</param>
 /// <param name="sender">the account script hash of sender</param>
 public TransactionManager(RpcClient rpc, UInt160 sender)
 {
     rpcClient   = rpc;
     policyAPI   = new PolicyAPI(rpc);
     nep5API     = new Nep5API(rpc);
     this.sender = sender;
 }
Exemple #2
0
        /// <summary>
        /// Returns the balance of the corresponding asset in the wallet, based on the specified asset Id.
        /// This method applies to assets that conform to NEP-5 standards.
        /// </summary>
        /// <returns>new address as string</returns>
        public BigDecimal GetBalance(string assetId)
        {
            byte       decimals = new Nep5API(this).Decimals(UInt160.Parse(assetId));
            BigInteger balance  = BigInteger.Parse(RpcSend("getbalance", assetId)["balance"].AsString());

            return(new BigDecimal(balance, decimals));
        }
Exemple #3
0
        /// <summary>
        /// Create an unsigned Transaction object with given parameters.
        /// </summary>
        /// <param name="script">Transaction Script</param>
        /// <param name="attributes">Transaction Attributes</param>
        /// <param name="cosigners">Transaction Cosigners</param>
        /// <param name="networkFee">Transaction NetworkFee, will set to estimate value(with only basic signatures) when networkFee is 0</param>
        /// <returns></returns>
        public TransactionManager MakeTransaction(byte[] script, TransactionAttribute[] attributes = null, Cosigner[] cosigners = null, long networkFee = 0)
        {
            var  random = new Random();
            uint height = rpcClient.GetBlockCount() - 1;

            Tx = new Transaction
            {
                Version         = 0,
                Nonce           = (uint)random.Next(),
                Script          = script,
                Sender          = sender,
                ValidUntilBlock = height + Transaction.MaxValidUntilBlockIncrement,
                Attributes      = attributes ?? new TransactionAttribute[0],
                Cosigners       = cosigners ?? new Cosigner[0],
                Witnesses       = new Witness[0]
            };

            RpcInvokeResult result = rpcClient.InvokeScript(script);

            Tx.SystemFee = Math.Max(long.Parse(result.GasConsumed) - ApplicationEngine.GasFree, 0);
            if (Tx.SystemFee > 0)
            {
                long d         = (long)NativeContract.GAS.Factor;
                long remainder = Tx.SystemFee % d;
                if (remainder > 0)
                {
                    Tx.SystemFee += d - remainder;
                }
                else if (remainder < 0)
                {
                    Tx.SystemFee -= remainder;
                }
            }

            context = new ContractParametersContext(Tx);

            // set networkfee to estimate value when networkFee is 0
            Tx.NetworkFee = networkFee == 0 ? EstimateNetworkFee() : networkFee;

            var gasBalance = new Nep5API(rpcClient).BalanceOf(NativeContract.GAS.Hash, sender);

            if (gasBalance >= Tx.SystemFee + Tx.NetworkFee)
            {
                return(this);
            }
            throw new InvalidOperationException($"Insufficient GAS in address: {sender.ToAddress()}");
        }
Exemple #4
0
 /// <summary>
 /// WalletAPI Constructor
 /// </summary>
 /// <param name="rpc">the RPC client to call NEO RPC methods</param>
 public WalletAPI(RpcClient rpc)
 {
     rpcClient = rpc;
     nep5API   = new Nep5API(rpc);
 }
 /// <summary>
 /// TransactionManager Constructor
 /// </summary>
 /// <param name="rpc">the RPC client to call NEO RPC API</param>
 /// <param name="sender">the account script hash of sender</param>
 public TransactionManager(RpcClient rpc)
 {
     rpcClient = rpc;
     policyAPI = new PolicyAPI(rpc);
     nep5API   = new Nep5API(rpc);
 }