Пример #1
0
        public IRpcMethodResult GetDefaultAccount()
        {
            try
            {
                var accountComponent = new AccountComponent();
                var account          = accountComponent.GetDefaultAccount();

                if (account != null)
                {
                    var result = new AccountOM();
                    result.Address   = account.Id;
                    result.PublicKey = account.PublicKey;
                    result.Balance   = account.Balance;
                    result.IsDefault = account.IsDefault;
                    result.WatchOnly = account.WatchedOnly;
                    result.Tag       = account.Tag;

                    return(Ok(result));
                }
                else
                {
                    throw new CommonException(ErrorCode.Service.Account.ACCOUNT_NOT_FOUND);
                }
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
Пример #2
0
        private void transactionTest()
        {
            var utxoComponent        = new UtxoComponent();
            var transactionComponent = new TransactionComponent();
            var accountComponent     = new AccountComponent();

            if (string.IsNullOrWhiteSpace(this.newAccountId))
            {
                var newAccount = accountComponent.GenerateNewAccount();
                this.newAccountId = newAccount.Id;
            }

            var defaultAccount = accountComponent.GetDefaultAccount();

            if (defaultAccount != null)
            {
                var balance = utxoComponent.GetConfirmedBlanace(defaultAccount.Id);
                var amount  = 50000000000L;
                var fee     = 1000000L;

                if (balance > (amount + fee))
                {
                    var dict = new Dictionary <string, long>();
                    dict.Add(newAccountId, amount);

                    var txMsg = transactionComponent.CreateNewTransactionMsg(defaultAccount.Id, dict, fee);
                    transactionComponent.AddTransactionToPool(txMsg);

                    LogHelper.Debug("====== A New transaction has been created. " + txMsg.Hash);

                    if (BlockchainJob.Current.P2PJob != null)
                    {
                        BlockchainJob.Current.P2PJob.BroadcastNewTransactionMessage(txMsg.Hash);
                    }
                }
            }
        }