Пример #1
0
        public static void TestConductTransactions(
            APIKey key1,
            APIKey key2
            )
        {
            Console.Write("Testing SendMoney w/ Valid Key: ");
            ReceiveAddress addr1 = API.GetReceiveAddress(key1);
            ReceiveAddress addr2 = API.GetReceiveAddress(key2);

            SendMoneyTransaction sendMoney = new SendMoneyTransaction()
            {
                ToAddr = addr1.Address,
                Amount = new Amount() { AmountValue = 0.01m, Currency = "BTC" },
                Notes = "Testing send_money"
            };
            Transaction sendMoneyTransaction = API.SendMoney(
                sendMoney,
                key2
                );
            ASSERT(sendMoneyTransaction.IsValid, sendMoneyTransaction);

            if (!sendMoneyTransaction.IsValid)
            {
                return;
            }

            User user1 = API.GetUser(key1);
            if (!user1.IsValid)
            {
                return;
            }

            Console.Write("Testing RequestMoney w/ Valid Key: ");
            RequestMoneyTransaction requestMoney = new RequestMoneyTransaction()
            {
                FromAddr = user1.Email,
                Amount = new Amount() { AmountValue = 0.01m, Currency = "BTC" },
                Notes = "Testing request_money"
            };
            Transaction requestMoneyTransaction = API.RequestMoney(
                requestMoney,
                key2
                );
            ASSERT(requestMoneyTransaction.IsValid, requestMoneyTransaction);

            if (!requestMoneyTransaction.IsValid)
            {
                return;
            }

            Console.Write("Testing CancelRequest w/ Valid Key: ");
            CoinbaseResponse response = API.CancelRequest(requestMoneyTransaction.ID, key1);
            ASSERT(response.IsValid, response);

            requestMoneyTransaction = API.RequestMoney(
                requestMoney,
                key2
                );
            if (!requestMoneyTransaction.IsValid)
            {
                return;
            }

            response = API.ResendRequest(requestMoneyTransaction.ID, key2);
            Console.Write("Testing ResendRequest w/ Valid Key: ");
            ASSERT(response.IsValid, response);

            Console.Write("Testing CompleteRequest w/ Valid Key: ");
            response = API.CompleteRequest(requestMoneyTransaction.ID, key1);
            ASSERT(response.IsValid, response);
        }
Пример #2
0
        private Transaction SnapshotCommitmentIntoBitcoin(string commitment)
        {
            APIKey key1 = new APIKey(
                RoleEnvironment.GetConfigurationSettingValue("CoinbaseAccountKey1")
                );
            APIKey key2 = new APIKey(
                RoleEnvironment.GetConfigurationSettingValue("CoinbaseAccountKey2")
                );

            Amount balance1 = API.GetBalance(key1);

            if (!balance1.IsValid)
            {
                Trace.TraceError(
                    "Unable to get balance for {0}: {1}",
                    key1,
                    balance1
                    );
                return null;
            }

            Amount balance2 = API.GetBalance(key2);
            if (!balance2.IsValid)
            {
                Trace.TraceError(
                    "Unable to get balance for {0}: {1}",
                    key2,
                    balance2
                    );
                return null;
            }

            if (balance1.AmountValue < balance2.AmountValue)
            {
                APIKey tempKey = key1;
                Amount tempBalance = balance1;
                key1 = key2;
                balance1 = balance2;
                key2 = tempKey;
                balance2 = tempBalance;
            }

            if (balance1.AmountValue < API.MINIMUM_PAYMENT_AMOUNT)
            {
                Trace.TraceError(
                    "Insufficient Funds ({0}) to send miniumum payment of {1} BTC",
                    balance1,
                    API.MINIMUM_PAYMENT_AMOUNT
                    );
                return null;
            }

            User user2 = API.GetUser(key2);
            if (!user2.IsValid)
            {
                Trace.TraceError(
                    "Unable to get User Information for {0}: {1}",
                    key2,
                    user2
                    );
                return null;
            }

            SendMoneyTransaction sendMoney = new SendMoneyTransaction()
            {
                Amount = new Amount() { AmountValue = API.MINIMUM_PAYMENT_AMOUNT, Currency = "BTC" },
                ToAddr = user2.Email,
                Notes = commitment
            };

            Transaction transaction = API.SendMoney(sendMoney, key1);

            if (!transaction.IsValid)
            {
                Trace.TraceError(
                    "Unable to complete SendMoney Transaction: {0}",
                    transaction
                    );
                return null;
            }

            return transaction;
        }
Пример #3
0
        public static Transaction SendMoney(SendMoneyTransaction transaction, APIKey apiKey)
        {
            SendMoneyTransactionRequest request = new SendMoneyTransactionRequest()
            {
                Transaction = transaction
            };
            TransactionResponse transactionResponse = (TransactionResponse) PostResource(
                "transactions",
                "send_money",
                request,
                typeof(SendMoneyTransactionRequest),
                typeof(TransactionResponse),
                apiKey
                );

            return transactionResponse.Transaction;
        }