mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-18 07:26:50 +00:00
Withdraw additional functionality (validation/submission/tracking) (#409)
* reworked request struct and exchange response started work on validation system * removed import cycle until work around * Added intial withdraw support via CLI added * Added Crypto command to gctcli * moved var declartion to single line * Test updates for binance and anx * All exchange tests have been updated test coverage added to validate * First pass at adding withdrawl select from database * started adding basic lru cache system * Added basic LRU cache including Add Get Remove Contains ContainsOrAdd Clear * wording changes on comments * removed exported var's in strut as they are not required * Added README * README updates * corrected ID on commands * rm line :D * merged in origin/cache * linter fixes (gofmt) * Added basic cache lookup to events * swapped to mutex over rwmutex updated comments * unexported getNewest & getOldest * unexported getNewest & getOldest * Updated comments and cited references in source * updated comments * WIP * Migrated exchange WithdrawFiat wrapper to new struct response * Migrated exchange WithdrawFiat wrapper to new struct response * started work on bank management * Added exchange level banking details back with migration to banking package * Removed broken tests for now * Added validation to bank accounts * removed duplicate bank details from withdraw struct * Test coverage increased * gofmt * merged upstream/master with clean up * First pass at adding command line linking to gctcli * added validation for crypto address, added gctcli support to retreive previous withdrawal requests * general cleanup * general cleanup * reordered imports * Increased test coverage moved to database sublogger * Pass incorrect currency no longer return error from c.CheckBankAccountConfig * remove TestMain() for now as other tests in this package will need to be reworked * Happy little race car * Reverted to upstream tests * Added test covarege for validation method, corrected response on cli protobuf * query clean up and removal of duplicated code * cleaned up queries into singlem ethod increased test coverage * Migrated international fund withdraw to new exchange response and added cache size override * Migrated international fund withdraw to new exchange response and added cache size override * Extended gctcli commands * lowered default cache to 25 * small code clean up * added get by date method * add returned error * cli commands cleaing return error on nil results to fix out of bounds * merged write & read helpers into one for test coverage and increased engine/withdraw test coverage * gofmt * Added test coverage for valid ID * removed unused param * converted to use timestamp package from protobuf * gofmt * use built in RFC3339 timestamp * remove setting of CreatedAt & UpdatedAt and allow ORm to take care of it * also use ptype on byid * code flow improvements * remove inverse conditional check and linters run * removed test data * removed comment * removed comment * also write failures to database for auditing * converted to use default time for start & end * Default to time.Now() minus 30 days * Default to time.Now() minus 30 days * small code clean up * fixed missing semicolon on migrations, code clean up * updated sqlite migrations * Added additonal check for exchange level bank account if global is not found * case sensativity fix for currency names * use correct compare * test coverage fixed * removed space * return pointer to banking.Account * return pointer to banking.Account * added else check back to validate() * Added empty string as default to migration over NULL due to retrivial of data
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
)
|
||||
|
||||
@@ -334,19 +334,19 @@ func ({{.Variable}} *{{.CapitalName}}) GetDepositAddress(cryptocurrency currency
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
func ({{.Variable}} *{{.CapitalName}}) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -175,16 +175,16 @@ func testWrappers(e exchange.IBotExchange) []string {
|
||||
funcs = append(funcs, "GetDepositAddress")
|
||||
}
|
||||
|
||||
_, err = e.WithdrawCryptocurrencyFunds(&withdraw.CryptoRequest{})
|
||||
_, err = e.WithdrawCryptocurrencyFunds(&withdraw.Request{})
|
||||
if err == common.ErrNotYetImplemented {
|
||||
funcs = append(funcs, "WithdrawCryptocurrencyFunds")
|
||||
}
|
||||
|
||||
_, err = e.WithdrawFiatFunds(&withdraw.FiatRequest{})
|
||||
_, err = e.WithdrawFiatFunds(&withdraw.Request{})
|
||||
if err == common.ErrNotYetImplemented {
|
||||
funcs = append(funcs, "WithdrawFiatFunds")
|
||||
}
|
||||
_, err = e.WithdrawFiatFundsToInternationalBank(&withdraw.FiatRequest{})
|
||||
_, err = e.WithdrawFiatFundsToInternationalBank(&withdraw.Request{})
|
||||
if err == common.ErrNotYetImplemented {
|
||||
funcs = append(funcs, "WithdrawFiatFundsToInternationalBank")
|
||||
}
|
||||
|
||||
@@ -23,7 +23,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -622,15 +623,14 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{r19}),
|
||||
})
|
||||
|
||||
genericWithdrawRequest := withdraw.GenericInfo{
|
||||
Amount: config.OrderSubmission.Amount,
|
||||
withdrawRequest := withdraw.Request{
|
||||
Currency: p.Quote,
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: withdrawAddressOverride,
|
||||
},
|
||||
Amount: config.OrderSubmission.Amount,
|
||||
}
|
||||
withdrawRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: genericWithdrawRequest,
|
||||
Address: withdrawAddressOverride,
|
||||
}
|
||||
var r20 string
|
||||
var r20 *withdraw.ExchangeResponse
|
||||
r20, err = e.WithdrawCryptocurrencyFunds(&withdrawRequest)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
@@ -666,53 +666,59 @@ func testWrappers(e exchange.IBotExchange, base *exchange.Base, config *Config)
|
||||
Response: jsonifyInterface([]interface{}{r21}),
|
||||
})
|
||||
|
||||
fiatWithdrawRequest := withdraw.FiatRequest{
|
||||
GenericInfo: genericWithdrawRequest,
|
||||
BankAccountName: config.BankDetails.BankAccountName,
|
||||
BankAccountNumber: config.BankDetails.BankAccountNumber,
|
||||
SwiftCode: config.BankDetails.SwiftCode,
|
||||
IBAN: config.BankDetails.Iban,
|
||||
BankCity: config.BankDetails.BankCity,
|
||||
BankName: config.BankDetails.BankName,
|
||||
BankAddress: config.BankDetails.BankAddress,
|
||||
BankCountry: config.BankDetails.BankCountry,
|
||||
BankPostalCode: config.BankDetails.BankPostalCode,
|
||||
BankCode: config.BankDetails.BankCode,
|
||||
IsExpressWire: config.BankDetails.IsExpressWire,
|
||||
RequiresIntermediaryBank: config.BankDetails.RequiresIntermediaryBank,
|
||||
IntermediaryBankName: config.BankDetails.IntermediaryBankName,
|
||||
IntermediaryBankAccountNumber: config.BankDetails.IntermediaryBankAccountNumber,
|
||||
IntermediarySwiftCode: config.BankDetails.IntermediarySwiftCode,
|
||||
IntermediaryIBAN: config.BankDetails.IntermediaryIban,
|
||||
IntermediaryBankCity: config.BankDetails.IntermediaryBankCity,
|
||||
IntermediaryBankAddress: config.BankDetails.IntermediaryBankAddress,
|
||||
IntermediaryBankCountry: config.BankDetails.IntermediaryBankCountry,
|
||||
IntermediaryBankPostalCode: config.BankDetails.IntermediaryBankPostalCode,
|
||||
IntermediaryBankCode: config.BankDetails.IntermediaryBankCode,
|
||||
withdrawRequestFiat := withdraw.Request{
|
||||
Currency: p.Quote,
|
||||
Amount: config.OrderSubmission.Amount,
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: &banking.Account{
|
||||
AccountName: config.BankDetails.BankAccountName,
|
||||
AccountNumber: config.BankDetails.BankAccountNumber,
|
||||
SWIFTCode: config.BankDetails.SwiftCode,
|
||||
IBAN: config.BankDetails.Iban,
|
||||
BankPostalCity: config.BankDetails.BankCity,
|
||||
BankName: config.BankDetails.BankName,
|
||||
BankAddress: config.BankDetails.BankAddress,
|
||||
BankCountry: config.BankDetails.BankCountry,
|
||||
BankPostalCode: config.BankDetails.BankPostalCode,
|
||||
BankCode: config.BankDetails.BankCode,
|
||||
},
|
||||
|
||||
IsExpressWire: config.BankDetails.IsExpressWire,
|
||||
RequiresIntermediaryBank: config.BankDetails.RequiresIntermediaryBank,
|
||||
IntermediaryBankName: config.BankDetails.IntermediaryBankName,
|
||||
IntermediaryBankAccountNumber: config.BankDetails.IntermediaryBankAccountNumber,
|
||||
IntermediarySwiftCode: config.BankDetails.IntermediarySwiftCode,
|
||||
IntermediaryIBAN: config.BankDetails.IntermediaryIban,
|
||||
IntermediaryBankCity: config.BankDetails.IntermediaryBankCity,
|
||||
IntermediaryBankAddress: config.BankDetails.IntermediaryBankAddress,
|
||||
IntermediaryBankCountry: config.BankDetails.IntermediaryBankCountry,
|
||||
IntermediaryBankPostalCode: config.BankDetails.IntermediaryBankPostalCode,
|
||||
IntermediaryBankCode: config.BankDetails.IntermediaryBankCode,
|
||||
},
|
||||
}
|
||||
var r22 string
|
||||
r22, err = e.WithdrawFiatFunds(&fiatWithdrawRequest)
|
||||
var r22 *withdraw.ExchangeResponse
|
||||
r22, err = e.WithdrawFiatFunds(&withdrawRequestFiat)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
msg = err.Error()
|
||||
responseContainer.ErrorCount++
|
||||
}
|
||||
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
|
||||
SentParams: jsonifyInterface([]interface{}{fiatWithdrawRequest}),
|
||||
SentParams: jsonifyInterface([]interface{}{withdrawRequestFiat}),
|
||||
Function: "WithdrawFiatFunds",
|
||||
Error: msg,
|
||||
Response: r22,
|
||||
})
|
||||
|
||||
var r23 string
|
||||
r23, err = e.WithdrawFiatFundsToInternationalBank(&fiatWithdrawRequest)
|
||||
var r23 *withdraw.ExchangeResponse
|
||||
r23, err = e.WithdrawFiatFundsToInternationalBank(&withdrawRequestFiat)
|
||||
msg = ""
|
||||
if err != nil {
|
||||
msg = err.Error()
|
||||
responseContainer.ErrorCount++
|
||||
}
|
||||
responseContainer.EndpointResponses = append(responseContainer.EndpointResponses, EndpointResponse{
|
||||
SentParams: jsonifyInterface([]interface{}{fiatWithdrawRequest}),
|
||||
SentParams: jsonifyInterface([]interface{}{withdrawRequestFiat}),
|
||||
Function: "WithdrawFiatFundsToInternationalBank",
|
||||
Error: msg,
|
||||
Response: r23,
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -13,12 +14,16 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctrpc"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
const timeFormat = "2006-01-02 15:04:05"
|
||||
|
||||
var startTime, endTime, order string
|
||||
var limit int
|
||||
|
||||
var getInfoCommand = cli.Command{
|
||||
Name: "getinfo",
|
||||
Usage: "gets GoCryptoTrader info",
|
||||
@@ -903,7 +908,7 @@ func getPortfolioSummary(_ *cli.Context) error {
|
||||
var addPortfolioAddressCommand = cli.Command{
|
||||
Name: "addportfolioaddress",
|
||||
Usage: "adds an address to the portfolio",
|
||||
ArgsUsage: "<address> <coin_type> <description> <balance>",
|
||||
ArgsUsage: "<address> <coin_type> <description> <balance> <cold_storage> <supported_exchanges> ",
|
||||
Action: addPortfolioAddress,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
@@ -922,6 +927,14 @@ var addPortfolioAddressCommand = cli.Command{
|
||||
Name: "balance",
|
||||
Usage: "balance of the address",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "cold_storage",
|
||||
Usage: "true/false if address is cold storage",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "supported_exchanges",
|
||||
Usage: "common separated list of exchanges supported by this address for withdrawals",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -941,6 +954,8 @@ func addPortfolioAddress(c *cli.Context) error {
|
||||
var coinType string
|
||||
var description string
|
||||
var balance float64
|
||||
var supportedExchanges string
|
||||
var coldstorage bool
|
||||
|
||||
if c.IsSet("address") {
|
||||
address = c.String("address")
|
||||
@@ -969,13 +984,30 @@ func addPortfolioAddress(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("cold_storage") {
|
||||
coldstorage = c.Bool("cold_storage")
|
||||
} else {
|
||||
tv, errBool := strconv.ParseBool(c.Args().Get(4))
|
||||
if errBool == nil {
|
||||
coldstorage = tv
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("supported_exchanges") {
|
||||
supportedExchanges = c.String("supported_exchanges")
|
||||
} else {
|
||||
supportedExchanges = c.Args().Get(5)
|
||||
}
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
result, err := client.AddPortfolioAddress(context.Background(),
|
||||
&gctrpc.AddPortfolioAddressRequest{
|
||||
Address: address,
|
||||
CoinType: coinType,
|
||||
Description: description,
|
||||
Balance: balance,
|
||||
Address: address,
|
||||
CoinType: coinType,
|
||||
Description: description,
|
||||
Balance: balance,
|
||||
SupportedExchanges: supportedExchanges,
|
||||
ColdStorage: coldstorage,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -2148,9 +2180,9 @@ func getCryptocurrencyDepositAddress(c *cli.Context) error {
|
||||
}
|
||||
|
||||
var withdrawCryptocurrencyFundsCommand = cli.Command{
|
||||
Name: "withdrawcryptocurrencyfunds",
|
||||
Name: "withdrawcryptofunds",
|
||||
Usage: "withdraws cryptocurrency funds from the desired exchange",
|
||||
ArgsUsage: "<exchange> <cryptocurrency>",
|
||||
ArgsUsage: "<exchange> <currency> <amount> <address> <addresstag> <fee> <description>",
|
||||
Action: withdrawCryptocurrencyFunds,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
@@ -2158,20 +2190,123 @@ var withdrawCryptocurrencyFundsCommand = cli.Command{
|
||||
Usage: "the exchange to withdraw from",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "cryptocurrency",
|
||||
Name: "currency",
|
||||
Usage: "the cryptocurrency to withdraw funds from",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "address",
|
||||
Usage: "address to withdraw to",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "addresstag",
|
||||
Usage: "address tag/memo",
|
||||
},
|
||||
cli.Float64Flag{
|
||||
Name: "amount",
|
||||
Usage: "amount of funds to withdraw",
|
||||
},
|
||||
cli.Float64Flag{
|
||||
Name: "fee",
|
||||
Usage: "fee to submit with request",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "description",
|
||||
Usage: "description to submit with request",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func withdrawCryptocurrencyFunds(_ *cli.Context) error {
|
||||
return common.ErrNotYetImplemented
|
||||
func withdrawCryptocurrencyFunds(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowCommandHelp(c, "withdrawcryptofunds")
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchange, cur, address, addressTag, description string
|
||||
var amount, fee float64
|
||||
|
||||
if c.IsSet("exchange") {
|
||||
exchange = c.String("exchange")
|
||||
} else if c.Args().Get(0) != "" {
|
||||
exchange = c.Args().Get(0)
|
||||
}
|
||||
|
||||
if !validExchange(exchange) {
|
||||
return errInvalidExchange
|
||||
}
|
||||
|
||||
if c.IsSet("currency") {
|
||||
cur = c.String("currency")
|
||||
} else if c.Args().Get(1) != "" {
|
||||
cur = c.Args().Get(1)
|
||||
}
|
||||
|
||||
if c.IsSet("amount") {
|
||||
amount = c.Float64("amount")
|
||||
} else if c.Args().Get(2) != "" {
|
||||
amountStr, err := strconv.ParseFloat(c.Args().Get(2), 64)
|
||||
if err == nil {
|
||||
amount = amountStr
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("address") {
|
||||
address = c.String("address")
|
||||
} else if c.Args().Get(3) != "" {
|
||||
address = c.Args().Get(3)
|
||||
}
|
||||
|
||||
if c.IsSet("addresstag") {
|
||||
addressTag = c.String("addresstag")
|
||||
} else if c.Args().Get(4) != "" {
|
||||
addressTag = c.Args().Get(4)
|
||||
}
|
||||
|
||||
if c.IsSet("fee") {
|
||||
fee = c.Float64("fee")
|
||||
} else if c.Args().Get(5) != "" {
|
||||
feeStr, err := strconv.ParseFloat(c.Args().Get(5), 64)
|
||||
if err == nil {
|
||||
fee = feeStr
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("description") {
|
||||
description = c.String("description")
|
||||
} else if c.Args().Get(6) != "" {
|
||||
description = c.Args().Get(6)
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
|
||||
result, err := client.WithdrawCryptocurrencyFunds(context.Background(),
|
||||
&gctrpc.WithdrawCryptoRequest{
|
||||
Exchange: exchange,
|
||||
Currency: cur,
|
||||
Address: address,
|
||||
AddressTag: addressTag,
|
||||
Amount: amount,
|
||||
Fee: fee,
|
||||
Description: description,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
var withdrawFiatFundsCommand = cli.Command{
|
||||
Name: "withdrawfiatfunds",
|
||||
Usage: "withdraws fiat funds from the desired exchange",
|
||||
ArgsUsage: "<exchange> <fiat_currency>",
|
||||
ArgsUsage: "<exchange> <currency> <amount> <bankaccount id> <description>",
|
||||
Action: withdrawFiatFunds,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
@@ -2179,14 +2314,350 @@ var withdrawFiatFundsCommand = cli.Command{
|
||||
Usage: "the exchange to withdraw from",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "fiat_currency",
|
||||
Name: "currency",
|
||||
Usage: "the fiat currency to withdraw funds from",
|
||||
},
|
||||
cli.Float64Flag{
|
||||
Name: "amount",
|
||||
Usage: "amount of funds to withdraw",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "bankaccountid",
|
||||
Usage: "ID of bank account to use",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "description",
|
||||
Usage: "description to submit with request",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func withdrawFiatFunds(_ *cli.Context) error {
|
||||
return common.ErrNotYetImplemented
|
||||
func withdrawFiatFunds(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowCommandHelp(c, "withdrawfiatfunds")
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchange, cur, description, bankAccountID string
|
||||
var amount float64
|
||||
|
||||
if c.IsSet("exchange") {
|
||||
exchange = c.String("exchange")
|
||||
} else if c.Args().Get(0) != "" {
|
||||
exchange = c.Args().Get(0)
|
||||
}
|
||||
|
||||
if !validExchange(exchange) {
|
||||
return errInvalidExchange
|
||||
}
|
||||
|
||||
if c.IsSet("currency") {
|
||||
cur = c.String("currency")
|
||||
} else if c.Args().Get(1) != "" {
|
||||
cur = c.Args().Get(1)
|
||||
}
|
||||
|
||||
if c.IsSet("amount") {
|
||||
amount = c.Float64("amount")
|
||||
} else if c.Args().Get(2) != "" {
|
||||
amountStr, err := strconv.ParseFloat(c.Args().Get(2), 64)
|
||||
if err == nil {
|
||||
amount = amountStr
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("bankaccountid") {
|
||||
bankAccountID = c.String("bankaccountid")
|
||||
} else if c.Args().Get(3) != "" {
|
||||
bankAccountID = c.Args().Get(3)
|
||||
}
|
||||
|
||||
if c.IsSet("description") {
|
||||
description = c.String("description")
|
||||
} else if c.Args().Get(4) != "" {
|
||||
description = c.Args().Get(4)
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
result, err := client.WithdrawFiatFunds(context.Background(),
|
||||
&gctrpc.WithdrawFiatRequest{
|
||||
Exchange: exchange,
|
||||
Currency: cur,
|
||||
Amount: amount,
|
||||
Description: description,
|
||||
BankAccountId: bankAccountID,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
var withdrawalRequestCommand = cli.Command{
|
||||
Name: "withdrawalrequesthistory",
|
||||
Usage: "retrieve previous withdrawal request details",
|
||||
ArgsUsage: "<type> <args>",
|
||||
Subcommands: []cli.Command{
|
||||
{
|
||||
Name: "byid",
|
||||
Usage: "id",
|
||||
ArgsUsage: "<id>",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "<id>",
|
||||
},
|
||||
},
|
||||
Action: withdrawlRequestByID,
|
||||
},
|
||||
{
|
||||
Name: "byexchangeid",
|
||||
Usage: "exchange id",
|
||||
ArgsUsage: "<id>",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "<exchange>",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "id",
|
||||
Usage: "<id>",
|
||||
},
|
||||
},
|
||||
Action: withdrawlRequestByExchangeID,
|
||||
},
|
||||
{
|
||||
Name: "byexchange",
|
||||
Usage: "exchange limit",
|
||||
ArgsUsage: "<id>",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "<exchange>",
|
||||
},
|
||||
cli.Int64Flag{
|
||||
Name: "limit",
|
||||
Usage: "<limit>",
|
||||
},
|
||||
},
|
||||
Action: withdrawlRequestByExchangeID,
|
||||
},
|
||||
{
|
||||
Name: "bydate",
|
||||
Usage: "exchange start end limit",
|
||||
ArgsUsage: "<exchange> <start> <end> <limit>",
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "exchange",
|
||||
Usage: "<exchange>",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "start",
|
||||
Usage: "<start>",
|
||||
Value: time.Now().AddDate(0, -1, 0).Format(timeFormat),
|
||||
Destination: &startTime,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "end",
|
||||
Usage: "<end>",
|
||||
Value: time.Now().Format(timeFormat),
|
||||
Destination: &endTime,
|
||||
},
|
||||
cli.Int64Flag{
|
||||
Name: "limit",
|
||||
Usage: "<limit>",
|
||||
},
|
||||
},
|
||||
Action: withdrawlRequestByDate,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func withdrawlRequestByID(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowSubcommandHelp(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
var ID string
|
||||
if c.IsSet("id") {
|
||||
ID = c.String("id")
|
||||
} else {
|
||||
ID = c.Args().First()
|
||||
}
|
||||
|
||||
if ID == "" {
|
||||
return errors.New("an ID must be specified")
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
|
||||
result, err := client.WithdrawalEventByID(context.Background(),
|
||||
&gctrpc.WithdrawalEventByIDRequest{
|
||||
Id: ID,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawlRequestByExchangeID(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowSubcommandHelp(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchange string
|
||||
if c.IsSet("exchange") {
|
||||
exchange = c.String("exchange")
|
||||
} else {
|
||||
exchange = c.Args().First()
|
||||
}
|
||||
|
||||
var limit, limitStr int64
|
||||
var ID string
|
||||
var err error
|
||||
if c.Command.Name == "byexchangeid" {
|
||||
if c.IsSet("id") {
|
||||
ID = c.String("id")
|
||||
} else {
|
||||
ID = c.Args().Get(1)
|
||||
}
|
||||
if ID == "" {
|
||||
return errors.New("an ID must be specified")
|
||||
}
|
||||
limit = 1
|
||||
} else {
|
||||
if c.IsSet("limit") {
|
||||
limit = c.Int64("limit")
|
||||
} else if c.Args().Get(1) != "" {
|
||||
limitStr, err = strconv.ParseInt(c.Args().Get(1), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if limitStr > math.MaxInt32 {
|
||||
return fmt.Errorf("limit greater than max size: %v", math.MaxInt32)
|
||||
}
|
||||
limit = limitStr
|
||||
}
|
||||
}
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
|
||||
result, err := client.WithdrawalEventsByExchange(context.Background(),
|
||||
&gctrpc.WithdrawalEventsByExchangeRequest{
|
||||
Exchange: exchange,
|
||||
Id: ID,
|
||||
Limit: int32(limit),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawlRequestByDate(c *cli.Context) error {
|
||||
if c.NArg() == 0 && c.NumFlags() == 0 {
|
||||
cli.ShowSubcommandHelp(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
var exchange string
|
||||
var limit, limitStr int64
|
||||
var err error
|
||||
if c.IsSet("exchange") {
|
||||
exchange = c.String("exchange")
|
||||
} else {
|
||||
exchange = c.Args().First()
|
||||
}
|
||||
|
||||
if !c.IsSet("start") {
|
||||
if c.Args().Get(1) != "" {
|
||||
startTime = c.Args().Get(1)
|
||||
}
|
||||
}
|
||||
|
||||
if !c.IsSet("end") {
|
||||
if c.Args().Get(2) != "" {
|
||||
endTime = c.Args().Get(2)
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsSet("limit") {
|
||||
limit = c.Int64("limit")
|
||||
} else if c.Args().Get(3) != "" {
|
||||
limitStr, err = strconv.ParseInt(c.Args().Get(3), 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if limitStr > math.MaxInt32 {
|
||||
return fmt.Errorf("limit greater than max size: %v", math.MaxInt32)
|
||||
}
|
||||
limit = limitStr
|
||||
}
|
||||
|
||||
s, err := time.Parse(timeFormat, startTime)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid time format for start: %v", err)
|
||||
}
|
||||
|
||||
e, err := time.Parse(timeFormat, endTime)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid time format for end: %v", err)
|
||||
}
|
||||
|
||||
if e.Before(s) {
|
||||
return errors.New("start cannot be after before")
|
||||
}
|
||||
|
||||
_, offset := time.Now().Zone()
|
||||
loc := time.FixedZone("", -offset)
|
||||
|
||||
conn, err := setupClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := gctrpc.NewGoCryptoTraderClient(conn)
|
||||
result, err := client.WithdrawalEventsByDate(context.Background(),
|
||||
&gctrpc.WithdrawalEventsByDateRequest{
|
||||
Exchange: exchange,
|
||||
Start: s.In(loc).Format(timeFormat),
|
||||
End: e.In(loc).Format(timeFormat),
|
||||
Limit: int32(limit),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jsonOutput(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
var getLoggerDetailsCommand = cli.Command{
|
||||
@@ -2953,11 +3424,6 @@ func clearScreen() error {
|
||||
}
|
||||
}
|
||||
|
||||
const timeFormat = "2006-01-02 15:04:05"
|
||||
|
||||
var startTime, endTime, order string
|
||||
var limit int
|
||||
|
||||
var getAuditEventCommand = cli.Command{
|
||||
Name: "getauditevent",
|
||||
Usage: "gets audit events matching query parameters",
|
||||
|
||||
@@ -124,6 +124,7 @@ func main() {
|
||||
getCryptocurrencyDepositAddressCommand,
|
||||
withdrawCryptocurrencyFundsCommand,
|
||||
withdrawFiatFundsCommand,
|
||||
withdrawalRequestCommand,
|
||||
getLoggerDetailsCommand,
|
||||
setLoggerDetailsCommand,
|
||||
getExchangePairsCommand,
|
||||
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
gctscript "github.com/thrasher-corp/gocryptotrader/gctscript/vm"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
)
|
||||
|
||||
// GetCurrencyConfig returns currency configurations
|
||||
@@ -33,28 +34,31 @@ func (c *Config) GetCurrencyConfig() CurrencyConfig {
|
||||
|
||||
// GetExchangeBankAccounts returns banking details associated with an exchange
|
||||
// for depositing funds
|
||||
func (c *Config) GetExchangeBankAccounts(exchangeName, depositingCurrency string) (BankAccount, error) {
|
||||
func (c *Config) GetExchangeBankAccounts(exchangeName, id, depositingCurrency string) (*banking.Account, error) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
for x := range c.Exchanges {
|
||||
if strings.EqualFold(c.Exchanges[x].Name, exchangeName) {
|
||||
for y := range c.Exchanges[x].BankAccounts {
|
||||
if strings.Contains(c.Exchanges[x].BankAccounts[y].SupportedCurrencies,
|
||||
depositingCurrency) {
|
||||
return c.Exchanges[x].BankAccounts[y], nil
|
||||
if strings.EqualFold(c.Exchanges[x].BankAccounts[y].ID, id) {
|
||||
if common.StringDataCompareInsensitive(
|
||||
strings.Split(c.Exchanges[x].BankAccounts[y].SupportedCurrencies, ","),
|
||||
depositingCurrency) {
|
||||
return &c.Exchanges[x].BankAccounts[y], nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return BankAccount{}, fmt.Errorf("exchange %s bank details not found for %s",
|
||||
return nil, fmt.Errorf("exchange %s bank details not found for %s",
|
||||
exchangeName,
|
||||
depositingCurrency)
|
||||
}
|
||||
|
||||
// UpdateExchangeBankAccounts updates the configuration for the associated
|
||||
// exchange bank
|
||||
func (c *Config) UpdateExchangeBankAccounts(exchangeName string, bankCfg []BankAccount) error {
|
||||
func (c *Config) UpdateExchangeBankAccounts(exchangeName string, bankCfg []banking.Account) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
@@ -70,7 +74,7 @@ func (c *Config) UpdateExchangeBankAccounts(exchangeName string, bankCfg []BankA
|
||||
|
||||
// GetClientBankAccounts returns banking details used for a given exchange
|
||||
// and currency
|
||||
func (c *Config) GetClientBankAccounts(exchangeName, targetCurrency string) (BankAccount, error) {
|
||||
func (c *Config) GetClientBankAccounts(exchangeName, targetCurrency string) (*banking.Account, error) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
@@ -78,16 +82,16 @@ func (c *Config) GetClientBankAccounts(exchangeName, targetCurrency string) (Ban
|
||||
if (strings.Contains(c.BankAccounts[x].SupportedExchanges, exchangeName) ||
|
||||
c.BankAccounts[x].SupportedExchanges == "ALL") &&
|
||||
strings.Contains(c.BankAccounts[x].SupportedCurrencies, targetCurrency) {
|
||||
return c.BankAccounts[x], nil
|
||||
return &c.BankAccounts[x], nil
|
||||
}
|
||||
}
|
||||
return BankAccount{}, fmt.Errorf("client banking details not found for %s and currency %s",
|
||||
return nil, fmt.Errorf("client banking details not found for %s and currency %s",
|
||||
exchangeName,
|
||||
targetCurrency)
|
||||
}
|
||||
|
||||
// UpdateClientBankAccounts updates the configuration for a bank
|
||||
func (c *Config) UpdateClientBankAccounts(bankCfg *BankAccount) error {
|
||||
func (c *Config) UpdateClientBankAccounts(bankCfg *banking.Account) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
@@ -108,7 +112,7 @@ func (c *Config) CheckClientBankAccounts() {
|
||||
|
||||
if len(c.BankAccounts) == 0 {
|
||||
c.BankAccounts = append(c.BankAccounts,
|
||||
BankAccount{
|
||||
banking.Account{
|
||||
ID: "test-bank-01",
|
||||
BankName: "Test Bank",
|
||||
BankAddress: "42 Bank Street",
|
||||
@@ -137,19 +141,6 @@ func (c *Config) CheckClientBankAccounts() {
|
||||
}
|
||||
}
|
||||
|
||||
// GetBankAccountByID Returns a bank account based on its ID
|
||||
func (c *Config) GetBankAccountByID(id string) (*BankAccount, error) {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
for x := range c.BankAccounts {
|
||||
if strings.EqualFold(c.BankAccounts[x].ID, id) {
|
||||
return &c.BankAccounts[x], nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf(ErrBankAccountNotFound, id)
|
||||
}
|
||||
|
||||
// PurgeExchangeAPICredentials purges the stored API credentials
|
||||
func (c *Config) PurgeExchangeAPICredentials() {
|
||||
m.Lock()
|
||||
@@ -952,16 +943,6 @@ func (c *Config) CheckExchangeConfigValues() error {
|
||||
|
||||
c.CheckExchangeAssetsConsistency(c.Exchanges[i].Name)
|
||||
|
||||
for x := range c.Exchanges[i].BankAccounts {
|
||||
if !c.Exchanges[i].BankAccounts[x].Enabled {
|
||||
continue
|
||||
}
|
||||
err := c.Exchanges[i].BankAccounts[x].Validate()
|
||||
if err != nil {
|
||||
c.Exchanges[i].BankAccounts[x].Enabled = false
|
||||
log.Warn(log.ConfigMgr, err.Error())
|
||||
}
|
||||
}
|
||||
exchanges++
|
||||
}
|
||||
}
|
||||
@@ -971,6 +952,20 @@ func (c *Config) CheckExchangeConfigValues() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// CheckBankAccountConfig checks all bank accounts to see if they are valid
|
||||
func (c *Config) CheckBankAccountConfig() {
|
||||
for x := range c.BankAccounts {
|
||||
if c.BankAccounts[x].Enabled {
|
||||
err := c.BankAccounts[x].Validate()
|
||||
if err != nil {
|
||||
c.BankAccounts[x].Enabled = false
|
||||
log.Warn(log.ConfigMgr, err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
banking.Accounts = c.BankAccounts
|
||||
}
|
||||
|
||||
// CheckCurrencyConfigValues checks to see if the currency config values are correct or not
|
||||
func (c *Config) CheckCurrencyConfigValues() error {
|
||||
fxProviders := forexprovider.GetSupportedForexProviders()
|
||||
@@ -1626,6 +1621,7 @@ func (c *Config) CheckConfig() error {
|
||||
c.CheckConnectionMonitorConfig()
|
||||
c.CheckCommunicationsConfig()
|
||||
c.CheckClientBankAccounts()
|
||||
c.CheckBankAccountConfig()
|
||||
c.CheckRemoteControlConfig()
|
||||
|
||||
err = c.CheckCurrencyConfigValues()
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
gctscript "github.com/thrasher-corp/gocryptotrader/gctscript/vm"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/ntpclient"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -37,11 +38,11 @@ func TestGetExchangeBankAccounts(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Error("GetExchangeBankAccounts LoadConfig error", err)
|
||||
}
|
||||
_, err = cfg.GetExchangeBankAccounts("Bitfinex", "USD")
|
||||
_, err = cfg.GetExchangeBankAccounts("Bitfinex", "", "USD")
|
||||
if err != nil {
|
||||
t.Error("GetExchangeBankAccounts error", err)
|
||||
}
|
||||
_, err = cfg.GetExchangeBankAccounts("Not an exchange", "Not a currency")
|
||||
_, err = cfg.GetExchangeBankAccounts("Not an exchange", "", "Not a currency")
|
||||
if err == nil {
|
||||
t.Error("GetExchangeBankAccounts, no error returned for invalid exchange")
|
||||
}
|
||||
@@ -54,7 +55,7 @@ func TestUpdateExchangeBankAccounts(t *testing.T) {
|
||||
t.Error("UpdateExchangeBankAccounts LoadConfig error", err)
|
||||
}
|
||||
|
||||
b := []BankAccount{{Enabled: false}}
|
||||
b := []banking.Account{{Enabled: false}}
|
||||
err = cfg.UpdateExchangeBankAccounts("Bitfinex", b)
|
||||
if err != nil {
|
||||
t.Error("UpdateExchangeBankAccounts error", err)
|
||||
@@ -77,39 +78,19 @@ func TestUpdateExchangeBankAccounts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetClientBankAccounts(t *testing.T) {
|
||||
cfg := GetConfig()
|
||||
err := cfg.LoadConfig(TestFile, true)
|
||||
if err != nil {
|
||||
t.Error("GetClientBankAccounts LoadConfig error", err)
|
||||
}
|
||||
_, err = cfg.GetClientBankAccounts("Kraken", "USD")
|
||||
if err != nil {
|
||||
t.Error("GetClientBankAccounts error", err)
|
||||
}
|
||||
_, err = cfg.GetClientBankAccounts("Bla", "USD")
|
||||
if err == nil {
|
||||
t.Error("GetClientBankAccounts error")
|
||||
}
|
||||
_, err = cfg.GetClientBankAccounts("Kraken", "JPY")
|
||||
if err == nil {
|
||||
t.Error("GetClientBankAccounts Expected error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateClientBankAccounts(t *testing.T) {
|
||||
cfg := GetConfig()
|
||||
err := cfg.LoadConfig(TestFile, true)
|
||||
if err != nil {
|
||||
t.Error("UpdateClientBankAccounts LoadConfig error", err)
|
||||
}
|
||||
b := BankAccount{Enabled: false, BankName: "test", AccountNumber: "0234"}
|
||||
b := banking.Account{Enabled: false, BankName: "test", AccountNumber: "0234"}
|
||||
err = cfg.UpdateClientBankAccounts(&b)
|
||||
if err != nil {
|
||||
t.Error("UpdateClientBankAccounts error", err)
|
||||
}
|
||||
|
||||
err = cfg.UpdateClientBankAccounts(&BankAccount{})
|
||||
err = cfg.UpdateClientBankAccounts(&banking.Account{})
|
||||
if err == nil {
|
||||
t.Error("UpdateClientBankAccounts error")
|
||||
}
|
||||
@@ -141,7 +122,7 @@ func TestCheckClientBankAccounts(t *testing.T) {
|
||||
}
|
||||
|
||||
cfg.BankAccounts = nil
|
||||
cfg.BankAccounts = []BankAccount{
|
||||
cfg.BankAccounts = []banking.Account{
|
||||
{
|
||||
Enabled: true,
|
||||
},
|
||||
@@ -152,7 +133,7 @@ func TestCheckClientBankAccounts(t *testing.T) {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
b := BankAccount{
|
||||
b := banking.Account{
|
||||
Enabled: true,
|
||||
BankName: "Commonwealth Bank of Awesome",
|
||||
BankAddress: "123 Fake Street",
|
||||
@@ -163,7 +144,7 @@ func TestCheckClientBankAccounts(t *testing.T) {
|
||||
AccountNumber: "1231006505",
|
||||
SupportedCurrencies: "USD",
|
||||
}
|
||||
cfg.BankAccounts = []BankAccount{b}
|
||||
cfg.BankAccounts = []banking.Account{b}
|
||||
cfg.CheckClientBankAccounts()
|
||||
if cfg.BankAccounts[0].Enabled ||
|
||||
cfg.BankAccounts[0].SupportedExchanges != "ALL" {
|
||||
@@ -174,7 +155,7 @@ func TestCheckClientBankAccounts(t *testing.T) {
|
||||
// transfers)
|
||||
b.SupportedCurrencies = "AUD"
|
||||
b.SWIFTCode = "BACXSI22"
|
||||
cfg.BankAccounts = []BankAccount{b}
|
||||
cfg.BankAccounts = []banking.Account{b}
|
||||
cfg.CheckClientBankAccounts()
|
||||
if cfg.BankAccounts[0].Enabled {
|
||||
t.Error("unexpected result")
|
||||
@@ -182,7 +163,7 @@ func TestCheckClientBankAccounts(t *testing.T) {
|
||||
|
||||
// Valid AU bank
|
||||
b.BSBNumber = "061337"
|
||||
cfg.BankAccounts = []BankAccount{b}
|
||||
cfg.BankAccounts = []banking.Account{b}
|
||||
cfg.CheckClientBankAccounts()
|
||||
if !cfg.BankAccounts[0].Enabled {
|
||||
t.Error("unexpected result")
|
||||
@@ -192,37 +173,13 @@ func TestCheckClientBankAccounts(t *testing.T) {
|
||||
b.Enabled = true
|
||||
b.IBAN = "SI56290000170073837"
|
||||
b.SWIFTCode = "BACXSI22"
|
||||
cfg.BankAccounts = []BankAccount{b}
|
||||
cfg.BankAccounts = []banking.Account{b}
|
||||
cfg.CheckClientBankAccounts()
|
||||
if !cfg.BankAccounts[0].Enabled {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetBankAccountByID(t *testing.T) {
|
||||
cfg := GetConfig()
|
||||
err := cfg.LoadConfig(TestFile, true)
|
||||
if err != nil {
|
||||
t.Error("CheckClientBankAccounts LoadConfig error", err)
|
||||
}
|
||||
|
||||
cfg.BankAccounts = nil
|
||||
cfg.CheckClientBankAccounts()
|
||||
if len(cfg.BankAccounts) == 0 {
|
||||
t.Error("CheckClientBankAccounts error:", err)
|
||||
}
|
||||
|
||||
_, err = cfg.GetBankAccountByID("test-bank-01")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
_, err = cfg.GetBankAccountByID("invalid-test-bank-01")
|
||||
if err == nil {
|
||||
t.Error("error expected for invalid account received nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPurgeExchangeCredentials(t *testing.T) {
|
||||
t.Parallel()
|
||||
var c Config
|
||||
@@ -1462,25 +1419,6 @@ func TestCheckExchangeConfigValues(t *testing.T) {
|
||||
!cfg.Exchanges[0].API.AuthenticatedWebsocketSupport {
|
||||
t.Error("Expected AuthenticatedAPISupport and AuthenticatedWebsocketAPISupport to be false from invalid API keys")
|
||||
}
|
||||
|
||||
// Test exchage bank accounts
|
||||
b := BankAccount{
|
||||
Enabled: true,
|
||||
BankName: "Commonwealth Bank of Awesome",
|
||||
BankAddress: "123 Fake Street",
|
||||
BankPostalCode: "1337",
|
||||
BankPostalCity: "Satoshiville",
|
||||
BankCountry: "Genesis",
|
||||
AccountName: "Satoshi Nakamoto",
|
||||
AccountNumber: "1231006505",
|
||||
SupportedCurrencies: "USD",
|
||||
}
|
||||
cfg.Exchanges[0].BankAccounts = []BankAccount{b}
|
||||
cfg.CheckExchangeConfigValues()
|
||||
if cfg.Exchanges[0].BankAccounts[0].Enabled {
|
||||
t.Error("unexpected result")
|
||||
}
|
||||
|
||||
// Test empty exchange name for an enabled exchange
|
||||
cfg.Exchanges[0].Enabled = true
|
||||
cfg.Exchanges[0].Name = ""
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -12,6 +10,7 @@ import (
|
||||
gctscript "github.com/thrasher-corp/gocryptotrader/gctscript/vm"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
)
|
||||
|
||||
// Constants declared here are filename strings and test strings
|
||||
@@ -49,7 +48,6 @@ const (
|
||||
ErrFailureOpeningConfig = "fatal error opening %s file. Error: %s"
|
||||
ErrCheckingConfigValues = "fatal error checking config values. Error: %s"
|
||||
ErrSavingConfigBytesMismatch = "config file %q bytes comparison doesn't match, read %s expected %s"
|
||||
ErrBankAccountNotFound = "bank account ID: %v not found"
|
||||
WarningWebserverCredentialValuesEmpty = "webserver support disabled due to empty Username/Password values"
|
||||
WarningWebserverListenAddressInvalid = "webserver support disabled due to invalid listen address"
|
||||
WarningExchangeAuthAPIDefaultOrEmptyValues = "exchange %s authenticated API support disabled due to default/empty APIKey/Secret/ClientID values"
|
||||
@@ -93,7 +91,7 @@ type Config struct {
|
||||
RemoteControl RemoteControlConfig `json:"remoteControl"`
|
||||
Portfolio portfolio.Base `json:"portfolioAddresses"`
|
||||
Exchanges []ExchangeConfig `json:"exchanges"`
|
||||
BankAccounts []BankAccount `json:"bankAccounts"`
|
||||
BankAccounts []banking.Account `json:"bankAccounts"`
|
||||
|
||||
// Deprecated config settings, will be removed at a future date
|
||||
Webserver *WebserverConfig `json:"webserver,omitempty"`
|
||||
@@ -129,7 +127,7 @@ type ExchangeConfig struct {
|
||||
CurrencyPairs *currency.PairsManager `json:"currencyPairs"`
|
||||
API APIConfig `json:"api"`
|
||||
Features *FeaturesConfig `json:"features"`
|
||||
BankAccounts []BankAccount `json:"bankAccounts,omitempty"`
|
||||
BankAccounts []banking.Account `json:"bankAccounts,omitempty"`
|
||||
|
||||
// Deprecated settings which will be removed in a future update
|
||||
AvailablePairs *currency.Pairs `json:"availablePairs,omitempty"`
|
||||
@@ -224,63 +222,6 @@ type CurrencyPairFormatConfig struct {
|
||||
Index string `json:"index,omitempty"`
|
||||
}
|
||||
|
||||
// BankAccount holds differing bank account details by supported funding
|
||||
// currency
|
||||
type BankAccount struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
ID string `json:"id,omitempty"`
|
||||
BankName string `json:"bankName"`
|
||||
BankAddress string `json:"bankAddress"`
|
||||
BankPostalCode string `json:"bankPostalCode"`
|
||||
BankPostalCity string `json:"bankPostalCity"`
|
||||
BankCountry string `json:"bankCountry"`
|
||||
AccountName string `json:"accountName"`
|
||||
AccountNumber string `json:"accountNumber"`
|
||||
SWIFTCode string `json:"swiftCode"`
|
||||
IBAN string `json:"iban"`
|
||||
BSBNumber string `json:"bsbNumber,omitempty"`
|
||||
SupportedCurrencies string `json:"supportedCurrencies"`
|
||||
SupportedExchanges string `json:"supportedExchanges,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates bank account settings
|
||||
func (b *BankAccount) Validate() error {
|
||||
if b.BankName == "" ||
|
||||
b.BankAddress == "" ||
|
||||
b.BankPostalCode == "" ||
|
||||
b.BankPostalCity == "" ||
|
||||
b.BankCountry == "" ||
|
||||
b.AccountName == "" ||
|
||||
b.SupportedCurrencies == "" {
|
||||
return fmt.Errorf(
|
||||
"banking details for %s is enabled but variables not set correctly",
|
||||
b.BankName)
|
||||
}
|
||||
|
||||
if b.SupportedExchanges == "" {
|
||||
b.SupportedExchanges = "ALL"
|
||||
}
|
||||
|
||||
if strings.Contains(strings.ToUpper(
|
||||
b.SupportedCurrencies),
|
||||
currency.AUD.String()) {
|
||||
if b.BSBNumber == "" ||
|
||||
b.SWIFTCode == "" {
|
||||
return fmt.Errorf(
|
||||
"banking details for %s is enabled but BSB/SWIFT values not set",
|
||||
b.BankName)
|
||||
}
|
||||
} else {
|
||||
// Either IBAN or SWIFT code is OK
|
||||
if b.IBAN == "" && b.SWIFTCode == "" {
|
||||
return fmt.Errorf(
|
||||
"banking details for %s is enabled but SWIFT/IBAN values not set",
|
||||
b.BankName)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// BankTransaction defines a related banking transaction
|
||||
type BankTransaction struct {
|
||||
ReferenceNumber string `json:"referenceNumber"`
|
||||
|
||||
@@ -2410,6 +2410,7 @@
|
||||
"bankAccounts": [
|
||||
{
|
||||
"enabled": false,
|
||||
"id": "test-account-01",
|
||||
"bankName": "test",
|
||||
"bankAddress": "test",
|
||||
"bankPostalCode": "",
|
||||
|
||||
@@ -37,6 +37,9 @@ var (
|
||||
// ErrNoDatabaseProvided error to display when no database is provided
|
||||
ErrNoDatabaseProvided = errors.New("no database provided")
|
||||
|
||||
// ErrDatabaseSupportDisabled error to display when no database is provided
|
||||
ErrDatabaseSupportDisabled = errors.New("database support is disabled")
|
||||
|
||||
// SupportedDrivers slice of supported database driver types
|
||||
SupportedDrivers = []string{DBSQLite, DBSQLite3, DBPostgreSQL}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ CREATE TABLE "audit_event" (
|
||||
identifier text not null,
|
||||
message text not null,
|
||||
created_at timestamp not null default CURRENT_TIMESTAMP
|
||||
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE EXTENSION IF NOT EXISTS pgcrypto;
|
||||
CREATE TABLE IF NOT EXISTS withdrawal_history
|
||||
(
|
||||
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
exchange text NOT NULL,
|
||||
exchange_id text NOT NULL,
|
||||
status varchar(255) NOT NULL,
|
||||
currency text NOT NULL,
|
||||
amount DOUBLE PRECISION NOT NULL,
|
||||
description text NULL,
|
||||
withdraw_type integer NOT NULL,
|
||||
created_at TIMESTAMP NOT NULL DEFAULT (now() at time zone 'utc'),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT (now() at time zone 'utc')
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_history;
|
||||
@@ -0,0 +1,19 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE TABLE IF NOT EXISTS "withdrawal_history"
|
||||
(
|
||||
id text PRIMARY KEY NOT NULL,
|
||||
exchange text NOT NULL,
|
||||
exchange_id text NOT NULL,
|
||||
status text NOT NULL,
|
||||
currency text NOT NULL,
|
||||
amount real NOT NULL,
|
||||
description text NULL,
|
||||
withdraw_type integer NOT NULL,
|
||||
created_at timestamp not null default CURRENT_TIMESTAMP,
|
||||
updated_at timestamp not null default CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_history;
|
||||
@@ -0,0 +1,18 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE TABLE IF NOT EXISTS withdrawal_fiat
|
||||
(
|
||||
id bigserial PRIMARY KEY NOT NULL,
|
||||
withdrawal_fiat_id uuid REFERENCES withdrawal_history(id) ON DELETE RESTRICT,
|
||||
bank_name text not null,
|
||||
bank_address text not null,
|
||||
bank_account_name text not null,
|
||||
bank_account_number text not null,
|
||||
bsb text not null DEFAULT '',
|
||||
swift_code text not null DEFAULT '',
|
||||
iban text not null DEFAULT '',
|
||||
bank_code DOUBLE PRECISION not null
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_fiat;
|
||||
@@ -0,0 +1,19 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE TABLE IF NOT EXISTS "withdrawal_fiat"
|
||||
(
|
||||
id integer not null primary key,
|
||||
bank_name text not null,
|
||||
bank_address text not null,
|
||||
bank_account_name text not null,
|
||||
bank_account_number text not null,
|
||||
bsb text not null DEFAULT '',
|
||||
swift_code text not null DEFAULT '',
|
||||
iban text not null DEFAULT '',
|
||||
bank_code real not null,
|
||||
withdrawal_history_id text NOT NULL,
|
||||
FOREIGN KEY(withdrawal_history_id) REFERENCES withdrawal_history(id) ON DELETE RESTRICT
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_fiat;
|
||||
@@ -0,0 +1,13 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE TABLE IF NOT EXISTS withdrawal_crypto
|
||||
(
|
||||
id bigserial PRIMARY KEY NOT NULL,
|
||||
withdrawal_crypto_id uuid REFERENCES withdrawal_history(id) ON DELETE RESTRICT,
|
||||
address text NOT NULL,
|
||||
address_tag text NULL,
|
||||
fee DOUBLE PRECISION NOT NULL
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_crypto;
|
||||
@@ -0,0 +1,14 @@
|
||||
-- +goose Up
|
||||
-- SQL in this section is executed when the migration is applied.
|
||||
CREATE TABLE IF NOT EXISTS withdrawal_crypto
|
||||
(
|
||||
id integer not null primary key,
|
||||
address text NOT NULL,
|
||||
address_tag text NULL,
|
||||
fee real NOT NULL,
|
||||
withdrawal_history_id text NOT NULL,
|
||||
FOREIGN KEY(withdrawal_history_id) REFERENCES withdrawal_history(id) ON DELETE RESTRICT
|
||||
);
|
||||
-- +goose Down
|
||||
-- SQL in this section is executed when the migration is rolled back.
|
||||
DROP TABLE IF EXISTS withdrawal_crypto;
|
||||
@@ -14,56 +14,67 @@ import "testing"
|
||||
func TestParent(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEvents)
|
||||
t.Run("Scripts", testScripts)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistories)
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsDelete)
|
||||
t.Run("Scripts", testScriptsDelete)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesDelete)
|
||||
}
|
||||
|
||||
func TestQueryDeleteAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsQueryDeleteAll)
|
||||
t.Run("Scripts", testScriptsQueryDeleteAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesQueryDeleteAll)
|
||||
}
|
||||
|
||||
func TestSliceDeleteAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSliceDeleteAll)
|
||||
t.Run("Scripts", testScriptsSliceDeleteAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSliceDeleteAll)
|
||||
}
|
||||
|
||||
func TestExists(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsExists)
|
||||
t.Run("Scripts", testScriptsExists)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesExists)
|
||||
}
|
||||
|
||||
func TestFind(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsFind)
|
||||
t.Run("Scripts", testScriptsFind)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesFind)
|
||||
}
|
||||
|
||||
func TestBind(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsBind)
|
||||
t.Run("Scripts", testScriptsBind)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesBind)
|
||||
}
|
||||
|
||||
func TestOne(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsOne)
|
||||
t.Run("Scripts", testScriptsOne)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesOne)
|
||||
}
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsAll)
|
||||
t.Run("Scripts", testScriptsAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesAll)
|
||||
}
|
||||
|
||||
func TestCount(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsCount)
|
||||
t.Run("Scripts", testScriptsCount)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesCount)
|
||||
}
|
||||
|
||||
func TestHooks(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsHooks)
|
||||
t.Run("Scripts", testScriptsHooks)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesHooks)
|
||||
}
|
||||
|
||||
func TestInsert(t *testing.T) {
|
||||
@@ -71,6 +82,8 @@ func TestInsert(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsInsertWhitelist)
|
||||
t.Run("Scripts", testScriptsInsert)
|
||||
t.Run("Scripts", testScriptsInsertWhitelist)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesInsert)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesInsertWhitelist)
|
||||
}
|
||||
|
||||
// TestToOne tests cannot be run in parallel
|
||||
@@ -116,24 +129,29 @@ func TestToManyRemove(t *testing.T) {}
|
||||
func TestReload(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsReload)
|
||||
t.Run("Scripts", testScriptsReload)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesReload)
|
||||
}
|
||||
|
||||
func TestReloadAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsReloadAll)
|
||||
t.Run("Scripts", testScriptsReloadAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesReloadAll)
|
||||
}
|
||||
|
||||
func TestSelect(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSelect)
|
||||
t.Run("Scripts", testScriptsSelect)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSelect)
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsUpdate)
|
||||
t.Run("Scripts", testScriptsUpdate)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesUpdate)
|
||||
}
|
||||
|
||||
func TestSliceUpdateAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSliceUpdateAll)
|
||||
t.Run("Scripts", testScriptsSliceUpdateAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSliceUpdateAll)
|
||||
}
|
||||
|
||||
@@ -4,11 +4,17 @@
|
||||
package postgres
|
||||
|
||||
var TableNames = struct {
|
||||
AuditEvent string
|
||||
Script string
|
||||
ScriptExecution string
|
||||
AuditEvent string
|
||||
Script string
|
||||
ScriptExecution string
|
||||
WithdrawalCrypto string
|
||||
WithdrawalFiat string
|
||||
WithdrawalHistory string
|
||||
}{
|
||||
AuditEvent: "audit_event",
|
||||
Script: "script",
|
||||
ScriptExecution: "script_execution",
|
||||
AuditEvent: "audit_event",
|
||||
Script: "script",
|
||||
ScriptExecution: "script_execution",
|
||||
WithdrawalCrypto: "withdrawal_crypto",
|
||||
WithdrawalFiat: "withdrawal_fiat",
|
||||
WithdrawalHistory: "withdrawal_history",
|
||||
}
|
||||
|
||||
@@ -8,4 +8,5 @@ import "testing"
|
||||
func TestUpsert(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsUpsert)
|
||||
t.Run("Scripts", testScriptsUpsert)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesUpsert)
|
||||
}
|
||||
|
||||
1096
database/models/postgres/withdrawal_crypto.go
Normal file
1096
database/models/postgres/withdrawal_crypto.go
Normal file
File diff suppressed because it is too large
Load Diff
892
database/models/postgres/withdrawal_crypto_test.go
Normal file
892
database/models/postgres/withdrawal_crypto_test.go
Normal file
@@ -0,0 +1,892 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/randomize"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testWithdrawalCryptos(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := WithdrawalCryptos()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := WithdrawalCryptos().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := WithdrawalCryptoExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if WithdrawalCrypto exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected WithdrawalCryptoExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
withdrawalCryptoFound, err := FindWithdrawalCrypto(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if withdrawalCryptoFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = WithdrawalCryptos().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := WithdrawalCryptos().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
withdrawalCryptoOne := &WithdrawalCrypto{}
|
||||
withdrawalCryptoTwo := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoOne, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoTwo, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalCryptoOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalCryptoTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalCryptos().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
withdrawalCryptoOne := &WithdrawalCrypto{}
|
||||
withdrawalCryptoTwo := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoOne, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoTwo, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalCryptoOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalCryptoTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &WithdrawalCrypto{}
|
||||
o := &WithdrawalCrypto{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto object: %s", err)
|
||||
}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeInsertHook, withdrawalCryptoBeforeInsertHook)
|
||||
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeInsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterInsertHook, withdrawalCryptoAfterInsertHook)
|
||||
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterInsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterSelectHook, withdrawalCryptoAfterSelectHook)
|
||||
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterSelectHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeUpdateHook, withdrawalCryptoBeforeUpdateHook)
|
||||
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeUpdateHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterUpdateHook, withdrawalCryptoAfterUpdateHook)
|
||||
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterUpdateHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeDeleteHook, withdrawalCryptoBeforeDeleteHook)
|
||||
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeDeleteHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterDeleteHook, withdrawalCryptoAfterDeleteHook)
|
||||
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterDeleteHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeUpsertHook, withdrawalCryptoBeforeUpsertHook)
|
||||
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeUpsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterUpsertHook, withdrawalCryptoAfterUpsertHook)
|
||||
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterUpsertHooks = []WithdrawalCryptoHook{}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(withdrawalCryptoColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptoToOneWithdrawalHistoryUsingWithdrawalCrypto(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local WithdrawalCrypto
|
||||
var foreign WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
queries.Assign(&local.WithdrawalCryptoID, foreign.ID)
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.WithdrawalCrypto().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !queries.Equal(check.ID, foreign.ID) {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{&local}
|
||||
if err = local.L.LoadWithdrawalCrypto(ctx, tx, false, (*[]*WithdrawalCrypto)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalCrypto == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.WithdrawalCrypto = nil
|
||||
if err = local.L.LoadWithdrawalCrypto(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalCrypto == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptoToOneSetOpWithdrawalHistoryUsingWithdrawalCrypto(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalCrypto
|
||||
var b, c WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalCryptoDBTypes, false, strmangle.SetComplement(withdrawalCryptoPrimaryKeyColumns, withdrawalCryptoColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*WithdrawalHistory{&b, &c} {
|
||||
err = a.SetWithdrawalCrypto(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.WithdrawalCrypto != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.WithdrawalCryptoWithdrawalCryptos[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if !queries.Equal(a.WithdrawalCryptoID, x.ID) {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalCryptoID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.WithdrawalCryptoID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.WithdrawalCryptoID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if !queries.Equal(a.WithdrawalCryptoID, x.ID) {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalCryptoID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptoToOneRemoveOpWithdrawalHistoryUsingWithdrawalCrypto(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalCrypto
|
||||
var b WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalCryptoDBTypes, false, strmangle.SetComplement(withdrawalCryptoPrimaryKeyColumns, withdrawalCryptoColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.SetWithdrawalCrypto(ctx, tx, true, &b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.RemoveWithdrawalCrypto(ctx, tx, &b); err != nil {
|
||||
t.Error("failed to remove relationship")
|
||||
}
|
||||
|
||||
count, err := a.WithdrawalCrypto().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 0 {
|
||||
t.Error("want no relationships remaining")
|
||||
}
|
||||
|
||||
if a.R.WithdrawalCrypto != nil {
|
||||
t.Error("R struct entry should be nil")
|
||||
}
|
||||
|
||||
if !queries.IsValuerNil(a.WithdrawalCryptoID) {
|
||||
t.Error("foreign key value should be nil")
|
||||
}
|
||||
|
||||
if len(b.R.WithdrawalCryptoWithdrawalCryptos) != 0 {
|
||||
t.Error("failed to remove a from b's relationships")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalCryptos().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
withdrawalCryptoDBTypes = map[string]string{`ID`: `bigint`, `WithdrawalCryptoID`: `uuid`, `Address`: `text`, `AddressTag`: `text`, `Fee`: `double precision`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testWithdrawalCryptosUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(withdrawalCryptoAllColumns) == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalCryptoAllColumns) == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(withdrawalCryptoAllColumns, withdrawalCryptoPrimaryKeyColumns) {
|
||||
fields = withdrawalCryptoAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
withdrawalCryptoAllColumns,
|
||||
withdrawalCryptoPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosUpsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalCryptoAllColumns) == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
// Attempt the INSERT side of an UPSERT
|
||||
o := WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, &o, withdrawalCryptoDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert WithdrawalCrypto: %s", err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
// Attempt the UPDATE side of an UPSERT
|
||||
if err = randomize.Struct(seed, &o, withdrawalCryptoDBTypes, false, withdrawalCryptoPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert WithdrawalCrypto: %s", err)
|
||||
}
|
||||
|
||||
count, err = WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
1106
database/models/postgres/withdrawal_fiat.go
Normal file
1106
database/models/postgres/withdrawal_fiat.go
Normal file
File diff suppressed because it is too large
Load Diff
892
database/models/postgres/withdrawal_fiat_test.go
Normal file
892
database/models/postgres/withdrawal_fiat_test.go
Normal file
@@ -0,0 +1,892 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/randomize"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testWithdrawalFiats(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := WithdrawalFiats()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := WithdrawalFiats().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := WithdrawalFiatExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if WithdrawalFiat exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected WithdrawalFiatExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
withdrawalFiatFound, err := FindWithdrawalFiat(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if withdrawalFiatFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = WithdrawalFiats().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := WithdrawalFiats().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
withdrawalFiatOne := &WithdrawalFiat{}
|
||||
withdrawalFiatTwo := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, withdrawalFiatOne, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalFiatTwo, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalFiatOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalFiatTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalFiats().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
withdrawalFiatOne := &WithdrawalFiat{}
|
||||
withdrawalFiatTwo := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, withdrawalFiatOne, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalFiatTwo, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalFiatOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalFiatTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &WithdrawalFiat{}
|
||||
o := &WithdrawalFiat{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat object: %s", err)
|
||||
}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeInsertHook, withdrawalFiatBeforeInsertHook)
|
||||
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeInsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterInsertHook, withdrawalFiatAfterInsertHook)
|
||||
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterInsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterSelectHook, withdrawalFiatAfterSelectHook)
|
||||
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterSelectHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeUpdateHook, withdrawalFiatBeforeUpdateHook)
|
||||
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeUpdateHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterUpdateHook, withdrawalFiatAfterUpdateHook)
|
||||
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterUpdateHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeDeleteHook, withdrawalFiatBeforeDeleteHook)
|
||||
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeDeleteHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterDeleteHook, withdrawalFiatAfterDeleteHook)
|
||||
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterDeleteHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeUpsertHook, withdrawalFiatBeforeUpsertHook)
|
||||
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeUpsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterUpsertHook, withdrawalFiatAfterUpsertHook)
|
||||
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterUpsertHooks = []WithdrawalFiatHook{}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(withdrawalFiatColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatToOneWithdrawalHistoryUsingWithdrawalFiat(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local WithdrawalFiat
|
||||
var foreign WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
queries.Assign(&local.WithdrawalFiatID, foreign.ID)
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.WithdrawalFiat().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !queries.Equal(check.ID, foreign.ID) {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{&local}
|
||||
if err = local.L.LoadWithdrawalFiat(ctx, tx, false, (*[]*WithdrawalFiat)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalFiat == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.WithdrawalFiat = nil
|
||||
if err = local.L.LoadWithdrawalFiat(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalFiat == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatToOneSetOpWithdrawalHistoryUsingWithdrawalFiat(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalFiat
|
||||
var b, c WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalFiatDBTypes, false, strmangle.SetComplement(withdrawalFiatPrimaryKeyColumns, withdrawalFiatColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*WithdrawalHistory{&b, &c} {
|
||||
err = a.SetWithdrawalFiat(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.WithdrawalFiat != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.WithdrawalFiatWithdrawalFiats[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if !queries.Equal(a.WithdrawalFiatID, x.ID) {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalFiatID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.WithdrawalFiatID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.WithdrawalFiatID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if !queries.Equal(a.WithdrawalFiatID, x.ID) {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalFiatID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatToOneRemoveOpWithdrawalHistoryUsingWithdrawalFiat(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalFiat
|
||||
var b WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalFiatDBTypes, false, strmangle.SetComplement(withdrawalFiatPrimaryKeyColumns, withdrawalFiatColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.SetWithdrawalFiat(ctx, tx, true, &b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = a.RemoveWithdrawalFiat(ctx, tx, &b); err != nil {
|
||||
t.Error("failed to remove relationship")
|
||||
}
|
||||
|
||||
count, err := a.WithdrawalFiat().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 0 {
|
||||
t.Error("want no relationships remaining")
|
||||
}
|
||||
|
||||
if a.R.WithdrawalFiat != nil {
|
||||
t.Error("R struct entry should be nil")
|
||||
}
|
||||
|
||||
if !queries.IsValuerNil(a.WithdrawalFiatID) {
|
||||
t.Error("foreign key value should be nil")
|
||||
}
|
||||
|
||||
if len(b.R.WithdrawalFiatWithdrawalFiats) != 0 {
|
||||
t.Error("failed to remove a from b's relationships")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalFiats().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
withdrawalFiatDBTypes = map[string]string{`ID`: `bigint`, `WithdrawalFiatID`: `uuid`, `BankName`: `text`, `BankAddress`: `text`, `BankAccountName`: `text`, `BankAccountNumber`: `text`, `BSB`: `text`, `SwiftCode`: `text`, `Iban`: `text`, `BankCode`: `double precision`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testWithdrawalFiatsUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(withdrawalFiatAllColumns) == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalFiatAllColumns) == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(withdrawalFiatAllColumns, withdrawalFiatPrimaryKeyColumns) {
|
||||
fields = withdrawalFiatAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
withdrawalFiatAllColumns,
|
||||
withdrawalFiatPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsUpsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalFiatAllColumns) == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
// Attempt the INSERT side of an UPSERT
|
||||
o := WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, &o, withdrawalFiatDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Upsert(ctx, tx, false, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert WithdrawalFiat: %s", err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
// Attempt the UPDATE side of an UPSERT
|
||||
if err = randomize.Struct(seed, &o, withdrawalFiatDBTypes, false, withdrawalFiatPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
if err = o.Upsert(ctx, tx, true, nil, boil.Infer(), boil.Infer()); err != nil {
|
||||
t.Errorf("Unable to upsert WithdrawalFiat: %s", err)
|
||||
}
|
||||
|
||||
count, err = WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
1406
database/models/postgres/withdrawal_history.go
Normal file
1406
database/models/postgres/withdrawal_history.go
Normal file
File diff suppressed because it is too large
Load Diff
1388
database/models/postgres/withdrawal_history_test.go
Normal file
1388
database/models/postgres/withdrawal_history_test.go
Normal file
File diff suppressed because it is too large
Load Diff
@@ -15,66 +15,99 @@ func TestParent(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEvents)
|
||||
t.Run("Scripts", testScripts)
|
||||
t.Run("ScriptExecutions", testScriptExecutions)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptos)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiats)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistories)
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsDelete)
|
||||
t.Run("Scripts", testScriptsDelete)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsDelete)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosDelete)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsDelete)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesDelete)
|
||||
}
|
||||
|
||||
func TestQueryDeleteAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsQueryDeleteAll)
|
||||
t.Run("Scripts", testScriptsQueryDeleteAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsQueryDeleteAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosQueryDeleteAll)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsQueryDeleteAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesQueryDeleteAll)
|
||||
}
|
||||
|
||||
func TestSliceDeleteAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSliceDeleteAll)
|
||||
t.Run("Scripts", testScriptsSliceDeleteAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsSliceDeleteAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosSliceDeleteAll)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsSliceDeleteAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSliceDeleteAll)
|
||||
}
|
||||
|
||||
func TestExists(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsExists)
|
||||
t.Run("Scripts", testScriptsExists)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsExists)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosExists)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsExists)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesExists)
|
||||
}
|
||||
|
||||
func TestFind(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsFind)
|
||||
t.Run("Scripts", testScriptsFind)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsFind)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosFind)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsFind)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesFind)
|
||||
}
|
||||
|
||||
func TestBind(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsBind)
|
||||
t.Run("Scripts", testScriptsBind)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsBind)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosBind)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsBind)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesBind)
|
||||
}
|
||||
|
||||
func TestOne(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsOne)
|
||||
t.Run("Scripts", testScriptsOne)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsOne)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosOne)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsOne)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesOne)
|
||||
}
|
||||
|
||||
func TestAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsAll)
|
||||
t.Run("Scripts", testScriptsAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosAll)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesAll)
|
||||
}
|
||||
|
||||
func TestCount(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsCount)
|
||||
t.Run("Scripts", testScriptsCount)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsCount)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosCount)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsCount)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesCount)
|
||||
}
|
||||
|
||||
func TestHooks(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsHooks)
|
||||
t.Run("Scripts", testScriptsHooks)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsHooks)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosHooks)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsHooks)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesHooks)
|
||||
}
|
||||
|
||||
func TestInsert(t *testing.T) {
|
||||
@@ -84,12 +117,20 @@ func TestInsert(t *testing.T) {
|
||||
t.Run("Scripts", testScriptsInsertWhitelist)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsInsert)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsInsertWhitelist)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosInsert)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosInsertWhitelist)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsInsert)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsInsertWhitelist)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesInsert)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesInsertWhitelist)
|
||||
}
|
||||
|
||||
// TestToOne tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToOne(t *testing.T) {
|
||||
t.Run("ScriptExecutionToScriptUsingScript", testScriptExecutionToOneScriptUsingScript)
|
||||
t.Run("WithdrawalCryptoToWithdrawalHistoryUsingWithdrawalHistory", testWithdrawalCryptoToOneWithdrawalHistoryUsingWithdrawalHistory)
|
||||
t.Run("WithdrawalFiatToWithdrawalHistoryUsingWithdrawalHistory", testWithdrawalFiatToOneWithdrawalHistoryUsingWithdrawalHistory)
|
||||
}
|
||||
|
||||
// TestOneToOne tests cannot be run in parallel
|
||||
@@ -100,12 +141,16 @@ func TestOneToOne(t *testing.T) {}
|
||||
// or deadlocks can occur.
|
||||
func TestToMany(t *testing.T) {
|
||||
t.Run("ScriptToScriptExecutions", testScriptToManyScriptExecutions)
|
||||
t.Run("WithdrawalHistoryToWithdrawalCryptos", testWithdrawalHistoryToManyWithdrawalCryptos)
|
||||
t.Run("WithdrawalHistoryToWithdrawalFiats", testWithdrawalHistoryToManyWithdrawalFiats)
|
||||
}
|
||||
|
||||
// TestToOneSet tests cannot be run in parallel
|
||||
// or deadlocks can occur.
|
||||
func TestToOneSet(t *testing.T) {
|
||||
t.Run("ScriptExecutionToScriptUsingScriptExecutions", testScriptExecutionToOneSetOpScriptUsingScript)
|
||||
t.Run("WithdrawalCryptoToWithdrawalHistoryUsingWithdrawalCryptos", testWithdrawalCryptoToOneSetOpWithdrawalHistoryUsingWithdrawalHistory)
|
||||
t.Run("WithdrawalFiatToWithdrawalHistoryUsingWithdrawalFiats", testWithdrawalFiatToOneSetOpWithdrawalHistoryUsingWithdrawalHistory)
|
||||
}
|
||||
|
||||
// TestToOneRemove tests cannot be run in parallel
|
||||
@@ -124,6 +169,8 @@ func TestOneToOneRemove(t *testing.T) {}
|
||||
// or deadlocks can occur.
|
||||
func TestToManyAdd(t *testing.T) {
|
||||
t.Run("ScriptToScriptExecutions", testScriptToManyAddOpScriptExecutions)
|
||||
t.Run("WithdrawalHistoryToWithdrawalCryptos", testWithdrawalHistoryToManyAddOpWithdrawalCryptos)
|
||||
t.Run("WithdrawalHistoryToWithdrawalFiats", testWithdrawalHistoryToManyAddOpWithdrawalFiats)
|
||||
}
|
||||
|
||||
// TestToManySet tests cannot be run in parallel
|
||||
@@ -138,28 +185,43 @@ func TestReload(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsReload)
|
||||
t.Run("Scripts", testScriptsReload)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsReload)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosReload)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsReload)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesReload)
|
||||
}
|
||||
|
||||
func TestReloadAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsReloadAll)
|
||||
t.Run("Scripts", testScriptsReloadAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsReloadAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosReloadAll)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsReloadAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesReloadAll)
|
||||
}
|
||||
|
||||
func TestSelect(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSelect)
|
||||
t.Run("Scripts", testScriptsSelect)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsSelect)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosSelect)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsSelect)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSelect)
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsUpdate)
|
||||
t.Run("Scripts", testScriptsUpdate)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsUpdate)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosUpdate)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsUpdate)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesUpdate)
|
||||
}
|
||||
|
||||
func TestSliceUpdateAll(t *testing.T) {
|
||||
t.Run("AuditEvents", testAuditEventsSliceUpdateAll)
|
||||
t.Run("Scripts", testScriptsSliceUpdateAll)
|
||||
t.Run("ScriptExecutions", testScriptExecutionsSliceUpdateAll)
|
||||
t.Run("WithdrawalCryptos", testWithdrawalCryptosSliceUpdateAll)
|
||||
t.Run("WithdrawalFiats", testWithdrawalFiatsSliceUpdateAll)
|
||||
t.Run("WithdrawalHistories", testWithdrawalHistoriesSliceUpdateAll)
|
||||
}
|
||||
|
||||
@@ -4,11 +4,17 @@
|
||||
package sqlite3
|
||||
|
||||
var TableNames = struct {
|
||||
AuditEvent string
|
||||
Script string
|
||||
ScriptExecution string
|
||||
AuditEvent string
|
||||
Script string
|
||||
ScriptExecution string
|
||||
WithdrawalCrypto string
|
||||
WithdrawalFiat string
|
||||
WithdrawalHistory string
|
||||
}{
|
||||
AuditEvent: "audit_event",
|
||||
Script: "script",
|
||||
ScriptExecution: "script_execution",
|
||||
AuditEvent: "audit_event",
|
||||
Script: "script",
|
||||
ScriptExecution: "script_execution",
|
||||
WithdrawalCrypto: "withdrawal_crypto",
|
||||
WithdrawalFiat: "withdrawal_fiat",
|
||||
WithdrawalHistory: "withdrawal_history",
|
||||
}
|
||||
|
||||
996
database/models/sqlite3/withdrawal_crypto.go
Normal file
996
database/models/sqlite3/withdrawal_crypto.go
Normal file
@@ -0,0 +1,996 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/queries/qm"
|
||||
"github.com/thrasher-corp/sqlboiler/queries/qmhelper"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
"github.com/volatiletech/null"
|
||||
)
|
||||
|
||||
// WithdrawalCrypto is an object representing the database table.
|
||||
type WithdrawalCrypto struct {
|
||||
ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"`
|
||||
Address string `boil:"address" json:"address" toml:"address" yaml:"address"`
|
||||
AddressTag null.String `boil:"address_tag" json:"address_tag,omitempty" toml:"address_tag" yaml:"address_tag,omitempty"`
|
||||
Fee float64 `boil:"fee" json:"fee" toml:"fee" yaml:"fee"`
|
||||
WithdrawalHistoryID string `boil:"withdrawal_history_id" json:"withdrawal_history_id" toml:"withdrawal_history_id" yaml:"withdrawal_history_id"`
|
||||
|
||||
R *withdrawalCryptoR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L withdrawalCryptoL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var WithdrawalCryptoColumns = struct {
|
||||
ID string
|
||||
Address string
|
||||
AddressTag string
|
||||
Fee string
|
||||
WithdrawalHistoryID string
|
||||
}{
|
||||
ID: "id",
|
||||
Address: "address",
|
||||
AddressTag: "address_tag",
|
||||
Fee: "fee",
|
||||
WithdrawalHistoryID: "withdrawal_history_id",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
type whereHelpernull_String struct{ field string }
|
||||
|
||||
func (w whereHelpernull_String) EQ(x null.String) qm.QueryMod {
|
||||
return qmhelper.WhereNullEQ(w.field, false, x)
|
||||
}
|
||||
func (w whereHelpernull_String) NEQ(x null.String) qm.QueryMod {
|
||||
return qmhelper.WhereNullEQ(w.field, true, x)
|
||||
}
|
||||
func (w whereHelpernull_String) IsNull() qm.QueryMod { return qmhelper.WhereIsNull(w.field) }
|
||||
func (w whereHelpernull_String) IsNotNull() qm.QueryMod { return qmhelper.WhereIsNotNull(w.field) }
|
||||
func (w whereHelpernull_String) LT(x null.String) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.LT, x)
|
||||
}
|
||||
func (w whereHelpernull_String) LTE(x null.String) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.LTE, x)
|
||||
}
|
||||
func (w whereHelpernull_String) GT(x null.String) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.GT, x)
|
||||
}
|
||||
func (w whereHelpernull_String) GTE(x null.String) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.GTE, x)
|
||||
}
|
||||
|
||||
type whereHelperfloat64 struct{ field string }
|
||||
|
||||
func (w whereHelperfloat64) EQ(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.EQ, x) }
|
||||
func (w whereHelperfloat64) NEQ(x float64) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.NEQ, x)
|
||||
}
|
||||
func (w whereHelperfloat64) LT(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.LT, x) }
|
||||
func (w whereHelperfloat64) LTE(x float64) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.LTE, x)
|
||||
}
|
||||
func (w whereHelperfloat64) GT(x float64) qm.QueryMod { return qmhelper.Where(w.field, qmhelper.GT, x) }
|
||||
func (w whereHelperfloat64) GTE(x float64) qm.QueryMod {
|
||||
return qmhelper.Where(w.field, qmhelper.GTE, x)
|
||||
}
|
||||
|
||||
var WithdrawalCryptoWhere = struct {
|
||||
ID whereHelperint64
|
||||
Address whereHelperstring
|
||||
AddressTag whereHelpernull_String
|
||||
Fee whereHelperfloat64
|
||||
WithdrawalHistoryID whereHelperstring
|
||||
}{
|
||||
ID: whereHelperint64{field: "\"withdrawal_crypto\".\"id\""},
|
||||
Address: whereHelperstring{field: "\"withdrawal_crypto\".\"address\""},
|
||||
AddressTag: whereHelpernull_String{field: "\"withdrawal_crypto\".\"address_tag\""},
|
||||
Fee: whereHelperfloat64{field: "\"withdrawal_crypto\".\"fee\""},
|
||||
WithdrawalHistoryID: whereHelperstring{field: "\"withdrawal_crypto\".\"withdrawal_history_id\""},
|
||||
}
|
||||
|
||||
// WithdrawalCryptoRels is where relationship names are stored.
|
||||
var WithdrawalCryptoRels = struct {
|
||||
WithdrawalHistory string
|
||||
}{
|
||||
WithdrawalHistory: "WithdrawalHistory",
|
||||
}
|
||||
|
||||
// withdrawalCryptoR is where relationships are stored.
|
||||
type withdrawalCryptoR struct {
|
||||
WithdrawalHistory *WithdrawalHistory
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*withdrawalCryptoR) NewStruct() *withdrawalCryptoR {
|
||||
return &withdrawalCryptoR{}
|
||||
}
|
||||
|
||||
// withdrawalCryptoL is where Load methods for each relationship are stored.
|
||||
type withdrawalCryptoL struct{}
|
||||
|
||||
var (
|
||||
withdrawalCryptoAllColumns = []string{"id", "address", "address_tag", "fee", "withdrawal_history_id"}
|
||||
withdrawalCryptoColumnsWithoutDefault = []string{"address", "address_tag", "fee", "withdrawal_history_id"}
|
||||
withdrawalCryptoColumnsWithDefault = []string{"id"}
|
||||
withdrawalCryptoPrimaryKeyColumns = []string{"id"}
|
||||
)
|
||||
|
||||
type (
|
||||
// WithdrawalCryptoSlice is an alias for a slice of pointers to WithdrawalCrypto.
|
||||
// This should generally be used opposed to []WithdrawalCrypto.
|
||||
WithdrawalCryptoSlice []*WithdrawalCrypto
|
||||
// WithdrawalCryptoHook is the signature for custom WithdrawalCrypto hook methods
|
||||
WithdrawalCryptoHook func(context.Context, boil.ContextExecutor, *WithdrawalCrypto) error
|
||||
|
||||
withdrawalCryptoQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
withdrawalCryptoType = reflect.TypeOf(&WithdrawalCrypto{})
|
||||
withdrawalCryptoMapping = queries.MakeStructMapping(withdrawalCryptoType)
|
||||
withdrawalCryptoPrimaryKeyMapping, _ = queries.BindMapping(withdrawalCryptoType, withdrawalCryptoMapping, withdrawalCryptoPrimaryKeyColumns)
|
||||
withdrawalCryptoInsertCacheMut sync.RWMutex
|
||||
withdrawalCryptoInsertCache = make(map[string]insertCache)
|
||||
withdrawalCryptoUpdateCacheMut sync.RWMutex
|
||||
withdrawalCryptoUpdateCache = make(map[string]updateCache)
|
||||
withdrawalCryptoUpsertCacheMut sync.RWMutex
|
||||
withdrawalCryptoUpsertCache = make(map[string]insertCache)
|
||||
)
|
||||
|
||||
var (
|
||||
// Force time package dependency for automated UpdatedAt/CreatedAt.
|
||||
_ = time.Second
|
||||
// Force qmhelper dependency for where clause generation (which doesn't
|
||||
// always happen)
|
||||
_ = qmhelper.Where
|
||||
)
|
||||
|
||||
var withdrawalCryptoBeforeInsertHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoBeforeUpdateHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoBeforeDeleteHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoBeforeUpsertHooks []WithdrawalCryptoHook
|
||||
|
||||
var withdrawalCryptoAfterInsertHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoAfterSelectHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoAfterUpdateHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoAfterDeleteHooks []WithdrawalCryptoHook
|
||||
var withdrawalCryptoAfterUpsertHooks []WithdrawalCryptoHook
|
||||
|
||||
// doBeforeInsertHooks executes all "before insert" hooks.
|
||||
func (o *WithdrawalCrypto) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoBeforeInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpdateHooks executes all "before Update" hooks.
|
||||
func (o *WithdrawalCrypto) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoBeforeUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeDeleteHooks executes all "before Delete" hooks.
|
||||
func (o *WithdrawalCrypto) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoBeforeDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpsertHooks executes all "before Upsert" hooks.
|
||||
func (o *WithdrawalCrypto) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoBeforeUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterInsertHooks executes all "after Insert" hooks.
|
||||
func (o *WithdrawalCrypto) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoAfterInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterSelectHooks executes all "after Select" hooks.
|
||||
func (o *WithdrawalCrypto) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoAfterSelectHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpdateHooks executes all "after Update" hooks.
|
||||
func (o *WithdrawalCrypto) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoAfterUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterDeleteHooks executes all "after Delete" hooks.
|
||||
func (o *WithdrawalCrypto) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoAfterDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpsertHooks executes all "after Upsert" hooks.
|
||||
func (o *WithdrawalCrypto) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalCryptoAfterUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddWithdrawalCryptoHook registers your hook function for all future operations.
|
||||
func AddWithdrawalCryptoHook(hookPoint boil.HookPoint, withdrawalCryptoHook WithdrawalCryptoHook) {
|
||||
switch hookPoint {
|
||||
case boil.BeforeInsertHook:
|
||||
withdrawalCryptoBeforeInsertHooks = append(withdrawalCryptoBeforeInsertHooks, withdrawalCryptoHook)
|
||||
case boil.BeforeUpdateHook:
|
||||
withdrawalCryptoBeforeUpdateHooks = append(withdrawalCryptoBeforeUpdateHooks, withdrawalCryptoHook)
|
||||
case boil.BeforeDeleteHook:
|
||||
withdrawalCryptoBeforeDeleteHooks = append(withdrawalCryptoBeforeDeleteHooks, withdrawalCryptoHook)
|
||||
case boil.BeforeUpsertHook:
|
||||
withdrawalCryptoBeforeUpsertHooks = append(withdrawalCryptoBeforeUpsertHooks, withdrawalCryptoHook)
|
||||
case boil.AfterInsertHook:
|
||||
withdrawalCryptoAfterInsertHooks = append(withdrawalCryptoAfterInsertHooks, withdrawalCryptoHook)
|
||||
case boil.AfterSelectHook:
|
||||
withdrawalCryptoAfterSelectHooks = append(withdrawalCryptoAfterSelectHooks, withdrawalCryptoHook)
|
||||
case boil.AfterUpdateHook:
|
||||
withdrawalCryptoAfterUpdateHooks = append(withdrawalCryptoAfterUpdateHooks, withdrawalCryptoHook)
|
||||
case boil.AfterDeleteHook:
|
||||
withdrawalCryptoAfterDeleteHooks = append(withdrawalCryptoAfterDeleteHooks, withdrawalCryptoHook)
|
||||
case boil.AfterUpsertHook:
|
||||
withdrawalCryptoAfterUpsertHooks = append(withdrawalCryptoAfterUpsertHooks, withdrawalCryptoHook)
|
||||
}
|
||||
}
|
||||
|
||||
// One returns a single withdrawalCrypto record from the query.
|
||||
func (q withdrawalCryptoQuery) One(ctx context.Context, exec boil.ContextExecutor) (*WithdrawalCrypto, error) {
|
||||
o := &WithdrawalCrypto{}
|
||||
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Bind(ctx, exec, o)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "sqlite3: failed to execute a one query for withdrawal_crypto")
|
||||
}
|
||||
|
||||
if err := o.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return o, err
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all WithdrawalCrypto records from the query.
|
||||
func (q withdrawalCryptoQuery) All(ctx context.Context, exec boil.ContextExecutor) (WithdrawalCryptoSlice, error) {
|
||||
var o []*WithdrawalCrypto
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "sqlite3: failed to assign all query results to WithdrawalCrypto slice")
|
||||
}
|
||||
|
||||
if len(withdrawalCryptoAfterSelectHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return o, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Count returns the count of all WithdrawalCrypto records in the query.
|
||||
func (q withdrawalCryptoQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to count withdrawal_crypto rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q withdrawalCryptoQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "sqlite3: failed to check if withdrawal_crypto exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// WithdrawalHistory pointed to by the foreign key.
|
||||
func (o *WithdrawalCrypto) WithdrawalHistory(mods ...qm.QueryMod) withdrawalHistoryQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.WithdrawalHistoryID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
query := WithdrawalHistories(queryMods...)
|
||||
queries.SetFrom(query.Query, "\"withdrawal_history\"")
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
// LoadWithdrawalHistory allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (withdrawalCryptoL) LoadWithdrawalHistory(ctx context.Context, e boil.ContextExecutor, singular bool, maybeWithdrawalCrypto interface{}, mods queries.Applicator) error {
|
||||
var slice []*WithdrawalCrypto
|
||||
var object *WithdrawalCrypto
|
||||
|
||||
if singular {
|
||||
object = maybeWithdrawalCrypto.(*WithdrawalCrypto)
|
||||
} else {
|
||||
slice = *maybeWithdrawalCrypto.(*[]*WithdrawalCrypto)
|
||||
}
|
||||
|
||||
args := make([]interface{}, 0, 1)
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &withdrawalCryptoR{}
|
||||
}
|
||||
args = append(args, object.WithdrawalHistoryID)
|
||||
|
||||
} else {
|
||||
Outer:
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &withdrawalCryptoR{}
|
||||
}
|
||||
|
||||
for _, a := range args {
|
||||
if a == obj.WithdrawalHistoryID {
|
||||
continue Outer
|
||||
}
|
||||
}
|
||||
|
||||
args = append(args, obj.WithdrawalHistoryID)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
query := NewQuery(qm.From(`withdrawal_history`), qm.WhereIn(`withdrawal_history.id in ?`, args...))
|
||||
if mods != nil {
|
||||
mods.Apply(query)
|
||||
}
|
||||
|
||||
results, err := query.QueryContext(ctx, e)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to eager load WithdrawalHistory")
|
||||
}
|
||||
|
||||
var resultSlice []*WithdrawalHistory
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice WithdrawalHistory")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for withdrawal_history")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for withdrawal_history")
|
||||
}
|
||||
|
||||
if len(withdrawalCryptoAfterSelectHooks) != 0 {
|
||||
for _, obj := range resultSlice {
|
||||
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(resultSlice) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if singular {
|
||||
foreign := resultSlice[0]
|
||||
object.R.WithdrawalHistory = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &withdrawalHistoryR{}
|
||||
}
|
||||
foreign.R.WithdrawalCryptos = append(foreign.R.WithdrawalCryptos, object)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.WithdrawalHistoryID == foreign.ID {
|
||||
local.R.WithdrawalHistory = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &withdrawalHistoryR{}
|
||||
}
|
||||
foreign.R.WithdrawalCryptos = append(foreign.R.WithdrawalCryptos, local)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetWithdrawalHistory of the withdrawalCrypto to the related item.
|
||||
// Sets o.R.WithdrawalHistory to related.
|
||||
// Adds o to related.R.WithdrawalCryptos.
|
||||
func (o *WithdrawalCrypto) SetWithdrawalHistory(ctx context.Context, exec boil.ContextExecutor, insert bool, related *WithdrawalHistory) error {
|
||||
var err error
|
||||
if insert {
|
||||
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
|
||||
return errors.Wrap(err, "failed to insert into foreign table")
|
||||
}
|
||||
}
|
||||
|
||||
updateQuery := fmt.Sprintf(
|
||||
"UPDATE \"withdrawal_crypto\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, []string{"withdrawal_history_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 0, withdrawalCryptoPrimaryKeyColumns),
|
||||
)
|
||||
values := []interface{}{related.ID, o.ID}
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, updateQuery)
|
||||
fmt.Fprintln(boil.DebugWriter, values)
|
||||
}
|
||||
|
||||
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
|
||||
return errors.Wrap(err, "failed to update local table")
|
||||
}
|
||||
|
||||
o.WithdrawalHistoryID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &withdrawalCryptoR{
|
||||
WithdrawalHistory: related,
|
||||
}
|
||||
} else {
|
||||
o.R.WithdrawalHistory = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &withdrawalHistoryR{
|
||||
WithdrawalCryptos: WithdrawalCryptoSlice{o},
|
||||
}
|
||||
} else {
|
||||
related.R.WithdrawalCryptos = append(related.R.WithdrawalCryptos, o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithdrawalCryptos retrieves all the records using an executor.
|
||||
func WithdrawalCryptos(mods ...qm.QueryMod) withdrawalCryptoQuery {
|
||||
mods = append(mods, qm.From("\"withdrawal_crypto\""))
|
||||
return withdrawalCryptoQuery{NewQuery(mods...)}
|
||||
}
|
||||
|
||||
// FindWithdrawalCrypto retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindWithdrawalCrypto(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*WithdrawalCrypto, error) {
|
||||
withdrawalCryptoObj := &WithdrawalCrypto{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"withdrawal_crypto\" where \"id\"=?", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, iD)
|
||||
|
||||
err := q.Bind(ctx, exec, withdrawalCryptoObj)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "sqlite3: unable to select from withdrawal_crypto")
|
||||
}
|
||||
|
||||
return withdrawalCryptoObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *WithdrawalCrypto) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("sqlite3: no withdrawal_crypto provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(withdrawalCryptoColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
withdrawalCryptoInsertCacheMut.RLock()
|
||||
cache, cached := withdrawalCryptoInsertCache[key]
|
||||
withdrawalCryptoInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
withdrawalCryptoAllColumns,
|
||||
withdrawalCryptoColumnsWithDefault,
|
||||
withdrawalCryptoColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(withdrawalCryptoType, withdrawalCryptoMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(withdrawalCryptoType, withdrawalCryptoMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"withdrawal_crypto\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"withdrawal_crypto\" () VALUES ()%s%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
cache.retQuery = fmt.Sprintf("SELECT \"%s\" FROM \"withdrawal_crypto\" WHERE %s", strings.Join(returnColumns, "\",\""), strmangle.WhereClause("\"", "\"", 0, withdrawalCryptoPrimaryKeyColumns))
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.query)
|
||||
fmt.Fprintln(boil.DebugWriter, vals)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, cache.query, vals...)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to insert into withdrawal_crypto")
|
||||
}
|
||||
|
||||
var lastID int64
|
||||
var identifierCols []interface{}
|
||||
|
||||
if len(cache.retMapping) == 0 {
|
||||
goto CacheNoHooks
|
||||
}
|
||||
|
||||
lastID, err = result.LastInsertId()
|
||||
if err != nil {
|
||||
return ErrSyncFail
|
||||
}
|
||||
|
||||
o.ID = int64(lastID)
|
||||
if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == withdrawalCryptoMapping["ID"] {
|
||||
goto CacheNoHooks
|
||||
}
|
||||
|
||||
identifierCols = []interface{}{
|
||||
o.ID,
|
||||
}
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.retQuery)
|
||||
fmt.Fprintln(boil.DebugWriter, identifierCols...)
|
||||
}
|
||||
|
||||
err = exec.QueryRowContext(ctx, cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to populate default values for withdrawal_crypto")
|
||||
}
|
||||
|
||||
CacheNoHooks:
|
||||
if !cached {
|
||||
withdrawalCryptoInsertCacheMut.Lock()
|
||||
withdrawalCryptoInsertCache[key] = cache
|
||||
withdrawalCryptoInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return o.doAfterInsertHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// Update uses an executor to update the WithdrawalCrypto.
|
||||
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
|
||||
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
|
||||
func (o *WithdrawalCrypto) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
|
||||
var err error
|
||||
if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
key := makeCacheKey(columns, nil)
|
||||
withdrawalCryptoUpdateCacheMut.RLock()
|
||||
cache, cached := withdrawalCryptoUpdateCache[key]
|
||||
withdrawalCryptoUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
withdrawalCryptoAllColumns,
|
||||
withdrawalCryptoPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("sqlite3: unable to update withdrawal_crypto, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"withdrawal_crypto\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, wl),
|
||||
strmangle.WhereClause("\"", "\"", 0, withdrawalCryptoPrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(withdrawalCryptoType, withdrawalCryptoMapping, append(wl, withdrawalCryptoPrimaryKeyColumns...))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.query)
|
||||
fmt.Fprintln(boil.DebugWriter, values)
|
||||
}
|
||||
|
||||
var result sql.Result
|
||||
result, err = exec.ExecContext(ctx, cache.query, values...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update withdrawal_crypto row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by update for withdrawal_crypto")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
withdrawalCryptoUpdateCacheMut.Lock()
|
||||
withdrawalCryptoUpdateCache[key] = cache
|
||||
withdrawalCryptoUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, o.doAfterUpdateHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q withdrawalCryptoQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
queries.SetUpdate(q.Query, cols)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update all for withdrawal_crypto")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected for withdrawal_crypto")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o WithdrawalCryptoSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
ln := int64(len(o))
|
||||
if ln == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return 0, errors.New("sqlite3: update all requires at least one column argument")
|
||||
}
|
||||
|
||||
colNames := make([]string, len(cols))
|
||||
args := make([]interface{}, len(cols))
|
||||
|
||||
i := 0
|
||||
for name, value := range cols {
|
||||
colNames[i] = name
|
||||
args[i] = value
|
||||
i++
|
||||
}
|
||||
|
||||
// Append all of the primary key values for each column
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalCryptoPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"withdrawal_crypto\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalCryptoPrimaryKeyColumns, len(o)))
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args...)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update all in withdrawalCrypto slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected all in update all withdrawalCrypto")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Delete deletes a single WithdrawalCrypto record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *WithdrawalCrypto) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("sqlite3: no WithdrawalCrypto provided for delete")
|
||||
}
|
||||
|
||||
if err := o.doBeforeDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), withdrawalCryptoPrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"withdrawal_crypto\" WHERE \"id\"=?"
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args...)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete from withdrawal_crypto")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by delete for withdrawal_crypto")
|
||||
}
|
||||
|
||||
if err := o.doAfterDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q withdrawalCryptoQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("sqlite3: no withdrawalCryptoQuery provided for delete all")
|
||||
}
|
||||
|
||||
queries.SetDelete(q.Query)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete all from withdrawal_crypto")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for withdrawal_crypto")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o WithdrawalCryptoSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(withdrawalCryptoBeforeDeleteHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalCryptoPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"withdrawal_crypto\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalCryptoPrimaryKeyColumns, len(o))
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete all from withdrawalCrypto slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for withdrawal_crypto")
|
||||
}
|
||||
|
||||
if len(withdrawalCryptoAfterDeleteHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doAfterDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Reload refetches the object from the database
|
||||
// using the primary keys with an executor.
|
||||
func (o *WithdrawalCrypto) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindWithdrawalCrypto(ctx, exec, o.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ret
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadAll refetches every row with matching primary key column values
|
||||
// and overwrites the original object slice with the newly updated slice.
|
||||
func (o *WithdrawalCryptoSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalCryptoPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"withdrawal_crypto\".* FROM \"withdrawal_crypto\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalCryptoPrimaryKeyColumns, len(*o))
|
||||
|
||||
q := queries.Raw(sql, args...)
|
||||
|
||||
err := q.Bind(ctx, exec, &slice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to reload all in WithdrawalCryptoSlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithdrawalCryptoExists checks if the WithdrawalCrypto row exists.
|
||||
func WithdrawalCryptoExists(ctx context.Context, exec boil.ContextExecutor, iD int64) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"withdrawal_crypto\" where \"id\"=? limit 1)"
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, iD)
|
||||
}
|
||||
|
||||
row := exec.QueryRowContext(ctx, sql, iD)
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "sqlite3: unable to check if withdrawal_crypto exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
793
database/models/sqlite3/withdrawal_crypto_test.go
Normal file
793
database/models/sqlite3/withdrawal_crypto_test.go
Normal file
@@ -0,0 +1,793 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/randomize"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testWithdrawalCryptos(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := WithdrawalCryptos()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := WithdrawalCryptos().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := WithdrawalCryptoExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if WithdrawalCrypto exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected WithdrawalCryptoExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
withdrawalCryptoFound, err := FindWithdrawalCrypto(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if withdrawalCryptoFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = WithdrawalCryptos().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := WithdrawalCryptos().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
withdrawalCryptoOne := &WithdrawalCrypto{}
|
||||
withdrawalCryptoTwo := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoOne, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoTwo, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalCryptoOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalCryptoTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalCryptos().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
withdrawalCryptoOne := &WithdrawalCrypto{}
|
||||
withdrawalCryptoTwo := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoOne, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalCryptoTwo, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalCryptoOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalCryptoTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalCryptoAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalCrypto) error {
|
||||
*o = WithdrawalCrypto{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &WithdrawalCrypto{}
|
||||
o := &WithdrawalCrypto{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto object: %s", err)
|
||||
}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeInsertHook, withdrawalCryptoBeforeInsertHook)
|
||||
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeInsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterInsertHook, withdrawalCryptoAfterInsertHook)
|
||||
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterInsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterSelectHook, withdrawalCryptoAfterSelectHook)
|
||||
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterSelectHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeUpdateHook, withdrawalCryptoBeforeUpdateHook)
|
||||
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeUpdateHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterUpdateHook, withdrawalCryptoAfterUpdateHook)
|
||||
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterUpdateHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeDeleteHook, withdrawalCryptoBeforeDeleteHook)
|
||||
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeDeleteHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterDeleteHook, withdrawalCryptoAfterDeleteHook)
|
||||
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterDeleteHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.BeforeUpsertHook, withdrawalCryptoBeforeUpsertHook)
|
||||
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoBeforeUpsertHooks = []WithdrawalCryptoHook{}
|
||||
|
||||
AddWithdrawalCryptoHook(boil.AfterUpsertHook, withdrawalCryptoAfterUpsertHook)
|
||||
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalCryptoAfterUpsertHooks = []WithdrawalCryptoHook{}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(withdrawalCryptoColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptoToOneWithdrawalHistoryUsingWithdrawalHistory(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local WithdrawalCrypto
|
||||
var foreign WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.WithdrawalHistoryID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.WithdrawalHistory().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if check.ID != foreign.ID {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{&local}
|
||||
if err = local.L.LoadWithdrawalHistory(ctx, tx, false, (*[]*WithdrawalCrypto)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalHistory == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.WithdrawalHistory = nil
|
||||
if err = local.L.LoadWithdrawalHistory(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalHistory == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptoToOneSetOpWithdrawalHistoryUsingWithdrawalHistory(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalCrypto
|
||||
var b, c WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalCryptoDBTypes, false, strmangle.SetComplement(withdrawalCryptoPrimaryKeyColumns, withdrawalCryptoColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*WithdrawalHistory{&b, &c} {
|
||||
err = a.SetWithdrawalHistory(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.WithdrawalHistory != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.WithdrawalCryptos[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.WithdrawalHistoryID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalHistoryID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.WithdrawalHistoryID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.WithdrawalHistoryID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.WithdrawalHistoryID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalHistoryID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalCryptos().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
withdrawalCryptoDBTypes = map[string]string{`ID`: `INTEGER`, `Address`: `TEXT`, `AddressTag`: `TEXT`, `Fee`: `REAL`, `WithdrawalHistoryID`: `TEXT`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testWithdrawalCryptosUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(withdrawalCryptoAllColumns) == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalCryptosSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalCryptoAllColumns) == len(withdrawalCryptoPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalCrypto{}
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalCryptoDBTypes, true, withdrawalCryptoPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalCrypto struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(withdrawalCryptoAllColumns, withdrawalCryptoPrimaryKeyColumns) {
|
||||
fields = withdrawalCryptoAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
withdrawalCryptoAllColumns,
|
||||
withdrawalCryptoPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := WithdrawalCryptoSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
982
database/models/sqlite3/withdrawal_fiat.go
Normal file
982
database/models/sqlite3/withdrawal_fiat.go
Normal file
@@ -0,0 +1,982 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/queries/qm"
|
||||
"github.com/thrasher-corp/sqlboiler/queries/qmhelper"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
// WithdrawalFiat is an object representing the database table.
|
||||
type WithdrawalFiat struct {
|
||||
ID int64 `boil:"id" json:"id" toml:"id" yaml:"id"`
|
||||
BankName string `boil:"bank_name" json:"bank_name" toml:"bank_name" yaml:"bank_name"`
|
||||
BankAddress string `boil:"bank_address" json:"bank_address" toml:"bank_address" yaml:"bank_address"`
|
||||
BankAccountName string `boil:"bank_account_name" json:"bank_account_name" toml:"bank_account_name" yaml:"bank_account_name"`
|
||||
BankAccountNumber string `boil:"bank_account_number" json:"bank_account_number" toml:"bank_account_number" yaml:"bank_account_number"`
|
||||
BSB string `boil:"bsb" json:"bsb" toml:"bsb" yaml:"bsb"`
|
||||
SwiftCode string `boil:"swift_code" json:"swift_code" toml:"swift_code" yaml:"swift_code"`
|
||||
Iban string `boil:"iban" json:"iban" toml:"iban" yaml:"iban"`
|
||||
BankCode float64 `boil:"bank_code" json:"bank_code" toml:"bank_code" yaml:"bank_code"`
|
||||
WithdrawalHistoryID string `boil:"withdrawal_history_id" json:"withdrawal_history_id" toml:"withdrawal_history_id" yaml:"withdrawal_history_id"`
|
||||
|
||||
R *withdrawalFiatR `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
L withdrawalFiatL `boil:"-" json:"-" toml:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
var WithdrawalFiatColumns = struct {
|
||||
ID string
|
||||
BankName string
|
||||
BankAddress string
|
||||
BankAccountName string
|
||||
BankAccountNumber string
|
||||
BSB string
|
||||
SwiftCode string
|
||||
Iban string
|
||||
BankCode string
|
||||
WithdrawalHistoryID string
|
||||
}{
|
||||
ID: "id",
|
||||
BankName: "bank_name",
|
||||
BankAddress: "bank_address",
|
||||
BankAccountName: "bank_account_name",
|
||||
BankAccountNumber: "bank_account_number",
|
||||
BSB: "bsb",
|
||||
SwiftCode: "swift_code",
|
||||
Iban: "iban",
|
||||
BankCode: "bank_code",
|
||||
WithdrawalHistoryID: "withdrawal_history_id",
|
||||
}
|
||||
|
||||
// Generated where
|
||||
|
||||
var WithdrawalFiatWhere = struct {
|
||||
ID whereHelperint64
|
||||
BankName whereHelperstring
|
||||
BankAddress whereHelperstring
|
||||
BankAccountName whereHelperstring
|
||||
BankAccountNumber whereHelperstring
|
||||
BSB whereHelperstring
|
||||
SwiftCode whereHelperstring
|
||||
Iban whereHelperstring
|
||||
BankCode whereHelperfloat64
|
||||
WithdrawalHistoryID whereHelperstring
|
||||
}{
|
||||
ID: whereHelperint64{field: "\"withdrawal_fiat\".\"id\""},
|
||||
BankName: whereHelperstring{field: "\"withdrawal_fiat\".\"bank_name\""},
|
||||
BankAddress: whereHelperstring{field: "\"withdrawal_fiat\".\"bank_address\""},
|
||||
BankAccountName: whereHelperstring{field: "\"withdrawal_fiat\".\"bank_account_name\""},
|
||||
BankAccountNumber: whereHelperstring{field: "\"withdrawal_fiat\".\"bank_account_number\""},
|
||||
BSB: whereHelperstring{field: "\"withdrawal_fiat\".\"bsb\""},
|
||||
SwiftCode: whereHelperstring{field: "\"withdrawal_fiat\".\"swift_code\""},
|
||||
Iban: whereHelperstring{field: "\"withdrawal_fiat\".\"iban\""},
|
||||
BankCode: whereHelperfloat64{field: "\"withdrawal_fiat\".\"bank_code\""},
|
||||
WithdrawalHistoryID: whereHelperstring{field: "\"withdrawal_fiat\".\"withdrawal_history_id\""},
|
||||
}
|
||||
|
||||
// WithdrawalFiatRels is where relationship names are stored.
|
||||
var WithdrawalFiatRels = struct {
|
||||
WithdrawalHistory string
|
||||
}{
|
||||
WithdrawalHistory: "WithdrawalHistory",
|
||||
}
|
||||
|
||||
// withdrawalFiatR is where relationships are stored.
|
||||
type withdrawalFiatR struct {
|
||||
WithdrawalHistory *WithdrawalHistory
|
||||
}
|
||||
|
||||
// NewStruct creates a new relationship struct
|
||||
func (*withdrawalFiatR) NewStruct() *withdrawalFiatR {
|
||||
return &withdrawalFiatR{}
|
||||
}
|
||||
|
||||
// withdrawalFiatL is where Load methods for each relationship are stored.
|
||||
type withdrawalFiatL struct{}
|
||||
|
||||
var (
|
||||
withdrawalFiatAllColumns = []string{"id", "bank_name", "bank_address", "bank_account_name", "bank_account_number", "bsb", "swift_code", "iban", "bank_code", "withdrawal_history_id"}
|
||||
withdrawalFiatColumnsWithoutDefault = []string{"bank_name", "bank_address", "bank_account_name", "bank_account_number", "bsb", "swift_code", "iban", "bank_code", "withdrawal_history_id"}
|
||||
withdrawalFiatColumnsWithDefault = []string{"id"}
|
||||
withdrawalFiatPrimaryKeyColumns = []string{"id"}
|
||||
)
|
||||
|
||||
type (
|
||||
// WithdrawalFiatSlice is an alias for a slice of pointers to WithdrawalFiat.
|
||||
// This should generally be used opposed to []WithdrawalFiat.
|
||||
WithdrawalFiatSlice []*WithdrawalFiat
|
||||
// WithdrawalFiatHook is the signature for custom WithdrawalFiat hook methods
|
||||
WithdrawalFiatHook func(context.Context, boil.ContextExecutor, *WithdrawalFiat) error
|
||||
|
||||
withdrawalFiatQuery struct {
|
||||
*queries.Query
|
||||
}
|
||||
)
|
||||
|
||||
// Cache for insert, update and upsert
|
||||
var (
|
||||
withdrawalFiatType = reflect.TypeOf(&WithdrawalFiat{})
|
||||
withdrawalFiatMapping = queries.MakeStructMapping(withdrawalFiatType)
|
||||
withdrawalFiatPrimaryKeyMapping, _ = queries.BindMapping(withdrawalFiatType, withdrawalFiatMapping, withdrawalFiatPrimaryKeyColumns)
|
||||
withdrawalFiatInsertCacheMut sync.RWMutex
|
||||
withdrawalFiatInsertCache = make(map[string]insertCache)
|
||||
withdrawalFiatUpdateCacheMut sync.RWMutex
|
||||
withdrawalFiatUpdateCache = make(map[string]updateCache)
|
||||
withdrawalFiatUpsertCacheMut sync.RWMutex
|
||||
withdrawalFiatUpsertCache = make(map[string]insertCache)
|
||||
)
|
||||
|
||||
var (
|
||||
// Force time package dependency for automated UpdatedAt/CreatedAt.
|
||||
_ = time.Second
|
||||
// Force qmhelper dependency for where clause generation (which doesn't
|
||||
// always happen)
|
||||
_ = qmhelper.Where
|
||||
)
|
||||
|
||||
var withdrawalFiatBeforeInsertHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatBeforeUpdateHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatBeforeDeleteHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatBeforeUpsertHooks []WithdrawalFiatHook
|
||||
|
||||
var withdrawalFiatAfterInsertHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatAfterSelectHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatAfterUpdateHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatAfterDeleteHooks []WithdrawalFiatHook
|
||||
var withdrawalFiatAfterUpsertHooks []WithdrawalFiatHook
|
||||
|
||||
// doBeforeInsertHooks executes all "before insert" hooks.
|
||||
func (o *WithdrawalFiat) doBeforeInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatBeforeInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpdateHooks executes all "before Update" hooks.
|
||||
func (o *WithdrawalFiat) doBeforeUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatBeforeUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeDeleteHooks executes all "before Delete" hooks.
|
||||
func (o *WithdrawalFiat) doBeforeDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatBeforeDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doBeforeUpsertHooks executes all "before Upsert" hooks.
|
||||
func (o *WithdrawalFiat) doBeforeUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatBeforeUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterInsertHooks executes all "after Insert" hooks.
|
||||
func (o *WithdrawalFiat) doAfterInsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatAfterInsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterSelectHooks executes all "after Select" hooks.
|
||||
func (o *WithdrawalFiat) doAfterSelectHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatAfterSelectHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpdateHooks executes all "after Update" hooks.
|
||||
func (o *WithdrawalFiat) doAfterUpdateHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatAfterUpdateHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterDeleteHooks executes all "after Delete" hooks.
|
||||
func (o *WithdrawalFiat) doAfterDeleteHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatAfterDeleteHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// doAfterUpsertHooks executes all "after Upsert" hooks.
|
||||
func (o *WithdrawalFiat) doAfterUpsertHooks(ctx context.Context, exec boil.ContextExecutor) (err error) {
|
||||
if boil.HooksAreSkipped(ctx) {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, hook := range withdrawalFiatAfterUpsertHooks {
|
||||
if err := hook(ctx, exec, o); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddWithdrawalFiatHook registers your hook function for all future operations.
|
||||
func AddWithdrawalFiatHook(hookPoint boil.HookPoint, withdrawalFiatHook WithdrawalFiatHook) {
|
||||
switch hookPoint {
|
||||
case boil.BeforeInsertHook:
|
||||
withdrawalFiatBeforeInsertHooks = append(withdrawalFiatBeforeInsertHooks, withdrawalFiatHook)
|
||||
case boil.BeforeUpdateHook:
|
||||
withdrawalFiatBeforeUpdateHooks = append(withdrawalFiatBeforeUpdateHooks, withdrawalFiatHook)
|
||||
case boil.BeforeDeleteHook:
|
||||
withdrawalFiatBeforeDeleteHooks = append(withdrawalFiatBeforeDeleteHooks, withdrawalFiatHook)
|
||||
case boil.BeforeUpsertHook:
|
||||
withdrawalFiatBeforeUpsertHooks = append(withdrawalFiatBeforeUpsertHooks, withdrawalFiatHook)
|
||||
case boil.AfterInsertHook:
|
||||
withdrawalFiatAfterInsertHooks = append(withdrawalFiatAfterInsertHooks, withdrawalFiatHook)
|
||||
case boil.AfterSelectHook:
|
||||
withdrawalFiatAfterSelectHooks = append(withdrawalFiatAfterSelectHooks, withdrawalFiatHook)
|
||||
case boil.AfterUpdateHook:
|
||||
withdrawalFiatAfterUpdateHooks = append(withdrawalFiatAfterUpdateHooks, withdrawalFiatHook)
|
||||
case boil.AfterDeleteHook:
|
||||
withdrawalFiatAfterDeleteHooks = append(withdrawalFiatAfterDeleteHooks, withdrawalFiatHook)
|
||||
case boil.AfterUpsertHook:
|
||||
withdrawalFiatAfterUpsertHooks = append(withdrawalFiatAfterUpsertHooks, withdrawalFiatHook)
|
||||
}
|
||||
}
|
||||
|
||||
// One returns a single withdrawalFiat record from the query.
|
||||
func (q withdrawalFiatQuery) One(ctx context.Context, exec boil.ContextExecutor) (*WithdrawalFiat, error) {
|
||||
o := &WithdrawalFiat{}
|
||||
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Bind(ctx, exec, o)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "sqlite3: failed to execute a one query for withdrawal_fiat")
|
||||
}
|
||||
|
||||
if err := o.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return o, err
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// All returns all WithdrawalFiat records from the query.
|
||||
func (q withdrawalFiatQuery) All(ctx context.Context, exec boil.ContextExecutor) (WithdrawalFiatSlice, error) {
|
||||
var o []*WithdrawalFiat
|
||||
|
||||
err := q.Bind(ctx, exec, &o)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "sqlite3: failed to assign all query results to WithdrawalFiat slice")
|
||||
}
|
||||
|
||||
if len(withdrawalFiatAfterSelectHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doAfterSelectHooks(ctx, exec); err != nil {
|
||||
return o, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
// Count returns the count of all WithdrawalFiat records in the query.
|
||||
func (q withdrawalFiatQuery) Count(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to count withdrawal_fiat rows")
|
||||
}
|
||||
|
||||
return count, nil
|
||||
}
|
||||
|
||||
// Exists checks if the row exists in the table.
|
||||
func (q withdrawalFiatQuery) Exists(ctx context.Context, exec boil.ContextExecutor) (bool, error) {
|
||||
var count int64
|
||||
|
||||
queries.SetSelect(q.Query, nil)
|
||||
queries.SetCount(q.Query)
|
||||
queries.SetLimit(q.Query, 1)
|
||||
|
||||
err := q.Query.QueryRowContext(ctx, exec).Scan(&count)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "sqlite3: failed to check if withdrawal_fiat exists")
|
||||
}
|
||||
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
// WithdrawalHistory pointed to by the foreign key.
|
||||
func (o *WithdrawalFiat) WithdrawalHistory(mods ...qm.QueryMod) withdrawalHistoryQuery {
|
||||
queryMods := []qm.QueryMod{
|
||||
qm.Where("\"id\" = ?", o.WithdrawalHistoryID),
|
||||
}
|
||||
|
||||
queryMods = append(queryMods, mods...)
|
||||
|
||||
query := WithdrawalHistories(queryMods...)
|
||||
queries.SetFrom(query.Query, "\"withdrawal_history\"")
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
// LoadWithdrawalHistory allows an eager lookup of values, cached into the
|
||||
// loaded structs of the objects. This is for an N-1 relationship.
|
||||
func (withdrawalFiatL) LoadWithdrawalHistory(ctx context.Context, e boil.ContextExecutor, singular bool, maybeWithdrawalFiat interface{}, mods queries.Applicator) error {
|
||||
var slice []*WithdrawalFiat
|
||||
var object *WithdrawalFiat
|
||||
|
||||
if singular {
|
||||
object = maybeWithdrawalFiat.(*WithdrawalFiat)
|
||||
} else {
|
||||
slice = *maybeWithdrawalFiat.(*[]*WithdrawalFiat)
|
||||
}
|
||||
|
||||
args := make([]interface{}, 0, 1)
|
||||
if singular {
|
||||
if object.R == nil {
|
||||
object.R = &withdrawalFiatR{}
|
||||
}
|
||||
args = append(args, object.WithdrawalHistoryID)
|
||||
|
||||
} else {
|
||||
Outer:
|
||||
for _, obj := range slice {
|
||||
if obj.R == nil {
|
||||
obj.R = &withdrawalFiatR{}
|
||||
}
|
||||
|
||||
for _, a := range args {
|
||||
if a == obj.WithdrawalHistoryID {
|
||||
continue Outer
|
||||
}
|
||||
}
|
||||
|
||||
args = append(args, obj.WithdrawalHistoryID)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
query := NewQuery(qm.From(`withdrawal_history`), qm.WhereIn(`withdrawal_history.id in ?`, args...))
|
||||
if mods != nil {
|
||||
mods.Apply(query)
|
||||
}
|
||||
|
||||
results, err := query.QueryContext(ctx, e)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to eager load WithdrawalHistory")
|
||||
}
|
||||
|
||||
var resultSlice []*WithdrawalHistory
|
||||
if err = queries.Bind(results, &resultSlice); err != nil {
|
||||
return errors.Wrap(err, "failed to bind eager loaded slice WithdrawalHistory")
|
||||
}
|
||||
|
||||
if err = results.Close(); err != nil {
|
||||
return errors.Wrap(err, "failed to close results of eager load for withdrawal_history")
|
||||
}
|
||||
if err = results.Err(); err != nil {
|
||||
return errors.Wrap(err, "error occurred during iteration of eager loaded relations for withdrawal_history")
|
||||
}
|
||||
|
||||
if len(withdrawalFiatAfterSelectHooks) != 0 {
|
||||
for _, obj := range resultSlice {
|
||||
if err := obj.doAfterSelectHooks(ctx, e); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(resultSlice) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if singular {
|
||||
foreign := resultSlice[0]
|
||||
object.R.WithdrawalHistory = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &withdrawalHistoryR{}
|
||||
}
|
||||
foreign.R.WithdrawalFiats = append(foreign.R.WithdrawalFiats, object)
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, local := range slice {
|
||||
for _, foreign := range resultSlice {
|
||||
if local.WithdrawalHistoryID == foreign.ID {
|
||||
local.R.WithdrawalHistory = foreign
|
||||
if foreign.R == nil {
|
||||
foreign.R = &withdrawalHistoryR{}
|
||||
}
|
||||
foreign.R.WithdrawalFiats = append(foreign.R.WithdrawalFiats, local)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetWithdrawalHistory of the withdrawalFiat to the related item.
|
||||
// Sets o.R.WithdrawalHistory to related.
|
||||
// Adds o to related.R.WithdrawalFiats.
|
||||
func (o *WithdrawalFiat) SetWithdrawalHistory(ctx context.Context, exec boil.ContextExecutor, insert bool, related *WithdrawalHistory) error {
|
||||
var err error
|
||||
if insert {
|
||||
if err = related.Insert(ctx, exec, boil.Infer()); err != nil {
|
||||
return errors.Wrap(err, "failed to insert into foreign table")
|
||||
}
|
||||
}
|
||||
|
||||
updateQuery := fmt.Sprintf(
|
||||
"UPDATE \"withdrawal_fiat\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, []string{"withdrawal_history_id"}),
|
||||
strmangle.WhereClause("\"", "\"", 0, withdrawalFiatPrimaryKeyColumns),
|
||||
)
|
||||
values := []interface{}{related.ID, o.ID}
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, updateQuery)
|
||||
fmt.Fprintln(boil.DebugWriter, values)
|
||||
}
|
||||
|
||||
if _, err = exec.ExecContext(ctx, updateQuery, values...); err != nil {
|
||||
return errors.Wrap(err, "failed to update local table")
|
||||
}
|
||||
|
||||
o.WithdrawalHistoryID = related.ID
|
||||
if o.R == nil {
|
||||
o.R = &withdrawalFiatR{
|
||||
WithdrawalHistory: related,
|
||||
}
|
||||
} else {
|
||||
o.R.WithdrawalHistory = related
|
||||
}
|
||||
|
||||
if related.R == nil {
|
||||
related.R = &withdrawalHistoryR{
|
||||
WithdrawalFiats: WithdrawalFiatSlice{o},
|
||||
}
|
||||
} else {
|
||||
related.R.WithdrawalFiats = append(related.R.WithdrawalFiats, o)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithdrawalFiats retrieves all the records using an executor.
|
||||
func WithdrawalFiats(mods ...qm.QueryMod) withdrawalFiatQuery {
|
||||
mods = append(mods, qm.From("\"withdrawal_fiat\""))
|
||||
return withdrawalFiatQuery{NewQuery(mods...)}
|
||||
}
|
||||
|
||||
// FindWithdrawalFiat retrieves a single record by ID with an executor.
|
||||
// If selectCols is empty Find will return all columns.
|
||||
func FindWithdrawalFiat(ctx context.Context, exec boil.ContextExecutor, iD int64, selectCols ...string) (*WithdrawalFiat, error) {
|
||||
withdrawalFiatObj := &WithdrawalFiat{}
|
||||
|
||||
sel := "*"
|
||||
if len(selectCols) > 0 {
|
||||
sel = strings.Join(strmangle.IdentQuoteSlice(dialect.LQ, dialect.RQ, selectCols), ",")
|
||||
}
|
||||
query := fmt.Sprintf(
|
||||
"select %s from \"withdrawal_fiat\" where \"id\"=?", sel,
|
||||
)
|
||||
|
||||
q := queries.Raw(query, iD)
|
||||
|
||||
err := q.Bind(ctx, exec, withdrawalFiatObj)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, sql.ErrNoRows
|
||||
}
|
||||
return nil, errors.Wrap(err, "sqlite3: unable to select from withdrawal_fiat")
|
||||
}
|
||||
|
||||
return withdrawalFiatObj, nil
|
||||
}
|
||||
|
||||
// Insert a single record using an executor.
|
||||
// See boil.Columns.InsertColumnSet documentation to understand column list inference for inserts.
|
||||
func (o *WithdrawalFiat) Insert(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) error {
|
||||
if o == nil {
|
||||
return errors.New("sqlite3: no withdrawal_fiat provided for insertion")
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
if err := o.doBeforeInsertHooks(ctx, exec); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nzDefaults := queries.NonZeroDefaultSet(withdrawalFiatColumnsWithDefault, o)
|
||||
|
||||
key := makeCacheKey(columns, nzDefaults)
|
||||
withdrawalFiatInsertCacheMut.RLock()
|
||||
cache, cached := withdrawalFiatInsertCache[key]
|
||||
withdrawalFiatInsertCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl, returnColumns := columns.InsertColumnSet(
|
||||
withdrawalFiatAllColumns,
|
||||
withdrawalFiatColumnsWithDefault,
|
||||
withdrawalFiatColumnsWithoutDefault,
|
||||
nzDefaults,
|
||||
)
|
||||
|
||||
cache.valueMapping, err = queries.BindMapping(withdrawalFiatType, withdrawalFiatMapping, wl)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cache.retMapping, err = queries.BindMapping(withdrawalFiatType, withdrawalFiatMapping, returnColumns)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(wl) != 0 {
|
||||
cache.query = fmt.Sprintf("INSERT INTO \"withdrawal_fiat\" (\"%s\") %%sVALUES (%s)%%s", strings.Join(wl, "\",\""), strmangle.Placeholders(dialect.UseIndexPlaceholders, len(wl), 1, 1))
|
||||
} else {
|
||||
cache.query = "INSERT INTO \"withdrawal_fiat\" () VALUES ()%s%s"
|
||||
}
|
||||
|
||||
var queryOutput, queryReturning string
|
||||
|
||||
if len(cache.retMapping) != 0 {
|
||||
cache.retQuery = fmt.Sprintf("SELECT \"%s\" FROM \"withdrawal_fiat\" WHERE %s", strings.Join(returnColumns, "\",\""), strmangle.WhereClause("\"", "\"", 0, withdrawalFiatPrimaryKeyColumns))
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf(cache.query, queryOutput, queryReturning)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
vals := queries.ValuesFromMapping(value, cache.valueMapping)
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.query)
|
||||
fmt.Fprintln(boil.DebugWriter, vals)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, cache.query, vals...)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to insert into withdrawal_fiat")
|
||||
}
|
||||
|
||||
var lastID int64
|
||||
var identifierCols []interface{}
|
||||
|
||||
if len(cache.retMapping) == 0 {
|
||||
goto CacheNoHooks
|
||||
}
|
||||
|
||||
lastID, err = result.LastInsertId()
|
||||
if err != nil {
|
||||
return ErrSyncFail
|
||||
}
|
||||
|
||||
o.ID = int64(lastID)
|
||||
if lastID != 0 && len(cache.retMapping) == 1 && cache.retMapping[0] == withdrawalFiatMapping["ID"] {
|
||||
goto CacheNoHooks
|
||||
}
|
||||
|
||||
identifierCols = []interface{}{
|
||||
o.ID,
|
||||
}
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.retQuery)
|
||||
fmt.Fprintln(boil.DebugWriter, identifierCols...)
|
||||
}
|
||||
|
||||
err = exec.QueryRowContext(ctx, cache.retQuery, identifierCols...).Scan(queries.PtrsFromMapping(value, cache.retMapping)...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to populate default values for withdrawal_fiat")
|
||||
}
|
||||
|
||||
CacheNoHooks:
|
||||
if !cached {
|
||||
withdrawalFiatInsertCacheMut.Lock()
|
||||
withdrawalFiatInsertCache[key] = cache
|
||||
withdrawalFiatInsertCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return o.doAfterInsertHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// Update uses an executor to update the WithdrawalFiat.
|
||||
// See boil.Columns.UpdateColumnSet documentation to understand column list inference for updates.
|
||||
// Update does not automatically update the record in case of default values. Use .Reload() to refresh the records.
|
||||
func (o *WithdrawalFiat) Update(ctx context.Context, exec boil.ContextExecutor, columns boil.Columns) (int64, error) {
|
||||
var err error
|
||||
if err = o.doBeforeUpdateHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
key := makeCacheKey(columns, nil)
|
||||
withdrawalFiatUpdateCacheMut.RLock()
|
||||
cache, cached := withdrawalFiatUpdateCache[key]
|
||||
withdrawalFiatUpdateCacheMut.RUnlock()
|
||||
|
||||
if !cached {
|
||||
wl := columns.UpdateColumnSet(
|
||||
withdrawalFiatAllColumns,
|
||||
withdrawalFiatPrimaryKeyColumns,
|
||||
)
|
||||
|
||||
if len(wl) == 0 {
|
||||
return 0, errors.New("sqlite3: unable to update withdrawal_fiat, could not build whitelist")
|
||||
}
|
||||
|
||||
cache.query = fmt.Sprintf("UPDATE \"withdrawal_fiat\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, wl),
|
||||
strmangle.WhereClause("\"", "\"", 0, withdrawalFiatPrimaryKeyColumns),
|
||||
)
|
||||
cache.valueMapping, err = queries.BindMapping(withdrawalFiatType, withdrawalFiatMapping, append(wl, withdrawalFiatPrimaryKeyColumns...))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
values := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), cache.valueMapping)
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, cache.query)
|
||||
fmt.Fprintln(boil.DebugWriter, values)
|
||||
}
|
||||
|
||||
var result sql.Result
|
||||
result, err = exec.ExecContext(ctx, cache.query, values...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update withdrawal_fiat row")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by update for withdrawal_fiat")
|
||||
}
|
||||
|
||||
if !cached {
|
||||
withdrawalFiatUpdateCacheMut.Lock()
|
||||
withdrawalFiatUpdateCache[key] = cache
|
||||
withdrawalFiatUpdateCacheMut.Unlock()
|
||||
}
|
||||
|
||||
return rowsAff, o.doAfterUpdateHooks(ctx, exec)
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values.
|
||||
func (q withdrawalFiatQuery) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
queries.SetUpdate(q.Query, cols)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update all for withdrawal_fiat")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected for withdrawal_fiat")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// UpdateAll updates all rows with the specified column values, using an executor.
|
||||
func (o WithdrawalFiatSlice) UpdateAll(ctx context.Context, exec boil.ContextExecutor, cols M) (int64, error) {
|
||||
ln := int64(len(o))
|
||||
if ln == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(cols) == 0 {
|
||||
return 0, errors.New("sqlite3: update all requires at least one column argument")
|
||||
}
|
||||
|
||||
colNames := make([]string, len(cols))
|
||||
args := make([]interface{}, len(cols))
|
||||
|
||||
i := 0
|
||||
for name, value := range cols {
|
||||
colNames[i] = name
|
||||
args[i] = value
|
||||
i++
|
||||
}
|
||||
|
||||
// Append all of the primary key values for each column
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalFiatPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := fmt.Sprintf("UPDATE \"withdrawal_fiat\" SET %s WHERE %s",
|
||||
strmangle.SetParamNames("\"", "\"", 0, colNames),
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalFiatPrimaryKeyColumns, len(o)))
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args...)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to update all in withdrawalFiat slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to retrieve rows affected all in update all withdrawalFiat")
|
||||
}
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Delete deletes a single WithdrawalFiat record with an executor.
|
||||
// Delete will match against the primary key column to find the record to delete.
|
||||
func (o *WithdrawalFiat) Delete(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if o == nil {
|
||||
return 0, errors.New("sqlite3: no WithdrawalFiat provided for delete")
|
||||
}
|
||||
|
||||
if err := o.doBeforeDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
args := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(o)), withdrawalFiatPrimaryKeyMapping)
|
||||
sql := "DELETE FROM \"withdrawal_fiat\" WHERE \"id\"=?"
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args...)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete from withdrawal_fiat")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by delete for withdrawal_fiat")
|
||||
}
|
||||
|
||||
if err := o.doAfterDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all matching rows.
|
||||
func (q withdrawalFiatQuery) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if q.Query == nil {
|
||||
return 0, errors.New("sqlite3: no withdrawalFiatQuery provided for delete all")
|
||||
}
|
||||
|
||||
queries.SetDelete(q.Query)
|
||||
|
||||
result, err := q.Query.ExecContext(ctx, exec)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete all from withdrawal_fiat")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for withdrawal_fiat")
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// DeleteAll deletes all rows in the slice, using an executor.
|
||||
func (o WithdrawalFiatSlice) DeleteAll(ctx context.Context, exec boil.ContextExecutor) (int64, error) {
|
||||
if len(o) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
if len(withdrawalFiatBeforeDeleteHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doBeforeDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var args []interface{}
|
||||
for _, obj := range o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalFiatPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "DELETE FROM \"withdrawal_fiat\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalFiatPrimaryKeyColumns, len(o))
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, args)
|
||||
}
|
||||
|
||||
result, err := exec.ExecContext(ctx, sql, args...)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: unable to delete all from withdrawalFiat slice")
|
||||
}
|
||||
|
||||
rowsAff, err := result.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "sqlite3: failed to get rows affected by deleteall for withdrawal_fiat")
|
||||
}
|
||||
|
||||
if len(withdrawalFiatAfterDeleteHooks) != 0 {
|
||||
for _, obj := range o {
|
||||
if err := obj.doAfterDeleteHooks(ctx, exec); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rowsAff, nil
|
||||
}
|
||||
|
||||
// Reload refetches the object from the database
|
||||
// using the primary keys with an executor.
|
||||
func (o *WithdrawalFiat) Reload(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
ret, err := FindWithdrawalFiat(ctx, exec, o.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*o = *ret
|
||||
return nil
|
||||
}
|
||||
|
||||
// ReloadAll refetches every row with matching primary key column values
|
||||
// and overwrites the original object slice with the newly updated slice.
|
||||
func (o *WithdrawalFiatSlice) ReloadAll(ctx context.Context, exec boil.ContextExecutor) error {
|
||||
if o == nil || len(*o) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{}
|
||||
var args []interface{}
|
||||
for _, obj := range *o {
|
||||
pkeyArgs := queries.ValuesFromMapping(reflect.Indirect(reflect.ValueOf(obj)), withdrawalFiatPrimaryKeyMapping)
|
||||
args = append(args, pkeyArgs...)
|
||||
}
|
||||
|
||||
sql := "SELECT \"withdrawal_fiat\".* FROM \"withdrawal_fiat\" WHERE " +
|
||||
strmangle.WhereClauseRepeated(string(dialect.LQ), string(dialect.RQ), 0, withdrawalFiatPrimaryKeyColumns, len(*o))
|
||||
|
||||
q := queries.Raw(sql, args...)
|
||||
|
||||
err := q.Bind(ctx, exec, &slice)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "sqlite3: unable to reload all in WithdrawalFiatSlice")
|
||||
}
|
||||
|
||||
*o = slice
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// WithdrawalFiatExists checks if the WithdrawalFiat row exists.
|
||||
func WithdrawalFiatExists(ctx context.Context, exec boil.ContextExecutor, iD int64) (bool, error) {
|
||||
var exists bool
|
||||
sql := "select exists(select 1 from \"withdrawal_fiat\" where \"id\"=? limit 1)"
|
||||
|
||||
if boil.DebugMode {
|
||||
fmt.Fprintln(boil.DebugWriter, sql)
|
||||
fmt.Fprintln(boil.DebugWriter, iD)
|
||||
}
|
||||
|
||||
row := exec.QueryRowContext(ctx, sql, iD)
|
||||
|
||||
err := row.Scan(&exists)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "sqlite3: unable to check if withdrawal_fiat exists")
|
||||
}
|
||||
|
||||
return exists, nil
|
||||
}
|
||||
793
database/models/sqlite3/withdrawal_fiat_test.go
Normal file
793
database/models/sqlite3/withdrawal_fiat_test.go
Normal file
@@ -0,0 +1,793 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/randomize"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testWithdrawalFiats(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := WithdrawalFiats()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := WithdrawalFiats().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := WithdrawalFiatExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if WithdrawalFiat exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected WithdrawalFiatExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
withdrawalFiatFound, err := FindWithdrawalFiat(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if withdrawalFiatFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = WithdrawalFiats().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := WithdrawalFiats().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
withdrawalFiatOne := &WithdrawalFiat{}
|
||||
withdrawalFiatTwo := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, withdrawalFiatOne, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalFiatTwo, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalFiatOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalFiatTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalFiats().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
withdrawalFiatOne := &WithdrawalFiat{}
|
||||
withdrawalFiatTwo := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, withdrawalFiatOne, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalFiatTwo, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalFiatOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalFiatTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalFiatAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalFiat) error {
|
||||
*o = WithdrawalFiat{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &WithdrawalFiat{}
|
||||
o := &WithdrawalFiat{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat object: %s", err)
|
||||
}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeInsertHook, withdrawalFiatBeforeInsertHook)
|
||||
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeInsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterInsertHook, withdrawalFiatAfterInsertHook)
|
||||
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterInsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterSelectHook, withdrawalFiatAfterSelectHook)
|
||||
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterSelectHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeUpdateHook, withdrawalFiatBeforeUpdateHook)
|
||||
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeUpdateHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterUpdateHook, withdrawalFiatAfterUpdateHook)
|
||||
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterUpdateHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeDeleteHook, withdrawalFiatBeforeDeleteHook)
|
||||
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeDeleteHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterDeleteHook, withdrawalFiatAfterDeleteHook)
|
||||
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterDeleteHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.BeforeUpsertHook, withdrawalFiatBeforeUpsertHook)
|
||||
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatBeforeUpsertHooks = []WithdrawalFiatHook{}
|
||||
|
||||
AddWithdrawalFiatHook(boil.AfterUpsertHook, withdrawalFiatAfterUpsertHook)
|
||||
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalFiatAfterUpsertHooks = []WithdrawalFiatHook{}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(withdrawalFiatColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatToOneWithdrawalHistoryUsingWithdrawalHistory(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var local WithdrawalFiat
|
||||
var foreign WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err := randomize.Struct(seed, &local, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
if err := randomize.Struct(seed, &foreign, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := foreign.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
local.WithdrawalHistoryID = foreign.ID
|
||||
if err := local.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := local.WithdrawalHistory().One(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if check.ID != foreign.ID {
|
||||
t.Errorf("want: %v, got %v", foreign.ID, check.ID)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{&local}
|
||||
if err = local.L.LoadWithdrawalHistory(ctx, tx, false, (*[]*WithdrawalFiat)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalHistory == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
|
||||
local.R.WithdrawalHistory = nil
|
||||
if err = local.L.LoadWithdrawalHistory(ctx, tx, true, &local, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if local.R.WithdrawalHistory == nil {
|
||||
t.Error("struct should have been eager loaded")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatToOneSetOpWithdrawalHistoryUsingWithdrawalHistory(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalFiat
|
||||
var b, c WithdrawalHistory
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalFiatDBTypes, false, strmangle.SetComplement(withdrawalFiatPrimaryKeyColumns, withdrawalFiatColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &b, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for i, x := range []*WithdrawalHistory{&b, &c} {
|
||||
err = a.SetWithdrawalHistory(ctx, tx, i != 0, x)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if a.R.WithdrawalHistory != x {
|
||||
t.Error("relationship struct not set to correct value")
|
||||
}
|
||||
|
||||
if x.R.WithdrawalFiats[0] != &a {
|
||||
t.Error("failed to append to foreign relationship struct")
|
||||
}
|
||||
if a.WithdrawalHistoryID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalHistoryID)
|
||||
}
|
||||
|
||||
zero := reflect.Zero(reflect.TypeOf(a.WithdrawalHistoryID))
|
||||
reflect.Indirect(reflect.ValueOf(&a.WithdrawalHistoryID)).Set(zero)
|
||||
|
||||
if err = a.Reload(ctx, tx); err != nil {
|
||||
t.Fatal("failed to reload", err)
|
||||
}
|
||||
|
||||
if a.WithdrawalHistoryID != x.ID {
|
||||
t.Error("foreign key was wrong value", a.WithdrawalHistoryID, x.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalFiats().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
withdrawalFiatDBTypes = map[string]string{`ID`: `INTEGER`, `BankName`: `TEXT`, `BankAddress`: `TEXT`, `BankAccountName`: `TEXT`, `BankAccountNumber`: `TEXT`, `BSB`: `TEXT`, `SwiftCode`: `TEXT`, `Iban`: `TEXT`, `BankCode`: `REAL`, `WithdrawalHistoryID`: `TEXT`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testWithdrawalFiatsUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(withdrawalFiatAllColumns) == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalFiatsSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalFiatAllColumns) == len(withdrawalFiatPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalFiat{}
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalFiatDBTypes, true, withdrawalFiatPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalFiat struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(withdrawalFiatAllColumns, withdrawalFiatPrimaryKeyColumns) {
|
||||
fields = withdrawalFiatAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
withdrawalFiatAllColumns,
|
||||
withdrawalFiatPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := WithdrawalFiatSlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
1151
database/models/sqlite3/withdrawal_history.go
Normal file
1151
database/models/sqlite3/withdrawal_history.go
Normal file
File diff suppressed because it is too large
Load Diff
991
database/models/sqlite3/withdrawal_history_test.go
Normal file
991
database/models/sqlite3/withdrawal_history_test.go
Normal file
@@ -0,0 +1,991 @@
|
||||
// Code generated by SQLBoiler 3.5.0-gct (https://github.com/thrasher-corp/sqlboiler). DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package sqlite3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries"
|
||||
"github.com/thrasher-corp/sqlboiler/randomize"
|
||||
"github.com/thrasher-corp/sqlboiler/strmangle"
|
||||
)
|
||||
|
||||
var (
|
||||
// Relationships sometimes use the reflection helper queries.Equal/queries.Assign
|
||||
// so force a package dependency in case they don't.
|
||||
_ = queries.Equal
|
||||
)
|
||||
|
||||
func testWithdrawalHistories(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
query := WithdrawalHistories()
|
||||
|
||||
if query.Query == nil {
|
||||
t.Error("expected a query, got nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Delete(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesQueryDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if rowsAff, err := WithdrawalHistories().DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesSliceDeleteAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalHistorySlice{o}
|
||||
|
||||
if rowsAff, err := slice.DeleteAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only have deleted one row, but affected:", rowsAff)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 0 {
|
||||
t.Error("want zero records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesExists(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
e, err := WithdrawalHistoryExists(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Unable to check if WithdrawalHistory exists: %s", err)
|
||||
}
|
||||
if !e {
|
||||
t.Errorf("Expected WithdrawalHistoryExists to return true, but got false.")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesFind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
withdrawalHistoryFound, err := FindWithdrawalHistory(ctx, tx, o.ID)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if withdrawalHistoryFound == nil {
|
||||
t.Error("want a record, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesBind(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = WithdrawalHistories().Bind(ctx, tx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesOne(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if x, err := WithdrawalHistories().One(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
} else if x == nil {
|
||||
t.Error("expected to get a non nil record")
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
withdrawalHistoryOne := &WithdrawalHistory{}
|
||||
withdrawalHistoryTwo := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, withdrawalHistoryOne, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalHistoryTwo, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalHistoryOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalHistoryTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalHistories().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 2 {
|
||||
t.Error("want 2 records, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesCount(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
seed := randomize.NewSeed()
|
||||
withdrawalHistoryOne := &WithdrawalHistory{}
|
||||
withdrawalHistoryTwo := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, withdrawalHistoryOne, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
if err = randomize.Struct(seed, withdrawalHistoryTwo, withdrawalHistoryDBTypes, false, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = withdrawalHistoryOne.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err = withdrawalHistoryTwo.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 2 {
|
||||
t.Error("want 2 records, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawalHistoryBeforeInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryAfterInsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryAfterSelectHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryBeforeUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryAfterUpdateHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryBeforeDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryAfterDeleteHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryBeforeUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func withdrawalHistoryAfterUpsertHook(ctx context.Context, e boil.ContextExecutor, o *WithdrawalHistory) error {
|
||||
*o = WithdrawalHistory{}
|
||||
return nil
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesHooks(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
empty := &WithdrawalHistory{}
|
||||
o := &WithdrawalHistory{}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, false); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory object: %s", err)
|
||||
}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.BeforeInsertHook, withdrawalHistoryBeforeInsertHook)
|
||||
if err = o.doBeforeInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryBeforeInsertHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.AfterInsertHook, withdrawalHistoryAfterInsertHook)
|
||||
if err = o.doAfterInsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryAfterInsertHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.AfterSelectHook, withdrawalHistoryAfterSelectHook)
|
||||
if err = o.doAfterSelectHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryAfterSelectHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.BeforeUpdateHook, withdrawalHistoryBeforeUpdateHook)
|
||||
if err = o.doBeforeUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryBeforeUpdateHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.AfterUpdateHook, withdrawalHistoryAfterUpdateHook)
|
||||
if err = o.doAfterUpdateHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryAfterUpdateHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.BeforeDeleteHook, withdrawalHistoryBeforeDeleteHook)
|
||||
if err = o.doBeforeDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryBeforeDeleteHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.AfterDeleteHook, withdrawalHistoryAfterDeleteHook)
|
||||
if err = o.doAfterDeleteHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryAfterDeleteHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.BeforeUpsertHook, withdrawalHistoryBeforeUpsertHook)
|
||||
if err = o.doBeforeUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryBeforeUpsertHooks = []WithdrawalHistoryHook{}
|
||||
|
||||
AddWithdrawalHistoryHook(boil.AfterUpsertHook, withdrawalHistoryAfterUpsertHook)
|
||||
if err = o.doAfterUpsertHooks(ctx, nil); err != nil {
|
||||
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
|
||||
}
|
||||
if !reflect.DeepEqual(o, empty) {
|
||||
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
|
||||
}
|
||||
withdrawalHistoryAfterUpsertHooks = []WithdrawalHistoryHook{}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesInsert(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesInsertWhitelist(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Whitelist(withdrawalHistoryColumnsWithoutDefault...)); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoryToManyWithdrawalCryptos(t *testing.T) {
|
||||
var err error
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalHistory
|
||||
var b, c WithdrawalCrypto
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, &b, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalCryptoDBTypes, false, withdrawalCryptoColumnsWithDefault...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b.WithdrawalHistoryID = a.ID
|
||||
c.WithdrawalHistoryID = a.ID
|
||||
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := a.WithdrawalCryptos().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bFound, cFound := false, false
|
||||
for _, v := range check {
|
||||
if v.WithdrawalHistoryID == b.WithdrawalHistoryID {
|
||||
bFound = true
|
||||
}
|
||||
if v.WithdrawalHistoryID == c.WithdrawalHistoryID {
|
||||
cFound = true
|
||||
}
|
||||
}
|
||||
|
||||
if !bFound {
|
||||
t.Error("expected to find b")
|
||||
}
|
||||
if !cFound {
|
||||
t.Error("expected to find c")
|
||||
}
|
||||
|
||||
slice := WithdrawalHistorySlice{&a}
|
||||
if err = a.L.LoadWithdrawalCryptos(ctx, tx, false, (*[]*WithdrawalHistory)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := len(a.R.WithdrawalCryptos); got != 2 {
|
||||
t.Error("number of eager loaded records wrong, got:", got)
|
||||
}
|
||||
|
||||
a.R.WithdrawalCryptos = nil
|
||||
if err = a.L.LoadWithdrawalCryptos(ctx, tx, true, &a, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := len(a.R.WithdrawalCryptos); got != 2 {
|
||||
t.Error("number of eager loaded records wrong, got:", got)
|
||||
}
|
||||
|
||||
if t.Failed() {
|
||||
t.Logf("%#v", check)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoryToManyWithdrawalFiats(t *testing.T) {
|
||||
var err error
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalHistory
|
||||
var b, c WithdrawalFiat
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, &b, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = randomize.Struct(seed, &c, withdrawalFiatDBTypes, false, withdrawalFiatColumnsWithDefault...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
b.WithdrawalHistoryID = a.ID
|
||||
c.WithdrawalHistoryID = a.ID
|
||||
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
check, err := a.WithdrawalFiats().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
bFound, cFound := false, false
|
||||
for _, v := range check {
|
||||
if v.WithdrawalHistoryID == b.WithdrawalHistoryID {
|
||||
bFound = true
|
||||
}
|
||||
if v.WithdrawalHistoryID == c.WithdrawalHistoryID {
|
||||
cFound = true
|
||||
}
|
||||
}
|
||||
|
||||
if !bFound {
|
||||
t.Error("expected to find b")
|
||||
}
|
||||
if !cFound {
|
||||
t.Error("expected to find c")
|
||||
}
|
||||
|
||||
slice := WithdrawalHistorySlice{&a}
|
||||
if err = a.L.LoadWithdrawalFiats(ctx, tx, false, (*[]*WithdrawalHistory)(&slice), nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := len(a.R.WithdrawalFiats); got != 2 {
|
||||
t.Error("number of eager loaded records wrong, got:", got)
|
||||
}
|
||||
|
||||
a.R.WithdrawalFiats = nil
|
||||
if err = a.L.LoadWithdrawalFiats(ctx, tx, true, &a, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := len(a.R.WithdrawalFiats); got != 2 {
|
||||
t.Error("number of eager loaded records wrong, got:", got)
|
||||
}
|
||||
|
||||
if t.Failed() {
|
||||
t.Logf("%#v", check)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoryToManyAddOpWithdrawalCryptos(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalHistory
|
||||
var b, c, d, e WithdrawalCrypto
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foreigners := []*WithdrawalCrypto{&b, &c, &d, &e}
|
||||
for _, x := range foreigners {
|
||||
if err = randomize.Struct(seed, x, withdrawalCryptoDBTypes, false, strmangle.SetComplement(withdrawalCryptoPrimaryKeyColumns, withdrawalCryptoColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foreignersSplitByInsertion := [][]*WithdrawalCrypto{
|
||||
{&b, &c},
|
||||
{&d, &e},
|
||||
}
|
||||
|
||||
for i, x := range foreignersSplitByInsertion {
|
||||
err = a.AddWithdrawalCryptos(ctx, tx, i != 0, x...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
first := x[0]
|
||||
second := x[1]
|
||||
|
||||
if a.ID != first.WithdrawalHistoryID {
|
||||
t.Error("foreign key was wrong value", a.ID, first.WithdrawalHistoryID)
|
||||
}
|
||||
if a.ID != second.WithdrawalHistoryID {
|
||||
t.Error("foreign key was wrong value", a.ID, second.WithdrawalHistoryID)
|
||||
}
|
||||
|
||||
if first.R.WithdrawalHistory != &a {
|
||||
t.Error("relationship was not added properly to the foreign slice")
|
||||
}
|
||||
if second.R.WithdrawalHistory != &a {
|
||||
t.Error("relationship was not added properly to the foreign slice")
|
||||
}
|
||||
|
||||
if a.R.WithdrawalCryptos[i*2] != first {
|
||||
t.Error("relationship struct slice not set to correct value")
|
||||
}
|
||||
if a.R.WithdrawalCryptos[i*2+1] != second {
|
||||
t.Error("relationship struct slice not set to correct value")
|
||||
}
|
||||
|
||||
count, err := a.WithdrawalCryptos().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want := int64((i + 1) * 2); count != want {
|
||||
t.Error("want", want, "got", count)
|
||||
}
|
||||
}
|
||||
}
|
||||
func testWithdrawalHistoryToManyAddOpWithdrawalFiats(t *testing.T) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
var a WithdrawalHistory
|
||||
var b, c, d, e WithdrawalFiat
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
if err = randomize.Struct(seed, &a, withdrawalHistoryDBTypes, false, strmangle.SetComplement(withdrawalHistoryPrimaryKeyColumns, withdrawalHistoryColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foreigners := []*WithdrawalFiat{&b, &c, &d, &e}
|
||||
for _, x := range foreigners {
|
||||
if err = randomize.Struct(seed, x, withdrawalFiatDBTypes, false, strmangle.SetComplement(withdrawalFiatPrimaryKeyColumns, withdrawalFiatColumnsWithoutDefault)...); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := a.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = b.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err = c.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
foreignersSplitByInsertion := [][]*WithdrawalFiat{
|
||||
{&b, &c},
|
||||
{&d, &e},
|
||||
}
|
||||
|
||||
for i, x := range foreignersSplitByInsertion {
|
||||
err = a.AddWithdrawalFiats(ctx, tx, i != 0, x...)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
first := x[0]
|
||||
second := x[1]
|
||||
|
||||
if a.ID != first.WithdrawalHistoryID {
|
||||
t.Error("foreign key was wrong value", a.ID, first.WithdrawalHistoryID)
|
||||
}
|
||||
if a.ID != second.WithdrawalHistoryID {
|
||||
t.Error("foreign key was wrong value", a.ID, second.WithdrawalHistoryID)
|
||||
}
|
||||
|
||||
if first.R.WithdrawalHistory != &a {
|
||||
t.Error("relationship was not added properly to the foreign slice")
|
||||
}
|
||||
if second.R.WithdrawalHistory != &a {
|
||||
t.Error("relationship was not added properly to the foreign slice")
|
||||
}
|
||||
|
||||
if a.R.WithdrawalFiats[i*2] != first {
|
||||
t.Error("relationship struct slice not set to correct value")
|
||||
}
|
||||
if a.R.WithdrawalFiats[i*2+1] != second {
|
||||
t.Error("relationship struct slice not set to correct value")
|
||||
}
|
||||
|
||||
count, err := a.WithdrawalFiats().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want := int64((i + 1) * 2); count != want {
|
||||
t.Error("want", want, "got", count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesReload(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err = o.Reload(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesReloadAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice := WithdrawalHistorySlice{o}
|
||||
|
||||
if err = slice.ReloadAll(ctx, tx); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesSelect(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
slice, err := WithdrawalHistories().All(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if len(slice) != 1 {
|
||||
t.Error("want one record, got:", len(slice))
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
withdrawalHistoryDBTypes = map[string]string{`ID`: `TEXT`, `Exchange`: `TEXT`, `ExchangeID`: `TEXT`, `Status`: `TEXT`, `Currency`: `TEXT`, `Amount`: `REAL`, `Description`: `TEXT`, `WithdrawType`: `INTEGER`, `CreatedAt`: `TIMESTAMP`, `UpdatedAt`: `TIMESTAMP`}
|
||||
_ = bytes.MinRead
|
||||
)
|
||||
|
||||
func testWithdrawalHistoriesUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if 0 == len(withdrawalHistoryPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with no primary key columns")
|
||||
}
|
||||
if len(withdrawalHistoryAllColumns) == len(withdrawalHistoryPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
if rowsAff, err := o.Update(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("should only affect one row but affected", rowsAff)
|
||||
}
|
||||
}
|
||||
|
||||
func testWithdrawalHistoriesSliceUpdateAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if len(withdrawalHistoryAllColumns) == len(withdrawalHistoryPrimaryKeyColumns) {
|
||||
t.Skip("Skipping table with only primary key columns")
|
||||
}
|
||||
|
||||
seed := randomize.NewSeed()
|
||||
var err error
|
||||
o := &WithdrawalHistory{}
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryColumnsWithDefault...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
tx := MustTx(boil.BeginTx(ctx, nil))
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
if err = o.Insert(ctx, tx, boil.Infer()); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
count, err := WithdrawalHistories().Count(ctx, tx)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if count != 1 {
|
||||
t.Error("want one record, got:", count)
|
||||
}
|
||||
|
||||
if err = randomize.Struct(seed, o, withdrawalHistoryDBTypes, true, withdrawalHistoryPrimaryKeyColumns...); err != nil {
|
||||
t.Errorf("Unable to randomize WithdrawalHistory struct: %s", err)
|
||||
}
|
||||
|
||||
// Remove Primary keys and unique columns from what we plan to update
|
||||
var fields []string
|
||||
if strmangle.StringSliceMatch(withdrawalHistoryAllColumns, withdrawalHistoryPrimaryKeyColumns) {
|
||||
fields = withdrawalHistoryAllColumns
|
||||
} else {
|
||||
fields = strmangle.SetComplement(
|
||||
withdrawalHistoryAllColumns,
|
||||
withdrawalHistoryPrimaryKeyColumns,
|
||||
)
|
||||
}
|
||||
|
||||
value := reflect.Indirect(reflect.ValueOf(o))
|
||||
typ := reflect.TypeOf(o).Elem()
|
||||
n := typ.NumField()
|
||||
|
||||
updateMap := M{}
|
||||
for _, col := range fields {
|
||||
for i := 0; i < n; i++ {
|
||||
f := typ.Field(i)
|
||||
if f.Tag.Get("boil") == col {
|
||||
updateMap[col] = value.Field(i).Interface()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
slice := WithdrawalHistorySlice{o}
|
||||
if rowsAff, err := slice.UpdateAll(ctx, tx, updateMap); err != nil {
|
||||
t.Error(err)
|
||||
} else if rowsAff != 1 {
|
||||
t.Error("wanted one record updated but got", rowsAff)
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package audit
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/database"
|
||||
@@ -71,7 +70,7 @@ func Event(id, msgtype, message string) {
|
||||
// GetEvent () returns list of order events matching query
|
||||
func GetEvent(startTime, endTime time.Time, order string, limit int) (interface{}, error) {
|
||||
if database.DB.SQL == nil {
|
||||
return nil, errors.New("database is nil")
|
||||
return nil, database.ErrDatabaseSupportDisabled
|
||||
}
|
||||
|
||||
query := qm.Where("created_at BETWEEN ? AND ?", startTime, endTime)
|
||||
|
||||
@@ -50,7 +50,6 @@ func TestScript(t *testing.T) {
|
||||
Driver: database.DBSQLite3,
|
||||
ConnectionDetails: drivers.ConnectionDetails{Database: "./testdb"},
|
||||
},
|
||||
|
||||
writeScript,
|
||||
testhelpers.CloseDatabase,
|
||||
nil,
|
||||
|
||||
389
database/repository/withdraw/withdraw.go
Normal file
389
database/repository/withdraw/withdraw.go
Normal file
@@ -0,0 +1,389 @@
|
||||
package withdraw
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/database"
|
||||
modelPSQL "github.com/thrasher-corp/gocryptotrader/database/models/postgres"
|
||||
modelSQLite "github.com/thrasher-corp/gocryptotrader/database/models/sqlite3"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/repository"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
"github.com/thrasher-corp/sqlboiler/boil"
|
||||
"github.com/thrasher-corp/sqlboiler/queries/qm"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoResults = errors.New("no results found")
|
||||
)
|
||||
|
||||
// Event stores Withdrawal Response details in database
|
||||
func Event(res *withdraw.Response) {
|
||||
if database.DB.SQL == nil {
|
||||
return
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = boil.SkipTimestamps(ctx)
|
||||
|
||||
tx, err := database.DB.SQL.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event transaction being failed: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if repository.GetSQLDialect() == database.DBSQLite3 {
|
||||
err = addSQLiteEvent(ctx, tx, res)
|
||||
} else {
|
||||
err = addPSQLEvent(ctx, tx, res)
|
||||
}
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Transaction rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Transaction commit failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Transaction rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func addPSQLEvent(ctx context.Context, tx *sql.Tx, res *withdraw.Response) (err error) {
|
||||
var tempEvent = modelPSQL.WithdrawalHistory{
|
||||
Exchange: res.Exchange.Name,
|
||||
ExchangeID: res.Exchange.ID,
|
||||
Status: res.Exchange.Status,
|
||||
Currency: res.RequestDetails.Currency.String(),
|
||||
Amount: res.RequestDetails.Amount,
|
||||
WithdrawType: int(res.RequestDetails.Type),
|
||||
}
|
||||
|
||||
if res.RequestDetails.Description != "" {
|
||||
tempEvent.Description.SetValid(res.RequestDetails.Description)
|
||||
}
|
||||
|
||||
err = tempEvent.Insert(ctx, tx, boil.Infer())
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if res.RequestDetails.Type == withdraw.Fiat {
|
||||
fiatEvent := &modelPSQL.WithdrawalFiat{
|
||||
BankName: res.RequestDetails.Fiat.Bank.BankName,
|
||||
BankAddress: res.RequestDetails.Fiat.Bank.BankAddress,
|
||||
BankAccountName: res.RequestDetails.Fiat.Bank.AccountName,
|
||||
BankAccountNumber: res.RequestDetails.Fiat.Bank.AccountNumber,
|
||||
BSB: res.RequestDetails.Fiat.Bank.BSBNumber,
|
||||
SwiftCode: res.RequestDetails.Fiat.Bank.SWIFTCode,
|
||||
Iban: res.RequestDetails.Fiat.Bank.IBAN,
|
||||
}
|
||||
err = tempEvent.SetWithdrawalFiatWithdrawalFiats(ctx, tx, true, fiatEvent)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if res.RequestDetails.Type == withdraw.Crypto {
|
||||
cryptoEvent := &modelPSQL.WithdrawalCrypto{
|
||||
Address: res.RequestDetails.Crypto.Address,
|
||||
Fee: res.RequestDetails.Crypto.FeeAmount,
|
||||
}
|
||||
if res.RequestDetails.Crypto.AddressTag != "" {
|
||||
cryptoEvent.AddressTag.SetValid(res.RequestDetails.Crypto.AddressTag)
|
||||
}
|
||||
err = tempEvent.AddWithdrawalCryptoWithdrawalCryptos(ctx, tx, true, cryptoEvent)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
realID, _ := uuid.FromString(tempEvent.ID)
|
||||
res.ID = realID
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func addSQLiteEvent(ctx context.Context, tx *sql.Tx, res *withdraw.Response) (err error) {
|
||||
newUUID, errUUID := uuid.NewV4()
|
||||
if errUUID != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Failed to generate UUID: %v", errUUID)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var tempEvent = modelSQLite.WithdrawalHistory{
|
||||
ID: newUUID.String(),
|
||||
Exchange: res.Exchange.Name,
|
||||
ExchangeID: res.Exchange.ID,
|
||||
Status: res.Exchange.Status,
|
||||
Currency: res.RequestDetails.Currency.String(),
|
||||
Amount: res.RequestDetails.Amount,
|
||||
WithdrawType: int64(res.RequestDetails.Type),
|
||||
}
|
||||
|
||||
if res.RequestDetails.Description != "" {
|
||||
tempEvent.Description.SetValid(res.RequestDetails.Description)
|
||||
}
|
||||
|
||||
err = tempEvent.Insert(ctx, tx, boil.Infer())
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if res.RequestDetails.Type == withdraw.Fiat {
|
||||
fiatEvent := &modelSQLite.WithdrawalFiat{
|
||||
BankName: res.RequestDetails.Fiat.Bank.BankName,
|
||||
BankAddress: res.RequestDetails.Fiat.Bank.BankAddress,
|
||||
BankAccountName: res.RequestDetails.Fiat.Bank.AccountName,
|
||||
BankAccountNumber: res.RequestDetails.Fiat.Bank.AccountNumber,
|
||||
BSB: res.RequestDetails.Fiat.Bank.BSBNumber,
|
||||
SwiftCode: res.RequestDetails.Fiat.Bank.SWIFTCode,
|
||||
Iban: res.RequestDetails.Fiat.Bank.IBAN,
|
||||
}
|
||||
|
||||
err = tempEvent.AddWithdrawalFiats(ctx, tx, true, fiatEvent)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if res.RequestDetails.Type == withdraw.Crypto {
|
||||
cryptoEvent := &modelSQLite.WithdrawalCrypto{
|
||||
Address: res.RequestDetails.Crypto.Address,
|
||||
Fee: res.RequestDetails.Crypto.FeeAmount,
|
||||
}
|
||||
|
||||
if res.RequestDetails.Crypto.AddressTag != "" {
|
||||
cryptoEvent.AddressTag.SetValid(res.RequestDetails.Crypto.AddressTag)
|
||||
}
|
||||
|
||||
err = tempEvent.AddWithdrawalCryptos(ctx, tx, true, cryptoEvent)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Event Insert failed: %v", err)
|
||||
err = tx.Rollback()
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "Rollback failed: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
res.ID = newUUID
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetEventByUUID return requested withdraw information by ID
|
||||
func GetEventByUUID(id string) (*withdraw.Response, error) {
|
||||
resp, err := getByColumns(generateWhereQuery([]string{"id"}, []string{id}, 1))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp[0], nil
|
||||
}
|
||||
|
||||
// GetEventsByExchange returns all withdrawal requests by exchange
|
||||
func GetEventsByExchange(exchange string, limit int) ([]*withdraw.Response, error) {
|
||||
return getByColumns(generateWhereQuery([]string{"exchange"}, []string{exchange}, limit))
|
||||
}
|
||||
|
||||
// GetEventByExchangeID return requested withdraw information by Exchange ID
|
||||
func GetEventByExchangeID(exchange, id string) (*withdraw.Response, error) {
|
||||
resp, err := getByColumns(generateWhereQuery([]string{"exchange", "exchange_id"}, []string{exchange, id}, 1))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp[0], err
|
||||
}
|
||||
|
||||
// GetEventsByDate returns requested withdraw information by date range
|
||||
func GetEventsByDate(exchange string, start, end time.Time, limit int) ([]*withdraw.Response, error) {
|
||||
betweenQuery := generateWhereBetweenQuery("created_at", start, end, limit)
|
||||
if exchange == "" {
|
||||
return getByColumns(betweenQuery)
|
||||
}
|
||||
return getByColumns(append(generateWhereQuery([]string{"exchange"}, []string{exchange}, 0), betweenQuery...))
|
||||
}
|
||||
|
||||
func generateWhereQuery(columns, id []string, limit int) []qm.QueryMod {
|
||||
var queries []qm.QueryMod
|
||||
if limit > 0 {
|
||||
queries = append(queries, qm.Limit(limit))
|
||||
}
|
||||
for x := range columns {
|
||||
queries = append(queries, qm.Where(columns[x]+"= ?", id[x]))
|
||||
}
|
||||
return queries
|
||||
}
|
||||
|
||||
func generateWhereBetweenQuery(column string, start, end interface{}, limit int) []qm.QueryMod {
|
||||
return []qm.QueryMod{
|
||||
qm.Limit(limit),
|
||||
qm.Where(column+" BETWEEN ? AND ?", start, end),
|
||||
}
|
||||
}
|
||||
|
||||
func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
|
||||
if database.DB.SQL == nil {
|
||||
return nil, database.ErrDatabaseSupportDisabled
|
||||
}
|
||||
|
||||
var resp []*withdraw.Response
|
||||
var ctx = context.Background()
|
||||
if repository.GetSQLDialect() == database.DBSQLite3 {
|
||||
v, err := modelSQLite.WithdrawalHistories(q...).All(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for x := range v {
|
||||
var tempResp = &withdraw.Response{}
|
||||
newUUID, _ := uuid.FromString(v[x].ID)
|
||||
tempResp.ID = newUUID
|
||||
tempResp.Exchange = new(withdraw.ExchangeResponse)
|
||||
tempResp.Exchange.ID = v[x].ExchangeID
|
||||
tempResp.Exchange.Name = v[x].Exchange
|
||||
tempResp.Exchange.Status = v[x].Status
|
||||
tempResp.RequestDetails = new(withdraw.Request)
|
||||
tempResp.RequestDetails = &withdraw.Request{
|
||||
Currency: currency.NewCode(v[x].Currency),
|
||||
Description: v[x].Description.String,
|
||||
Amount: v[x].Amount,
|
||||
Type: withdraw.RequestType(v[x].WithdrawType),
|
||||
}
|
||||
|
||||
createdAtTime, err := time.Parse(time.RFC3339, v[x].CreatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "record: %v has an incorrect time format ( %v ) - defaulting to empty time: %v", tempResp.ID, v[x].CreatedAt, err)
|
||||
tempResp.CreatedAt = time.Time{}
|
||||
} else {
|
||||
tempResp.CreatedAt = createdAtTime
|
||||
}
|
||||
|
||||
updatedAtTime, err := time.Parse(time.RFC3339, v[x].UpdatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.DatabaseMgr, "record: %v has an incorrect time format ( %v ) - defaulting to empty time: %v", tempResp.ID, v[x].UpdatedAt, err)
|
||||
tempResp.UpdatedAt = time.Time{}
|
||||
} else {
|
||||
tempResp.UpdatedAt = updatedAtTime
|
||||
}
|
||||
|
||||
if withdraw.RequestType(v[x].WithdrawType) == withdraw.Crypto {
|
||||
x, err := v[x].WithdrawalCryptos().One(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tempResp.RequestDetails.Crypto = new(withdraw.CryptoRequest)
|
||||
tempResp.RequestDetails.Crypto.Address = x.Address
|
||||
tempResp.RequestDetails.Crypto.AddressTag = x.AddressTag.String
|
||||
tempResp.RequestDetails.Crypto.FeeAmount = x.Fee
|
||||
} else {
|
||||
x, err := v[x].WithdrawalFiats().One(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tempResp.RequestDetails.Fiat = new(withdraw.FiatRequest)
|
||||
tempResp.RequestDetails.Fiat.Bank = new(banking.Account)
|
||||
tempResp.RequestDetails.Fiat.Bank.AccountName = x.BankAccountName
|
||||
tempResp.RequestDetails.Fiat.Bank.AccountNumber = x.BankAccountNumber
|
||||
tempResp.RequestDetails.Fiat.Bank.IBAN = x.Iban
|
||||
tempResp.RequestDetails.Fiat.Bank.SWIFTCode = x.SwiftCode
|
||||
tempResp.RequestDetails.Fiat.Bank.BSBNumber = x.BSB
|
||||
}
|
||||
resp = append(resp, tempResp)
|
||||
}
|
||||
} else {
|
||||
v, err := modelPSQL.WithdrawalHistories(q...).All(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for x := range v {
|
||||
var tempResp = &withdraw.Response{}
|
||||
newUUID, _ := uuid.FromString(v[x].ID)
|
||||
tempResp.ID = newUUID
|
||||
tempResp.Exchange = new(withdraw.ExchangeResponse)
|
||||
tempResp.Exchange.ID = v[x].ExchangeID
|
||||
tempResp.Exchange.Name = v[x].Exchange
|
||||
tempResp.Exchange.Status = v[x].Status
|
||||
tempResp.RequestDetails = new(withdraw.Request)
|
||||
tempResp.RequestDetails = &withdraw.Request{
|
||||
Currency: currency.NewCode(v[x].Currency),
|
||||
Description: v[x].Description.String,
|
||||
Amount: v[x].Amount,
|
||||
Type: withdraw.RequestType(v[x].WithdrawType),
|
||||
}
|
||||
tempResp.CreatedAt = v[x].CreatedAt
|
||||
tempResp.UpdatedAt = v[x].UpdatedAt
|
||||
|
||||
if withdraw.RequestType(v[x].WithdrawType) == withdraw.Crypto {
|
||||
tempResp.RequestDetails.Crypto = new(withdraw.CryptoRequest)
|
||||
x, err := v[x].WithdrawalCryptoWithdrawalCryptos().One(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tempResp.RequestDetails.Crypto.Address = x.Address
|
||||
tempResp.RequestDetails.Crypto.AddressTag = x.AddressTag.String
|
||||
tempResp.RequestDetails.Crypto.FeeAmount = x.Fee
|
||||
} else if withdraw.RequestType(v[x].WithdrawType) == withdraw.Fiat {
|
||||
tempResp.RequestDetails.Fiat = new(withdraw.FiatRequest)
|
||||
x, err := v[x].WithdrawalFiatWithdrawalFiats().One(ctx, database.DB.SQL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tempResp.RequestDetails.Fiat.Bank = new(banking.Account)
|
||||
tempResp.RequestDetails.Fiat.Bank.AccountName = x.BankAccountName
|
||||
tempResp.RequestDetails.Fiat.Bank.AccountNumber = x.BankAccountNumber
|
||||
tempResp.RequestDetails.Fiat.Bank.IBAN = x.Iban
|
||||
tempResp.RequestDetails.Fiat.Bank.SWIFTCode = x.SwiftCode
|
||||
tempResp.RequestDetails.Fiat.Bank.BSBNumber = x.BSB
|
||||
}
|
||||
resp = append(resp, tempResp)
|
||||
}
|
||||
}
|
||||
if len(resp) == 0 {
|
||||
return nil, ErrNoResults
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
171
database/repository/withdraw/withdraw_test.go
Normal file
171
database/repository/withdraw/withdraw_test.go
Normal file
@@ -0,0 +1,171 @@
|
||||
package withdraw
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/database"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/drivers"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/repository"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/testhelpers"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
"github.com/thrasher-corp/goose"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
var err error
|
||||
testhelpers.PostgresTestDatabase = testhelpers.GetConnectionDetails()
|
||||
testhelpers.TempDir, err = ioutil.TempDir("", "gct-temp")
|
||||
if err != nil {
|
||||
fmt.Printf("failed to create temp file: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
t := m.Run()
|
||||
|
||||
err = os.RemoveAll(testhelpers.TempDir)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to remove temp db file: %v", err)
|
||||
}
|
||||
|
||||
os.Exit(t)
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
config *database.Config
|
||||
runner func(t *testing.T)
|
||||
closer func(dbConn *database.Db) error
|
||||
output interface{}
|
||||
}{
|
||||
{
|
||||
"SQLite-Write",
|
||||
&database.Config{
|
||||
Driver: database.DBSQLite3,
|
||||
ConnectionDetails: drivers.ConnectionDetails{Database: "./testdb"},
|
||||
},
|
||||
withdrawHelper,
|
||||
testhelpers.CloseDatabase,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"Postgres-Write",
|
||||
testhelpers.PostgresTestDatabase,
|
||||
withdrawHelper,
|
||||
nil,
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tests := range testCases {
|
||||
test := tests
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
if !testhelpers.CheckValidConfig(&test.config.ConnectionDetails) {
|
||||
t.Skip("database not configured skipping test")
|
||||
}
|
||||
|
||||
dbConn, err := testhelpers.ConnectToDatabase(test.config)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
path := filepath.Join("..", "..", "migrations")
|
||||
err = goose.Run("up", dbConn.SQL, repository.GetSQLDialect(), path, "")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to run migrations %v", err)
|
||||
}
|
||||
|
||||
if test.runner != nil {
|
||||
test.runner(t)
|
||||
}
|
||||
|
||||
if test.closer != nil {
|
||||
err = test.closer(dbConn)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func withdrawHelper(t *testing.T) {
|
||||
t.Helper()
|
||||
var wg sync.WaitGroup
|
||||
for x := 0; x < 20; x++ {
|
||||
wg.Add(1)
|
||||
go func(x int) {
|
||||
defer wg.Done()
|
||||
test := fmt.Sprintf("test-%v", x)
|
||||
resp := &withdraw.Response{
|
||||
Exchange: &withdraw.ExchangeResponse{
|
||||
Name: test,
|
||||
ID: test,
|
||||
Status: test,
|
||||
},
|
||||
RequestDetails: &withdraw.Request{
|
||||
Exchange: test,
|
||||
Description: test,
|
||||
Amount: 1.0,
|
||||
},
|
||||
}
|
||||
rnd := rand.Intn(2)
|
||||
if rnd == 0 {
|
||||
resp.RequestDetails.Currency = currency.AUD
|
||||
resp.RequestDetails.Type = 1
|
||||
resp.RequestDetails.Fiat = new(withdraw.FiatRequest)
|
||||
resp.RequestDetails.Fiat.Bank = new(banking.Account)
|
||||
} else {
|
||||
resp.RequestDetails.Currency = currency.BTC
|
||||
resp.RequestDetails.Type = 0
|
||||
resp.RequestDetails.Crypto = new(withdraw.CryptoRequest)
|
||||
resp.RequestDetails.Crypto.Address = test
|
||||
resp.RequestDetails.Crypto.FeeAmount = 0
|
||||
resp.RequestDetails.Crypto.AddressTag = test
|
||||
}
|
||||
Event(resp)
|
||||
}(x)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
_, err := GetEventByUUID(withdraw.DryRunID.String())
|
||||
if err != nil {
|
||||
if !errors.Is(err, ErrNoResults) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
v, err := GetEventsByExchange("test-1", 10)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = GetEventByExchangeID("test-1", "test-1")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(v) > 0 {
|
||||
_, err = GetEventByUUID(v[0].ID.String())
|
||||
if err != nil {
|
||||
if !errors.Is(err, ErrNoResults) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_, err = GetEventsByDate("test-1", time.Now().UTC().Add(-time.Minute), time.Now().UTC(), 5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
gctscript "github.com/thrasher-corp/gocryptotrader/gctscript/vm"
|
||||
gctlog "github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/utils"
|
||||
)
|
||||
|
||||
@@ -121,6 +122,7 @@ func ValidateSettings(b *Engine, s *Settings) {
|
||||
b.Settings.MaxVirtualMachines = s.MaxVirtualMachines
|
||||
b.Settings.EnableDispatcher = s.EnableDispatcher
|
||||
b.Settings.EnablePortfolioManager = s.EnablePortfolioManager
|
||||
b.Settings.WithdrawCacheSize = s.WithdrawCacheSize
|
||||
if b.Settings.EnablePortfolioManager {
|
||||
if b.Settings.PortfolioManagerDelay != time.Duration(0) && s.PortfolioManagerDelay > 0 {
|
||||
b.Settings.PortfolioManagerDelay = s.PortfolioManagerDelay
|
||||
@@ -161,6 +163,10 @@ func ValidateSettings(b *Engine, s *Settings) {
|
||||
gctscript.GCTScriptConfig.MaxVirtualMachines = uint8(s.MaxVirtualMachines)
|
||||
}
|
||||
|
||||
if flagSet["withdrawcachesize"] {
|
||||
withdraw.CacheSize = s.WithdrawCacheSize
|
||||
}
|
||||
|
||||
b.Settings.EnableCommsRelayer = s.EnableCommsRelayer
|
||||
b.Settings.EnableEventManager = s.EnableEventManager
|
||||
|
||||
@@ -287,6 +293,8 @@ func PrintSettings(s *Settings) {
|
||||
gctlog.Debugf(gctlog.Global, "- GCTSCRIPT SETTINGS: ")
|
||||
gctlog.Debugf(gctlog.Global, "\t Enable GCTScript manager: %v", s.EnableGCTScriptManager)
|
||||
gctlog.Debugf(gctlog.Global, "\t GCTScript max virtual machines: %v", s.MaxVirtualMachines)
|
||||
gctlog.Debugf(gctlog.Global, "- WITHDRAW SETTINGS: ")
|
||||
gctlog.Debugf(gctlog.Global, "\t Withdraw Cache size: %v", s.WithdrawCacheSize)
|
||||
gctlog.Debugf(gctlog.Global, "- COMMON SETTINGS:")
|
||||
gctlog.Debugf(gctlog.Global, "\t Global HTTP timeout: %v", s.GlobalHTTPTimeout)
|
||||
gctlog.Debugf(gctlog.Global, "\t Global HTTP user agent: %v", s.GlobalHTTPUserAgent)
|
||||
|
||||
@@ -78,6 +78,9 @@ type Settings struct {
|
||||
|
||||
// GCTscript settings
|
||||
MaxVirtualMachines uint
|
||||
|
||||
// Withdraw settings
|
||||
WithdrawCacheSize uint64
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/stats"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctscript/vm"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio"
|
||||
@@ -690,20 +689,6 @@ func GetExchangeCryptocurrencyDepositAddresses() map[string]map[string]string {
|
||||
return result
|
||||
}
|
||||
|
||||
// WithdrawCryptocurrencyFundsByExchange withdraws the desired cryptocurrency and amount to a desired cryptocurrency address
|
||||
func WithdrawCryptocurrencyFundsByExchange(exchName string, req *withdraw.CryptoRequest) (string, error) {
|
||||
if req == nil {
|
||||
return "", errors.New("crypto withdraw request param is nil")
|
||||
}
|
||||
|
||||
exch := GetExchangeByName(exchName)
|
||||
if exch == nil {
|
||||
return "", ErrExchangeNotFound
|
||||
}
|
||||
|
||||
return exch.WithdrawCryptocurrencyFunds(req)
|
||||
}
|
||||
|
||||
// FormatCurrency is a method that formats and returns a currency pair
|
||||
// based on the user currency display preferences
|
||||
func FormatCurrency(p currency.Pair) currency.Pair {
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
grpcauth "github.com/grpc-ecosystem/go-grpc-middleware/auth"
|
||||
grpcruntime "github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/thrasher-corp/gocryptotrader/common"
|
||||
@@ -21,6 +22,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/common/file"
|
||||
"github.com/thrasher-corp/gocryptotrader/common/file/archive"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/database"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/models/postgres"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/models/sqlite3"
|
||||
"github.com/thrasher-corp/gocryptotrader/database/repository/audit"
|
||||
@@ -34,6 +36,8 @@ import (
|
||||
gctscript "github.com/thrasher-corp/gocryptotrader/gctscript/vm"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/utils"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
@@ -637,6 +641,9 @@ func (s *RPCServer) GetPortfolioSummary(ctx context.Context, r *gctrpc.GetPortfo
|
||||
// AddPortfolioAddress adds an address to the portfolio manager
|
||||
func (s *RPCServer) AddPortfolioAddress(ctx context.Context, r *gctrpc.AddPortfolioAddressRequest) (*gctrpc.AddPortfolioAddressResponse, error) {
|
||||
err := Bot.Portfolio.AddAddress(r.Address, r.Description, currency.NewCode(r.CoinType), r.Balance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &gctrpc.AddPortfolioAddressResponse{}, err
|
||||
}
|
||||
|
||||
@@ -924,13 +931,172 @@ func (s *RPCServer) GetCryptocurrencyDepositAddress(ctx context.Context, r *gctr
|
||||
|
||||
// WithdrawCryptocurrencyFunds withdraws cryptocurrency funds specified by
|
||||
// exchange
|
||||
func (s *RPCServer) WithdrawCryptocurrencyFunds(ctx context.Context, r *gctrpc.WithdrawCurrencyRequest) (*gctrpc.WithdrawResponse, error) {
|
||||
return &gctrpc.WithdrawResponse{}, common.ErrNotYetImplemented
|
||||
func (s *RPCServer) WithdrawCryptocurrencyFunds(ctx context.Context, r *gctrpc.WithdrawCryptoRequest) (*gctrpc.WithdrawResponse, error) {
|
||||
exch := GetExchangeByName(r.Exchange)
|
||||
if exch == nil {
|
||||
return nil, errors.New("exchange is not loaded/doesn't exist")
|
||||
}
|
||||
|
||||
request := &withdraw.Request{
|
||||
Amount: r.Amount,
|
||||
Currency: currency.NewCode(strings.ToUpper(r.Currency)),
|
||||
Type: withdraw.Crypto,
|
||||
Description: r.Description,
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: r.Address,
|
||||
AddressTag: r.AddressTag,
|
||||
FeeAmount: r.Fee,
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := SubmitWithdrawal(r.Exchange, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &gctrpc.WithdrawResponse{
|
||||
Id: resp.ID.String(),
|
||||
Status: resp.Exchange.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds withdraws fiat funds specified by exchange
|
||||
func (s *RPCServer) WithdrawFiatFunds(ctx context.Context, r *gctrpc.WithdrawCurrencyRequest) (*gctrpc.WithdrawResponse, error) {
|
||||
return &gctrpc.WithdrawResponse{}, common.ErrNotYetImplemented
|
||||
func (s *RPCServer) WithdrawFiatFunds(ctx context.Context, r *gctrpc.WithdrawFiatRequest) (*gctrpc.WithdrawResponse, error) {
|
||||
exch := GetExchangeByName(r.Exchange)
|
||||
if exch == nil {
|
||||
return nil, errors.New("exchange is not loaded/doesn't exist")
|
||||
}
|
||||
|
||||
var bankAccount *banking.Account
|
||||
|
||||
bankAccount, err := banking.GetBankAccountByID(r.BankAccountId)
|
||||
if err != nil {
|
||||
bankAccount, err = exch.GetBase().GetExchangeBankAccounts(r.BankAccountId, r.Currency)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
request := &withdraw.Request{
|
||||
Amount: r.Amount,
|
||||
Currency: currency.NewCode(strings.ToUpper(r.Currency)),
|
||||
Type: withdraw.Fiat,
|
||||
Description: r.Description,
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: bankAccount,
|
||||
},
|
||||
}
|
||||
resp, err := SubmitWithdrawal(r.Exchange, request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &gctrpc.WithdrawResponse{
|
||||
Id: resp.ID.String(),
|
||||
Status: resp.Exchange.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawalEventByID returns previous withdrawal request details
|
||||
func (s *RPCServer) WithdrawalEventByID(ctx context.Context, r *gctrpc.WithdrawalEventByIDRequest) (*gctrpc.WithdrawalEventByIDResponse, error) {
|
||||
if !Bot.Config.Database.Enabled {
|
||||
return nil, database.ErrDatabaseSupportDisabled
|
||||
}
|
||||
v, err := WithdrawalEventByID(r.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp := &gctrpc.WithdrawalEventByIDResponse{
|
||||
Event: &gctrpc.WithdrawalEventResponse{
|
||||
Id: v.ID.String(),
|
||||
Exchange: &gctrpc.WithdrawlExchangeEvent{
|
||||
Name: v.Exchange.Name,
|
||||
Id: v.Exchange.Name,
|
||||
Status: v.Exchange.Status,
|
||||
},
|
||||
Request: &gctrpc.WithdrawalRequestEvent{
|
||||
Currency: v.RequestDetails.Currency.String(),
|
||||
Description: v.RequestDetails.Description,
|
||||
Amount: v.RequestDetails.Amount,
|
||||
Type: int32(v.RequestDetails.Type),
|
||||
},
|
||||
},
|
||||
}
|
||||
createdAtPtype, err := ptypes.TimestampProto(v.CreatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.Global, "failed to convert time: %v", err)
|
||||
}
|
||||
resp.Event.CreatedAt = createdAtPtype
|
||||
|
||||
updatedAtPtype, err := ptypes.TimestampProto(v.UpdatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.Global, "failed to convert time: %v", err)
|
||||
}
|
||||
resp.Event.UpdatedAt = updatedAtPtype
|
||||
|
||||
if v.RequestDetails.Type == withdraw.Crypto {
|
||||
resp.Event.Request.Crypto = new(gctrpc.CryptoWithdrawalEvent)
|
||||
resp.Event.Request.Crypto = &gctrpc.CryptoWithdrawalEvent{
|
||||
Address: v.RequestDetails.Crypto.Address,
|
||||
AddressTag: v.RequestDetails.Crypto.AddressTag,
|
||||
Fee: v.RequestDetails.Crypto.FeeAmount,
|
||||
}
|
||||
} else if v.RequestDetails.Type == withdraw.Fiat {
|
||||
if v.RequestDetails.Fiat != nil {
|
||||
resp.Event.Request.Fiat = new(gctrpc.FiatWithdrawalEvent)
|
||||
resp.Event.Request.Fiat = &gctrpc.FiatWithdrawalEvent{
|
||||
BankName: v.RequestDetails.Fiat.Bank.BankName,
|
||||
AccountName: v.RequestDetails.Fiat.Bank.AccountName,
|
||||
AccountNumber: v.RequestDetails.Fiat.Bank.AccountNumber,
|
||||
Bsb: v.RequestDetails.Fiat.Bank.BSBNumber,
|
||||
Swift: v.RequestDetails.Fiat.Bank.SWIFTCode,
|
||||
Iban: v.RequestDetails.Fiat.Bank.IBAN,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// WithdrawalEventsByExchange returns previous withdrawal request details by exchange
|
||||
func (s *RPCServer) WithdrawalEventsByExchange(ctx context.Context, r *gctrpc.WithdrawalEventsByExchangeRequest) (*gctrpc.WithdrawalEventsByExchangeResponse, error) {
|
||||
if !Bot.Config.Database.Enabled {
|
||||
return nil, database.ErrDatabaseSupportDisabled
|
||||
}
|
||||
if r.Id == "" {
|
||||
ret, err := WithdrawalEventByExchange(r.Exchange, int(r.Limit))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parseMultipleEvents(ret), nil
|
||||
}
|
||||
|
||||
ret, err := WithdrawalEventByExchangeID(r.Exchange, r.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return parseSingleEvents(ret), nil
|
||||
}
|
||||
|
||||
// WithdrawalEventsByDate returns previous withdrawal request details by exchange
|
||||
func (s *RPCServer) WithdrawalEventsByDate(ctx context.Context, r *gctrpc.WithdrawalEventsByDateRequest) (*gctrpc.WithdrawalEventsByExchangeResponse, error) {
|
||||
UTCStartTime, err := time.Parse(audit.TableTimeFormat, r.Start)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
UTCSEndTime, err := time.Parse(audit.TableTimeFormat, r.End)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret, err := WithdrawEventByDate(r.Exchange, UTCStartTime, UTCSEndTime, int(r.Limit))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return parseMultipleEvents(ret), nil
|
||||
}
|
||||
|
||||
// GetLoggerDetails returns a loggers details
|
||||
|
||||
222
engine/withdraw.go
Normal file
222
engine/withdraw.go
Normal file
@@ -0,0 +1,222 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
withdrawDataStore "github.com/thrasher-corp/gocryptotrader/database/repository/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/gctrpc"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
const (
|
||||
// ErrWithdrawRequestNotFound message to display when no record is found
|
||||
ErrWithdrawRequestNotFound = "%v not found"
|
||||
// ErrRequestCannotbeNil message to display when request is nil
|
||||
ErrRequestCannotbeNil = "request cannot be nil"
|
||||
// StatusError const for for "error" string
|
||||
StatusError = "error"
|
||||
)
|
||||
|
||||
// SubmitWithdrawal preforms validation and submits a new withdraw request to exchange
|
||||
func SubmitWithdrawal(exchName string, req *withdraw.Request) (*withdraw.Response, error) {
|
||||
if req == nil {
|
||||
return nil, errors.New(ErrRequestCannotbeNil)
|
||||
}
|
||||
|
||||
var err error
|
||||
var ret *withdraw.ExchangeResponse
|
||||
if req.Exchange == "" {
|
||||
req.Exchange = exchName
|
||||
}
|
||||
|
||||
err = withdraw.Validate(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
exch := GetExchangeByName(exchName)
|
||||
if exch == nil {
|
||||
return nil, ErrExchangeNotFound
|
||||
}
|
||||
|
||||
resp := &withdraw.Response{
|
||||
Exchange: &withdraw.ExchangeResponse{
|
||||
Name: exchName,
|
||||
},
|
||||
RequestDetails: req,
|
||||
}
|
||||
|
||||
if Bot.Settings.EnableDryRun {
|
||||
log.Warnln(log.Global, "Dry run enabled, no withdrawal request will be submitted or have an event created")
|
||||
resp.ID = withdraw.DryRunID
|
||||
resp.Exchange.Status = "dryrun"
|
||||
resp.Exchange.ID = withdraw.DryRunID.String()
|
||||
} else {
|
||||
if req.Type == withdraw.Fiat {
|
||||
ret, err = exch.WithdrawFiatFunds(req)
|
||||
if err != nil {
|
||||
resp.Exchange.ID = StatusError
|
||||
resp.Exchange.Status = err.Error()
|
||||
} else {
|
||||
resp.Exchange.Status = ret.Status
|
||||
resp.Exchange.ID = ret.ID
|
||||
}
|
||||
} else if req.Type == withdraw.Crypto {
|
||||
ret, err = exch.WithdrawCryptocurrencyFunds(req)
|
||||
if err != nil {
|
||||
resp.Exchange.ID = StatusError
|
||||
resp.Exchange.Status = err.Error()
|
||||
} else {
|
||||
resp.Exchange.Status = ret.Status
|
||||
resp.Exchange.ID = ret.ID
|
||||
}
|
||||
}
|
||||
withdrawDataStore.Event(resp)
|
||||
}
|
||||
if err == nil {
|
||||
withdraw.Cache.Add(resp.ID, resp)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// WithdrawalEventByID returns a withdrawal request by ID
|
||||
func WithdrawalEventByID(id string) (*withdraw.Response, error) {
|
||||
v := withdraw.Cache.Get(id)
|
||||
if v != nil {
|
||||
return v.(*withdraw.Response), nil
|
||||
}
|
||||
|
||||
l, err := withdrawDataStore.GetEventByUUID(id)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf(ErrWithdrawRequestNotFound, id)
|
||||
}
|
||||
withdraw.Cache.Add(id, l)
|
||||
return l, nil
|
||||
}
|
||||
|
||||
// WithdrawalEventByExchange returns a withdrawal request by ID
|
||||
func WithdrawalEventByExchange(exchange string, limit int) ([]*withdraw.Response, error) {
|
||||
return withdrawDataStore.GetEventsByExchange(exchange, limit)
|
||||
}
|
||||
|
||||
// WithdrawEventByDate returns a withdrawal request by ID
|
||||
func WithdrawEventByDate(exchange string, start, end time.Time, limit int) ([]*withdraw.Response, error) {
|
||||
return withdrawDataStore.GetEventsByDate(exchange, start, end, limit)
|
||||
}
|
||||
|
||||
// WithdrawalEventByExchangeID returns a withdrawal request by Exchange ID
|
||||
func WithdrawalEventByExchangeID(exchange, id string) (*withdraw.Response, error) {
|
||||
return withdrawDataStore.GetEventByExchangeID(exchange, id)
|
||||
}
|
||||
|
||||
func parseMultipleEvents(ret []*withdraw.Response) *gctrpc.WithdrawalEventsByExchangeResponse {
|
||||
v := &gctrpc.WithdrawalEventsByExchangeResponse{}
|
||||
for x := range ret {
|
||||
tempEvent := &gctrpc.WithdrawalEventResponse{
|
||||
Id: ret[x].ID.String(),
|
||||
Exchange: &gctrpc.WithdrawlExchangeEvent{
|
||||
Name: ret[x].Exchange.Name,
|
||||
Id: ret[x].Exchange.Name,
|
||||
Status: ret[x].Exchange.Status,
|
||||
},
|
||||
Request: &gctrpc.WithdrawalRequestEvent{
|
||||
Currency: ret[x].RequestDetails.Currency.String(),
|
||||
Description: ret[x].RequestDetails.Description,
|
||||
Amount: ret[x].RequestDetails.Amount,
|
||||
Type: int32(ret[x].RequestDetails.Type),
|
||||
},
|
||||
}
|
||||
|
||||
createdAtPtype, err := ptypes.TimestampProto(ret[x].CreatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.Global, "failed to convert time: %v", err)
|
||||
}
|
||||
tempEvent.CreatedAt = createdAtPtype
|
||||
|
||||
updatedAtPtype, err := ptypes.TimestampProto(ret[x].UpdatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.Global, "failed to convert time: %v", err)
|
||||
}
|
||||
tempEvent.UpdatedAt = updatedAtPtype
|
||||
|
||||
if ret[x].RequestDetails.Type == withdraw.Crypto {
|
||||
tempEvent.Request.Crypto = new(gctrpc.CryptoWithdrawalEvent)
|
||||
tempEvent.Request.Crypto = &gctrpc.CryptoWithdrawalEvent{
|
||||
Address: ret[x].RequestDetails.Crypto.Address,
|
||||
AddressTag: ret[x].RequestDetails.Crypto.AddressTag,
|
||||
Fee: ret[x].RequestDetails.Crypto.FeeAmount,
|
||||
}
|
||||
} else if ret[x].RequestDetails.Type == withdraw.Fiat {
|
||||
if ret[x].RequestDetails.Fiat != nil {
|
||||
tempEvent.Request.Fiat = new(gctrpc.FiatWithdrawalEvent)
|
||||
tempEvent.Request.Fiat = &gctrpc.FiatWithdrawalEvent{
|
||||
BankName: ret[x].RequestDetails.Fiat.Bank.BankName,
|
||||
AccountName: ret[x].RequestDetails.Fiat.Bank.AccountName,
|
||||
AccountNumber: ret[x].RequestDetails.Fiat.Bank.AccountNumber,
|
||||
Bsb: ret[x].RequestDetails.Fiat.Bank.BSBNumber,
|
||||
Swift: ret[x].RequestDetails.Fiat.Bank.SWIFTCode,
|
||||
Iban: ret[x].RequestDetails.Fiat.Bank.IBAN,
|
||||
}
|
||||
}
|
||||
}
|
||||
v.Event = append(v.Event, tempEvent)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func parseSingleEvents(ret *withdraw.Response) *gctrpc.WithdrawalEventsByExchangeResponse {
|
||||
tempEvent := &gctrpc.WithdrawalEventResponse{
|
||||
Id: ret.ID.String(),
|
||||
Exchange: &gctrpc.WithdrawlExchangeEvent{
|
||||
Name: ret.Exchange.Name,
|
||||
Id: ret.Exchange.Name,
|
||||
Status: ret.Exchange.Status,
|
||||
},
|
||||
Request: &gctrpc.WithdrawalRequestEvent{
|
||||
Currency: ret.RequestDetails.Currency.String(),
|
||||
Description: ret.RequestDetails.Description,
|
||||
Amount: ret.RequestDetails.Amount,
|
||||
Type: int32(ret.RequestDetails.Type),
|
||||
},
|
||||
}
|
||||
createdAtPtype, err := ptypes.TimestampProto(ret.CreatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.Global, "failed to convert time: %v", err)
|
||||
}
|
||||
tempEvent.CreatedAt = createdAtPtype
|
||||
|
||||
updatedAtPtype, err := ptypes.TimestampProto(ret.UpdatedAt)
|
||||
if err != nil {
|
||||
log.Errorf(log.Global, "failed to convert time: %v", err)
|
||||
}
|
||||
tempEvent.UpdatedAt = updatedAtPtype
|
||||
|
||||
if ret.RequestDetails.Type == withdraw.Crypto {
|
||||
tempEvent.Request.Crypto = new(gctrpc.CryptoWithdrawalEvent)
|
||||
tempEvent.Request.Crypto = &gctrpc.CryptoWithdrawalEvent{
|
||||
Address: ret.RequestDetails.Crypto.Address,
|
||||
AddressTag: ret.RequestDetails.Crypto.AddressTag,
|
||||
Fee: ret.RequestDetails.Crypto.FeeAmount,
|
||||
}
|
||||
} else if ret.RequestDetails.Type == withdraw.Fiat {
|
||||
if ret.RequestDetails.Fiat != nil {
|
||||
tempEvent.Request.Fiat = new(gctrpc.FiatWithdrawalEvent)
|
||||
tempEvent.Request.Fiat = &gctrpc.FiatWithdrawalEvent{
|
||||
BankName: ret.RequestDetails.Fiat.Bank.BankName,
|
||||
AccountName: ret.RequestDetails.Fiat.Bank.AccountName,
|
||||
AccountNumber: ret.RequestDetails.Fiat.Bank.AccountNumber,
|
||||
Bsb: ret.RequestDetails.Fiat.Bank.BSBNumber,
|
||||
Swift: ret.RequestDetails.Fiat.Bank.SWIFTCode,
|
||||
Iban: ret.RequestDetails.Fiat.Bank.IBAN,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &gctrpc.WithdrawalEventsByExchangeResponse{
|
||||
Event: []*gctrpc.WithdrawalEventResponse{tempEvent},
|
||||
}
|
||||
}
|
||||
191
engine/withdraw_test.go
Normal file
191
engine/withdraw_test.go
Normal file
@@ -0,0 +1,191 @@
|
||||
package engine
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
const (
|
||||
exchangeName = "BTC Markets"
|
||||
bankAccountID = "test-bank-01"
|
||||
)
|
||||
|
||||
var (
|
||||
settings = Settings{
|
||||
ConfigFile: filepath.Join("..", "testdata", "configtest.json"),
|
||||
EnableDryRun: true,
|
||||
DataDir: filepath.Join("..", "testdata", "gocryptotrader"),
|
||||
Verbose: false,
|
||||
EnableGRPC: false,
|
||||
EnableDeprecatedRPC: false,
|
||||
EnableWebsocketRPC: false,
|
||||
}
|
||||
)
|
||||
|
||||
func setupEngine() (err error) {
|
||||
Bot, err = NewFromSettings(&settings)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return Bot.Start()
|
||||
}
|
||||
|
||||
func cleanup() {
|
||||
err := os.RemoveAll(settings.DataDir)
|
||||
if err != nil {
|
||||
fmt.Printf("Clean up failed to remove file: %v manual removal may be required", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubmitWithdrawal(t *testing.T) {
|
||||
err := setupEngine()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
banking.Accounts = append(banking.Accounts,
|
||||
banking.Account{
|
||||
Enabled: true,
|
||||
ID: "test-bank-01",
|
||||
BankName: "Test Bank",
|
||||
BankAddress: "42 Bank Street",
|
||||
BankPostalCode: "13337",
|
||||
BankPostalCity: "Satoshiville",
|
||||
BankCountry: "Japan",
|
||||
AccountName: "Satoshi Nakamoto",
|
||||
AccountNumber: "0234",
|
||||
BSBNumber: "123456",
|
||||
SWIFTCode: "91272837",
|
||||
IBAN: "98218738671897",
|
||||
SupportedCurrencies: "AUD,USD",
|
||||
SupportedExchanges: exchangeName,
|
||||
},
|
||||
)
|
||||
|
||||
bank, err := banking.GetBankAccountByID(bankAccountID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req := &withdraw.Request{
|
||||
Exchange: exchangeName,
|
||||
Currency: currency.AUD,
|
||||
Description: exchangeName,
|
||||
Amount: 1.0,
|
||||
Type: 1,
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: bank,
|
||||
},
|
||||
}
|
||||
|
||||
_, err = SubmitWithdrawal(exchangeName, req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = SubmitWithdrawal(exchangeName, nil)
|
||||
if err != nil {
|
||||
if err.Error() != withdraw.ErrRequestCannotBeNil.Error() {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
cleanup()
|
||||
}
|
||||
|
||||
func TestWithdrawEventByID(t *testing.T) {
|
||||
tempResp := &withdraw.Response{
|
||||
ID: withdraw.DryRunID,
|
||||
}
|
||||
_, err := WithdrawalEventByID(withdraw.DryRunID.String())
|
||||
if err != nil {
|
||||
if err.Error() != fmt.Errorf(ErrWithdrawRequestNotFound, withdraw.DryRunID.String()).Error() {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
withdraw.Cache.Add(withdraw.DryRunID.String(), tempResp)
|
||||
v, err := WithdrawalEventByID(withdraw.DryRunID.String())
|
||||
if err != nil {
|
||||
if err != fmt.Errorf(ErrWithdrawRequestNotFound, withdraw.DryRunID.String()) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if v == nil {
|
||||
t.Fatal("expected WithdrawalEventByID() to return data from cache")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawalEventByExchange(t *testing.T) {
|
||||
_, err := WithdrawalEventByExchange(exchangeName, 1)
|
||||
if err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawEventByDate(t *testing.T) {
|
||||
_, err := WithdrawEventByDate(exchangeName, time.Now(), time.Now(), 1)
|
||||
if err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawalEventByExchangeID(t *testing.T) {
|
||||
_, err := WithdrawalEventByExchangeID(exchangeName, exchangeName)
|
||||
if err == nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseEvents(t *testing.T) {
|
||||
var testData []*withdraw.Response
|
||||
for x := 0; x < 5; x++ {
|
||||
test := fmt.Sprintf("test-%v", x)
|
||||
resp := &withdraw.Response{
|
||||
ID: withdraw.DryRunID,
|
||||
Exchange: &withdraw.ExchangeResponse{
|
||||
Name: test,
|
||||
ID: test,
|
||||
Status: test,
|
||||
},
|
||||
RequestDetails: &withdraw.Request{
|
||||
Exchange: test,
|
||||
Description: test,
|
||||
Amount: 1.0,
|
||||
},
|
||||
}
|
||||
if x%2 == 0 {
|
||||
resp.RequestDetails.Currency = currency.AUD
|
||||
resp.RequestDetails.Type = 1
|
||||
resp.RequestDetails.Fiat = new(withdraw.FiatRequest)
|
||||
resp.RequestDetails.Fiat.Bank = new(banking.Account)
|
||||
} else {
|
||||
resp.RequestDetails.Currency = currency.BTC
|
||||
resp.RequestDetails.Type = 0
|
||||
resp.RequestDetails.Crypto = new(withdraw.CryptoRequest)
|
||||
resp.RequestDetails.Crypto.Address = test
|
||||
resp.RequestDetails.Crypto.FeeAmount = 0
|
||||
resp.RequestDetails.Crypto.AddressTag = test
|
||||
}
|
||||
testData = append(testData, resp)
|
||||
}
|
||||
v := parseMultipleEvents(testData)
|
||||
if reflect.TypeOf(v).String() != "*gctrpc.WithdrawalEventsByExchangeResponse" {
|
||||
t.Fatal("expected type to be *gctrpc.WithdrawalEventsByExchangeResponse")
|
||||
}
|
||||
|
||||
v = parseSingleEvents(testData[0])
|
||||
if reflect.TypeOf(v).String() != "*gctrpc.WithdrawalEventsByExchangeResponse" {
|
||||
t.Fatal("expected type to be *gctrpc.WithdrawalEventsByExchangeResponse")
|
||||
}
|
||||
|
||||
v = parseSingleEvents(testData[1])
|
||||
if v.Event[0].Request.Type != 0 {
|
||||
t.Fatal("Expected second entry in slice to return a Request.Type of Crypto")
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -562,8 +562,7 @@ func TestModifyOrder(t *testing.T) {
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
t.Parallel()
|
||||
var withdrawCryptoRequest = withdraw.CryptoRequest{}
|
||||
_, err := a.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
_, err := a.WithdrawCryptocurrencyFunds(&withdraw.Request{})
|
||||
if err != common.ErrNotYetImplemented {
|
||||
t.Errorf("Expected 'Not implemented', received %v", err)
|
||||
}
|
||||
@@ -575,8 +574,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
_, err := a.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
_, err := a.WithdrawFiatFunds(&withdraw.Request{})
|
||||
if err != common.ErrNotYetImplemented {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err)
|
||||
}
|
||||
@@ -588,8 +586,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
_, err := a.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
_, err := a.WithdrawFiatFundsToInternationalBank(&withdraw.Request{})
|
||||
if err != common.ErrNotYetImplemented {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrNotYetImplemented, err)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config for Alphapoint
|
||||
@@ -299,18 +299,18 @@ func (a *Alphapoint) GetDepositAddress(cryptocurrency currency.Code, _ string) (
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (a *Alphapoint) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
func (a *Alphapoint) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted
|
||||
func (a *Alphapoint) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
func (a *Alphapoint) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (a *Alphapoint) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
func (a *Alphapoint) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply your own keys here for due diligence testing
|
||||
@@ -463,13 +463,13 @@ func TestWithdraw(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: 0,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: 0,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
_, err := b.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
@@ -486,8 +486,7 @@ func TestWithdraw(t *testing.T) {
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var withdrawFiatRequest withdraw.FiatRequest
|
||||
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
_, err := b.WithdrawFiatFunds(&withdraw.Request{})
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
}
|
||||
@@ -496,8 +495,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var withdrawFiatRequest withdraw.FiatRequest
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(&withdraw.Request{})
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -511,24 +511,30 @@ func (b *Binance) GetDepositAddress(cryptocurrency currency.Code, _ string) (str
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Binance) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
func (b *Binance) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
amountStr := strconv.FormatFloat(withdrawRequest.Amount, 'f', -1, 64)
|
||||
return b.WithdrawCrypto(withdrawRequest.Currency.String(),
|
||||
withdrawRequest.Address,
|
||||
withdrawRequest.AddressTag,
|
||||
v, err := b.WithdrawCrypto(withdrawRequest.Currency.String(),
|
||||
withdrawRequest.Crypto.Address,
|
||||
withdrawRequest.Crypto.AddressTag,
|
||||
withdrawRequest.Description, amountStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: v,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Binance) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (b *Binance) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Binance) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (b *Binance) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -17,8 +17,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -671,32 +671,32 @@ func (b *Bitfinex) WithdrawCryptocurrency(wallet, address, paymentID string, amo
|
||||
}
|
||||
|
||||
// WithdrawFIAT Sends an authenticated request to withdraw FIAT currency
|
||||
func (b *Bitfinex) WithdrawFIAT(withdrawalType, walletType string, withdrawRequest *withdraw.FiatRequest) (Withdrawal, error) {
|
||||
func (b *Bitfinex) WithdrawFIAT(withdrawalType, walletType string, withdrawRequest *withdraw.Request) (Withdrawal, error) {
|
||||
var response []Withdrawal
|
||||
req := make(map[string]interface{})
|
||||
|
||||
req["withdraw_type"] = withdrawalType
|
||||
req["walletselected"] = walletType
|
||||
req["amount"] = strconv.FormatFloat(withdrawRequest.Amount, 'f', -1, 64)
|
||||
req["account_name"] = withdrawRequest.BankAccountName
|
||||
req["account_number"] = withdrawRequest.BankAccountNumber
|
||||
req["bank_name"] = withdrawRequest.BankName
|
||||
req["bank_address"] = withdrawRequest.BankAddress
|
||||
req["bank_city"] = withdrawRequest.BankCity
|
||||
req["bank_country"] = withdrawRequest.BankCountry
|
||||
req["expressWire"] = withdrawRequest.IsExpressWire
|
||||
req["swift"] = withdrawRequest.SwiftCode
|
||||
req["account_name"] = withdrawRequest.Fiat.Bank.AccountName
|
||||
req["account_number"] = withdrawRequest.Fiat.Bank.AccountNumber
|
||||
req["bank_name"] = withdrawRequest.Fiat.Bank.BankName
|
||||
req["bank_address"] = withdrawRequest.Fiat.Bank.BankAddress
|
||||
req["bank_city"] = withdrawRequest.Fiat.Bank.BankPostalCity
|
||||
req["bank_country"] = withdrawRequest.Fiat.Bank.BankCountry
|
||||
req["expressWire"] = withdrawRequest.Fiat.IsExpressWire
|
||||
req["swift"] = withdrawRequest.Fiat.Bank.SWIFTCode
|
||||
req["detail_payment"] = withdrawRequest.Description
|
||||
req["currency"] = withdrawRequest.WireCurrency
|
||||
req["account_address"] = withdrawRequest.BankAddress
|
||||
req["currency"] = withdrawRequest.Currency
|
||||
req["account_address"] = withdrawRequest.Fiat.Bank.BankAddress
|
||||
|
||||
if withdrawRequest.RequiresIntermediaryBank {
|
||||
req["intermediary_bank_name"] = withdrawRequest.IntermediaryBankName
|
||||
req["intermediary_bank_address"] = withdrawRequest.IntermediaryBankAddress
|
||||
req["intermediary_bank_city"] = withdrawRequest.IntermediaryBankCity
|
||||
req["intermediary_bank_country"] = withdrawRequest.IntermediaryBankCountry
|
||||
req["intermediary_bank_account"] = strconv.FormatFloat(withdrawRequest.IntermediaryBankAccountNumber, 'f', -1, 64)
|
||||
req["intermediary_bank_swift"] = withdrawRequest.IntermediarySwiftCode
|
||||
if withdrawRequest.Fiat.RequiresIntermediaryBank {
|
||||
req["intermediary_bank_name"] = withdrawRequest.Fiat.IntermediaryBankName
|
||||
req["intermediary_bank_address"] = withdrawRequest.Fiat.IntermediaryBankAddress
|
||||
req["intermediary_bank_city"] = withdrawRequest.Fiat.IntermediaryBankCity
|
||||
req["intermediary_bank_country"] = withdrawRequest.Fiat.IntermediaryBankCountry
|
||||
req["intermediary_bank_account"] = strconv.FormatFloat(withdrawRequest.Fiat.IntermediaryBankAccountNumber, 'f', -1, 64)
|
||||
req["intermediary_bank_swift"] = withdrawRequest.Fiat.IntermediarySwiftCode
|
||||
}
|
||||
|
||||
err := b.SendAuthenticatedHTTPRequest(http.MethodPost,
|
||||
|
||||
@@ -16,7 +16,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply your own keys here to do better tests
|
||||
@@ -273,55 +274,6 @@ func TestWalletTransfer(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawCryptocurrency(t *testing.T) {
|
||||
if !b.ValidateAPICredentials() {
|
||||
t.SkipNow()
|
||||
}
|
||||
t.Parallel()
|
||||
|
||||
_, err := b.WithdrawCryptocurrency("bad",
|
||||
"rEb8TK3gBgk5auZkwc6sHnwrGVJH8DuaLh",
|
||||
"102257461",
|
||||
1,
|
||||
currency.XRP)
|
||||
if err == nil {
|
||||
t.Error("error cannot be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: 1,
|
||||
Currency: currency.USD,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
},
|
||||
BankAccountName: "Satoshi Nakamoto",
|
||||
BankAccountNumber: "12345",
|
||||
BankAddress: "123 Fake St",
|
||||
BankCity: "Tarry Town",
|
||||
BankCountry: "Hyrule",
|
||||
BankName: "Federal Reserve Bank",
|
||||
WireCurrency: currency.USD.String(),
|
||||
SwiftCode: "Taylor",
|
||||
RequiresIntermediaryBank: false,
|
||||
IsExpressWire: false,
|
||||
}
|
||||
|
||||
_, err := b.WithdrawFIAT("wire", "exchange", &withdrawFiatRequest)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
t.Errorf("Withdraw failed to be placed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewOrder(t *testing.T) {
|
||||
if !b.ValidateAPICredentials() {
|
||||
t.SkipNow()
|
||||
@@ -862,13 +814,13 @@ func TestWithdraw(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
_, err := b.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
@@ -880,34 +832,53 @@ func TestWithdraw(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.USD,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: &banking.Account{},
|
||||
WireCurrency: currency.USD.String(),
|
||||
},
|
||||
}
|
||||
|
||||
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
t.Errorf("Withdraw failed to be placed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Parallel()
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
var withdrawFiatRequest = withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: &banking.Account{},
|
||||
WireCurrency: currency.USD.String(),
|
||||
RequiresIntermediaryBank: true,
|
||||
IsExpressWire: false,
|
||||
IntermediaryBankAccountNumber: 12345,
|
||||
IntermediaryBankAddress: "123 Fake St",
|
||||
IntermediaryBankCity: "Tarry Town",
|
||||
IntermediaryBankCountry: "Hyrule",
|
||||
IntermediaryBankName: "Federal Reserve Bank",
|
||||
IntermediarySwiftCode: "Taylor",
|
||||
},
|
||||
BankAccountName: "Satoshi Nakamoto",
|
||||
BankAccountNumber: "12345",
|
||||
BankAddress: "123 Fake St",
|
||||
BankCity: "Tarry Town",
|
||||
BankCountry: "Hyrule",
|
||||
BankName: "Federal Reserve Bank",
|
||||
WireCurrency: currency.USD.String(),
|
||||
SwiftCode: "Taylor",
|
||||
RequiresIntermediaryBank: true,
|
||||
IsExpressWire: false,
|
||||
IntermediaryBankAccountNumber: 12345,
|
||||
IntermediaryBankAddress: "123 Fake St",
|
||||
IntermediaryBankCity: "Tarry Town",
|
||||
IntermediaryBankCountry: "Hyrule",
|
||||
IntermediaryBankName: "Federal Reserve Bank",
|
||||
IntermediarySwiftCode: "Taylor",
|
||||
}
|
||||
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -537,26 +537,29 @@ func (b *Bitfinex) GetDepositAddress(c currency.Code, accountID string) (string,
|
||||
}
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted
|
||||
func (b *Bitfinex) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
func (b *Bitfinex) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
// Bitfinex has support for three types, exchange, margin and deposit
|
||||
// As this is for trading, I've made the wrapper default 'exchange'
|
||||
// TODO: Discover an automated way to make the decision for wallet type to withdraw from
|
||||
walletType := "exchange"
|
||||
resp, err := b.WithdrawCryptocurrency(walletType,
|
||||
withdrawRequest.Address,
|
||||
withdrawRequest.Crypto.Address,
|
||||
withdrawRequest.Description,
|
||||
withdrawRequest.Amount,
|
||||
withdrawRequest.Currency)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return strconv.FormatInt(resp.WithdrawalID, 10), err
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: strconv.FormatInt(resp.WithdrawalID, 10),
|
||||
Status: resp.Status,
|
||||
}, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted
|
||||
// Returns comma delimited withdrawal IDs
|
||||
func (b *Bitfinex) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
func (b *Bitfinex) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
withdrawalType := "wire"
|
||||
// Bitfinex has support for three types, exchange, margin and deposit
|
||||
// As this is for trading, I've made the wrapper default 'exchange'
|
||||
@@ -564,16 +567,26 @@ func (b *Bitfinex) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (str
|
||||
walletType := "exchange"
|
||||
resp, err := b.WithdrawFIAT(withdrawalType, walletType, withdrawRequest)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return strconv.FormatInt(resp.WithdrawalID, 10), nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: strconv.FormatInt(resp.WithdrawalID, 10),
|
||||
Status: resp.Status,
|
||||
}, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is submitted
|
||||
// Returns comma delimited withdrawal IDs
|
||||
func (b *Bitfinex) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return b.WithdrawFiatFunds(withdrawRequest)
|
||||
func (b *Bitfinex) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
v, err := b.WithdrawFiatFunds(withdrawRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: v.ID,
|
||||
Status: v.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply your own keys here for due diligence testing
|
||||
@@ -368,13 +368,13 @@ func TestWithdraw(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
_, err := b.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
@@ -400,7 +400,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
|
||||
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrNotYetImplemented {
|
||||
@@ -414,7 +414,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrNotYetImplemented {
|
||||
|
||||
@@ -16,8 +16,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -319,20 +319,20 @@ func (b *Bitflyer) GetDepositAddress(cryptocurrency currency.Code, accountID str
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Bitflyer) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
func (b *Bitflyer) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bitflyer) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
func (b *Bitflyer) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bitflyer) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrNotYetImplemented
|
||||
func (b *Bitflyer) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrNotYetImplemented
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -11,7 +11,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply your own keys here for due diligence testing
|
||||
@@ -450,13 +451,13 @@ func TestWithdraw(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
_, err := b.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
@@ -474,23 +475,16 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.USD,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
var withdrawFiatRequest = withdraw.Request{
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: &banking.Account{},
|
||||
WireCurrency: currency.KRW.String(),
|
||||
RequiresIntermediaryBank: false,
|
||||
IsExpressWire: false,
|
||||
},
|
||||
BankAccountName: "Satoshi Nakamoto",
|
||||
BankAccountNumber: "12345",
|
||||
BankCode: 123,
|
||||
BankAddress: "123 Fake St",
|
||||
BankCity: "Tarry Town",
|
||||
BankCountry: "Hyrule",
|
||||
BankName: "Federal Reserve Bank",
|
||||
WireCurrency: currency.KRW.String(),
|
||||
SwiftCode: "Taylor",
|
||||
RequiresIntermediaryBank: false,
|
||||
IsExpressWire: false,
|
||||
Amount: -1,
|
||||
Currency: currency.USD,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
}
|
||||
|
||||
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
@@ -508,7 +502,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -423,39 +423,47 @@ func (b *Bithumb) GetDepositAddress(cryptocurrency currency.Code, _ string) (str
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Bithumb) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
_, err := b.WithdrawCrypto(withdrawRequest.Address,
|
||||
withdrawRequest.AddressTag,
|
||||
func (b *Bithumb) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
v, err := b.WithdrawCrypto(withdrawRequest.Crypto.Address,
|
||||
withdrawRequest.Crypto.AddressTag,
|
||||
withdrawRequest.Currency.String(),
|
||||
withdrawRequest.Amount)
|
||||
return "", err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: v.Message,
|
||||
Status: v.Status,
|
||||
}, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bithumb) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
func (b *Bithumb) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
if math.Mod(withdrawRequest.Amount, 1) != 0 {
|
||||
return "", errors.New("currency KRW does not support decimal places")
|
||||
return nil, errors.New("currency KRW does not support decimal places")
|
||||
}
|
||||
if withdrawRequest.Currency != currency.KRW {
|
||||
return "", errors.New("only KRW is supported")
|
||||
return nil, errors.New("only KRW is supported")
|
||||
}
|
||||
bankDetails := strconv.FormatFloat(withdrawRequest.BankCode, 'f', -1, 64) +
|
||||
"_" + withdrawRequest.BankName
|
||||
resp, err := b.RequestKRWWithdraw(bankDetails, withdrawRequest.BankAccountNumber, int64(withdrawRequest.Amount))
|
||||
bankDetails := strconv.FormatFloat(withdrawRequest.Fiat.Bank.BankCode, 'f', -1, 64) +
|
||||
"_" + withdrawRequest.Fiat.Bank.BankName
|
||||
resp, err := b.RequestKRWWithdraw(bankDetails, withdrawRequest.Fiat.Bank.AccountNumber, int64(withdrawRequest.Amount))
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
if resp.Status != "0000" {
|
||||
return "", errors.New(resp.Message)
|
||||
return nil, errors.New(resp.Message)
|
||||
}
|
||||
|
||||
return resp.Message, nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
Status: resp.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank is not supported as Bithumb only withdraws KRW to South Korean banks
|
||||
func (b *Bithumb) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (b *Bithumb) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply your own keys here for due diligence testing
|
||||
@@ -608,14 +608,14 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
OneTimePassword: 000000,
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
OneTimePassword: 000000,
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
@@ -636,7 +636,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -648,7 +648,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
|
||||
@@ -18,8 +18,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -523,35 +523,38 @@ func (b *Bitmex) GetDepositAddress(cryptocurrency currency.Code, _ string) (stri
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Bitmex) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
func (b *Bitmex) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
var request = UserRequestWithdrawalParams{
|
||||
Address: withdrawRequest.Address,
|
||||
Address: withdrawRequest.Crypto.Address,
|
||||
Amount: withdrawRequest.Amount,
|
||||
Currency: withdrawRequest.Currency.String(),
|
||||
OtpToken: withdrawRequest.OneTimePassword,
|
||||
}
|
||||
if withdrawRequest.FeeAmount > 0 {
|
||||
request.Fee = withdrawRequest.FeeAmount
|
||||
if withdrawRequest.Crypto.FeeAmount > 0 {
|
||||
request.Fee = withdrawRequest.Crypto.FeeAmount
|
||||
}
|
||||
|
||||
resp, err := b.UserRequestWithdrawal(request)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.TransactID, nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
Status: resp.Text,
|
||||
ID: resp.Tx,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Bitmex) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (b *Bitmex) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Bitmex) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (b *Bitmex) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -8,7 +8,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please add your private keys and customerID for better tests
|
||||
@@ -456,13 +457,13 @@ func TestWithdraw(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
_, err := b.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
@@ -483,24 +484,26 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.USD,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
var withdrawFiatRequest = withdraw.Request{
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: &banking.Account{
|
||||
AccountName: "Satoshi Nakamoto",
|
||||
AccountNumber: "12345",
|
||||
BankAddress: "123 Fake St",
|
||||
BankPostalCity: "Tarry Town",
|
||||
BankCountry: "AU",
|
||||
BankName: "Federal Reserve Bank",
|
||||
SWIFTCode: "CTBAAU2S",
|
||||
BankPostalCode: "2088",
|
||||
IBAN: "IT60X0542811101000000123456",
|
||||
},
|
||||
WireCurrency: currency.USD.String(),
|
||||
RequiresIntermediaryBank: false,
|
||||
IsExpressWire: false,
|
||||
},
|
||||
BankAccountName: "Satoshi Nakamoto",
|
||||
BankAccountNumber: "12345",
|
||||
BankAddress: "123 Fake St",
|
||||
BankCity: "Tarry Town",
|
||||
BankCountry: "AU",
|
||||
BankName: "Federal Reserve Bank",
|
||||
WireCurrency: currency.USD.String(),
|
||||
SwiftCode: "CTBAAU2S",
|
||||
RequiresIntermediaryBank: false,
|
||||
IsExpressWire: false,
|
||||
BankPostalCode: "2088",
|
||||
IBAN: "IT60X0542811101000000123456",
|
||||
Amount: -1,
|
||||
Currency: currency.USD,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
}
|
||||
|
||||
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
@@ -521,30 +524,32 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.USD,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
var withdrawFiatRequest = withdraw.Request{
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: &banking.Account{
|
||||
AccountName: "Satoshi Nakamoto",
|
||||
AccountNumber: "12345",
|
||||
BankAddress: "123 Fake St",
|
||||
BankPostalCity: "Tarry Town",
|
||||
BankCountry: "AU",
|
||||
BankName: "Federal Reserve Bank",
|
||||
SWIFTCode: "CTBAAU2S",
|
||||
BankPostalCode: "2088",
|
||||
IBAN: "IT60X0542811101000000123456",
|
||||
},
|
||||
WireCurrency: currency.USD.String(),
|
||||
RequiresIntermediaryBank: false,
|
||||
IsExpressWire: false,
|
||||
IntermediaryBankAccountNumber: 12345,
|
||||
IntermediaryBankAddress: "123 Fake St",
|
||||
IntermediaryBankCity: "Tarry Town",
|
||||
IntermediaryBankCountry: "AU",
|
||||
IntermediaryBankName: "Federal Reserve Bank",
|
||||
IntermediaryBankPostalCode: "2088",
|
||||
},
|
||||
BankAccountName: "Satoshi Nakamoto",
|
||||
BankAccountNumber: "12345",
|
||||
BankAddress: "123 Fake St",
|
||||
BankCity: "Tarry Town",
|
||||
BankCountry: "AU",
|
||||
BankName: "Federal Reserve Bank",
|
||||
WireCurrency: currency.USD.String(),
|
||||
SwiftCode: "CTBAAU2S",
|
||||
RequiresIntermediaryBank: false,
|
||||
IsExpressWire: false,
|
||||
BankPostalCode: "2088",
|
||||
IBAN: "IT60X0542811101000000123456",
|
||||
IntermediaryBankAccountNumber: 12345,
|
||||
IntermediaryBankAddress: "123 Fake St",
|
||||
IntermediaryBankCity: "Tarry Town",
|
||||
IntermediaryBankCountry: "AU",
|
||||
IntermediaryBankName: "Federal Reserve Bank",
|
||||
IntermediaryBankPostalCode: "2088",
|
||||
Amount: -1,
|
||||
Currency: currency.USD,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
}
|
||||
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -436,86 +436,94 @@ func (b *Bitstamp) GetDepositAddress(cryptocurrency currency.Code, _ string) (st
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Bitstamp) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
func (b *Bitstamp) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
resp, err := b.CryptoWithdrawal(withdrawRequest.Amount,
|
||||
withdrawRequest.Address,
|
||||
withdrawRequest.Crypto.Address,
|
||||
withdrawRequest.Currency.String(),
|
||||
withdrawRequest.AddressTag,
|
||||
withdrawRequest.Crypto.AddressTag,
|
||||
true)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
if len(resp.Error) != 0 {
|
||||
var details strings.Builder
|
||||
for x := range resp.Error {
|
||||
details.WriteString(strings.Join(resp.Error[x], ""))
|
||||
}
|
||||
return "", errors.New(details.String())
|
||||
return nil, errors.New(details.String())
|
||||
}
|
||||
|
||||
return resp.ID, nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: resp.ID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bitstamp) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
func (b *Bitstamp) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
resp, err := b.OpenBankWithdrawal(withdrawRequest.Amount,
|
||||
withdrawRequest.Currency.String(),
|
||||
withdrawRequest.BankAccountName,
|
||||
withdrawRequest.IBAN,
|
||||
withdrawRequest.SwiftCode,
|
||||
withdrawRequest.BankAddress,
|
||||
withdrawRequest.BankPostalCode,
|
||||
withdrawRequest.BankCity,
|
||||
withdrawRequest.BankCountry,
|
||||
withdrawRequest.Fiat.Bank.AccountName,
|
||||
withdrawRequest.Fiat.Bank.IBAN,
|
||||
withdrawRequest.Fiat.Bank.SWIFTCode,
|
||||
withdrawRequest.Fiat.Bank.BankAddress,
|
||||
withdrawRequest.Fiat.Bank.BankPostalCode,
|
||||
withdrawRequest.Fiat.Bank.BankPostalCity,
|
||||
withdrawRequest.Fiat.Bank.BankCountry,
|
||||
withdrawRequest.Description,
|
||||
sepaWithdrawal)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
if resp.Status == errStr {
|
||||
var details strings.Builder
|
||||
for x := range resp.Reason {
|
||||
details.WriteString(strings.Join(resp.Reason[x], ""))
|
||||
}
|
||||
return "", errors.New(details.String())
|
||||
return nil, errors.New(details.String())
|
||||
}
|
||||
|
||||
return resp.ID, nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: resp.ID,
|
||||
Status: resp.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bitstamp) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
func (b *Bitstamp) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
resp, err := b.OpenInternationalBankWithdrawal(withdrawRequest.Amount,
|
||||
withdrawRequest.Currency.String(),
|
||||
withdrawRequest.BankAccountName,
|
||||
withdrawRequest.IBAN,
|
||||
withdrawRequest.SwiftCode,
|
||||
withdrawRequest.BankAddress,
|
||||
withdrawRequest.BankPostalCode,
|
||||
withdrawRequest.BankCity,
|
||||
withdrawRequest.BankCountry,
|
||||
withdrawRequest.IntermediaryBankName,
|
||||
withdrawRequest.IntermediaryBankAddress,
|
||||
withdrawRequest.IntermediaryBankPostalCode,
|
||||
withdrawRequest.IntermediaryBankCity,
|
||||
withdrawRequest.IntermediaryBankCountry,
|
||||
withdrawRequest.WireCurrency,
|
||||
withdrawRequest.Fiat.Bank.AccountName,
|
||||
withdrawRequest.Fiat.Bank.IBAN,
|
||||
withdrawRequest.Fiat.Bank.SWIFTCode,
|
||||
withdrawRequest.Fiat.Bank.BankAddress,
|
||||
withdrawRequest.Fiat.Bank.BankPostalCode,
|
||||
withdrawRequest.Fiat.Bank.BankPostalCity,
|
||||
withdrawRequest.Fiat.Bank.BankCountry,
|
||||
withdrawRequest.Fiat.IntermediaryBankName,
|
||||
withdrawRequest.Fiat.IntermediaryBankAddress,
|
||||
withdrawRequest.Fiat.IntermediaryBankPostalCode,
|
||||
withdrawRequest.Fiat.IntermediaryBankCity,
|
||||
withdrawRequest.Fiat.IntermediaryBankCountry,
|
||||
withdrawRequest.Fiat.WireCurrency,
|
||||
withdrawRequest.Description,
|
||||
internationalWithdrawal)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
if resp.Status == errStr {
|
||||
var details strings.Builder
|
||||
for x := range resp.Reason {
|
||||
details.WriteString(strings.Join(resp.Reason[x], ""))
|
||||
}
|
||||
return "", errors.New(details.String())
|
||||
return nil, errors.New(details.String())
|
||||
}
|
||||
|
||||
return resp.ID, nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: resp.ID,
|
||||
Status: resp.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply you own test keys here to run better tests.
|
||||
@@ -462,13 +462,13 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
@@ -489,7 +489,8 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
|
||||
_, err := b.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -501,7 +502,8 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
|
||||
_, err := b.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
|
||||
@@ -17,8 +17,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -429,21 +429,26 @@ func (b *Bittrex) GetDepositAddress(cryptocurrency currency.Code, _ string) (str
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *Bittrex) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
uuid, err := b.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.AddressTag, withdrawRequest.Address, withdrawRequest.Amount)
|
||||
return uuid.Result.ID, err
|
||||
func (b *Bittrex) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
uuid, err := b.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.Crypto.AddressTag, withdrawRequest.Crypto.Address, withdrawRequest.Amount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: uuid.Result.ID,
|
||||
}, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bittrex) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (b *Bittrex) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *Bittrex) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (b *Bittrex) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -500,43 +500,49 @@ func (b *BTCMarkets) GetDepositAddress(cryptocurrency currency.Code, accountID s
|
||||
}
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted
|
||||
func (b *BTCMarkets) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
func (b *BTCMarkets) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
a, err := b.RequestWithdraw(withdrawRequest.Currency.String(),
|
||||
withdrawRequest.Amount,
|
||||
withdrawRequest.Address,
|
||||
withdrawRequest.Crypto.Address,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"")
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
return a.Status, nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: a.ID,
|
||||
Status: a.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *BTCMarkets) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
func (b *BTCMarkets) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
if withdrawRequest.Currency != currency.AUD {
|
||||
return "", errors.New("only aud is supported for withdrawals")
|
||||
return nil, errors.New("only aud is supported for withdrawals")
|
||||
}
|
||||
a, err := b.RequestWithdraw(withdrawRequest.GenericInfo.Currency.String(),
|
||||
withdrawRequest.GenericInfo.Amount,
|
||||
a, err := b.RequestWithdraw(withdrawRequest.Currency.String(),
|
||||
withdrawRequest.Amount,
|
||||
"",
|
||||
withdrawRequest.BankAccountName,
|
||||
withdrawRequest.BankAccountNumber,
|
||||
withdrawRequest.BSB,
|
||||
withdrawRequest.BankName)
|
||||
withdrawRequest.Fiat.Bank.AccountName,
|
||||
withdrawRequest.Fiat.Bank.AccountNumber,
|
||||
withdrawRequest.Fiat.Bank.BSBNumber,
|
||||
withdrawRequest.Fiat.Bank.BankName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
return a.Status, nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: a.ID,
|
||||
Status: a.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (b *BTCMarkets) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (b *BTCMarkets) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -511,20 +511,20 @@ func (b *BTSE) GetDepositAddress(cryptocurrency currency.Code, accountID string)
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *BTSE) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (b *BTSE) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *BTSE) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (b *BTSE) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (b *BTSE) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (b *BTSE) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -16,7 +16,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
var c CoinbasePro
|
||||
@@ -544,13 +545,13 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
@@ -571,12 +572,14 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: 100,
|
||||
Currency: currency.USD,
|
||||
var withdrawFiatRequest = withdraw.Request{
|
||||
Amount: 100,
|
||||
Currency: currency.USD,
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: &banking.Account{
|
||||
BankName: "Federal Reserve Bank",
|
||||
},
|
||||
},
|
||||
BankName: "Federal Reserve Bank",
|
||||
}
|
||||
|
||||
_, err := c.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
@@ -593,12 +596,14 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: 100,
|
||||
Currency: currency.USD,
|
||||
var withdrawFiatRequest = withdraw.Request{
|
||||
Amount: 100,
|
||||
Currency: currency.USD,
|
||||
Fiat: &withdraw.FiatRequest{
|
||||
Bank: &banking.Account{
|
||||
BankName: "Federal Reserve Bank",
|
||||
},
|
||||
},
|
||||
BankName: "Federal Reserve Bank",
|
||||
}
|
||||
|
||||
_, err := c.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -463,42 +463,56 @@ func (c *CoinbasePro) GetDepositAddress(cryptocurrency currency.Code, accountID
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (c *CoinbasePro) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
resp, err := c.WithdrawCrypto(withdrawRequest.Amount, withdrawRequest.Currency.String(), withdrawRequest.Address)
|
||||
return resp.ID, err
|
||||
func (c *CoinbasePro) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
resp, err := c.WithdrawCrypto(withdrawRequest.Amount, withdrawRequest.Currency.String(), withdrawRequest.Crypto.Address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: resp.ID,
|
||||
}, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (c *CoinbasePro) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
func (c *CoinbasePro) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
paymentMethods, err := c.GetPayMethods()
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
selectedWithdrawalMethod := PaymentMethod{}
|
||||
for i := range paymentMethods {
|
||||
if withdrawRequest.BankName == paymentMethods[i].Name {
|
||||
if withdrawRequest.Fiat.Bank.BankName == paymentMethods[i].Name {
|
||||
selectedWithdrawalMethod = paymentMethods[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
if selectedWithdrawalMethod.ID == "" {
|
||||
return "", fmt.Errorf("could not find payment method '%v'. Check the name via the website and try again", withdrawRequest.BankName)
|
||||
return nil, fmt.Errorf("could not find payment method '%v'. Check the name via the website and try again", withdrawRequest.Fiat.Bank.BankName)
|
||||
}
|
||||
|
||||
resp, err := c.WithdrawViaPaymentMethod(withdrawRequest.Amount, withdrawRequest.Currency.String(), selectedWithdrawalMethod.ID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp.ID, nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
Status: resp.ID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (c *CoinbasePro) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return c.WithdrawFiatFunds(withdrawRequest)
|
||||
func (c *CoinbasePro) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
v, err := c.WithdrawFiatFunds(withdrawRequest)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: v.ID,
|
||||
Status: v.Status,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -18,8 +18,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -560,20 +560,20 @@ func (c *Coinbene) GetDepositAddress(cryptocurrency currency.Code, accountID str
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (c *Coinbene) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (c *Coinbene) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (c *Coinbene) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (c *Coinbene) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (c *Coinbene) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (c *Coinbene) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
var c COINUT
|
||||
@@ -384,13 +384,13 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
@@ -408,7 +408,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := c.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -420,7 +420,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := c.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -664,20 +664,20 @@ func (c *COINUT) GetDepositAddress(cryptocurrency currency.Code, accountID strin
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (c *COINUT) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (c *COINUT) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (c *COINUT) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (c *COINUT) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (c *COINUT) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (c *COINUT) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -222,16 +223,16 @@ func (e *Base) GetPairAssetType(c currency.Pair) (asset.Item, error) {
|
||||
|
||||
// GetClientBankAccounts returns banking details associated with
|
||||
// a client for withdrawal purposes
|
||||
func (e *Base) GetClientBankAccounts(exchangeName, withdrawalCurrency string) (config.BankAccount, error) {
|
||||
func (e *Base) GetClientBankAccounts(exchangeName, withdrawalCurrency string) (*banking.Account, error) {
|
||||
cfg := config.GetConfig()
|
||||
return cfg.GetClientBankAccounts(exchangeName, withdrawalCurrency)
|
||||
}
|
||||
|
||||
// GetExchangeBankAccounts returns banking details associated with an
|
||||
// exchange for funding purposes
|
||||
func (e *Base) GetExchangeBankAccounts(exchangeName, depositCurrency string) (config.BankAccount, error) {
|
||||
func (e *Base) GetExchangeBankAccounts(id, depositCurrency string) (*banking.Account, error) {
|
||||
cfg := config.GetConfig()
|
||||
return cfg.GetExchangeBankAccounts(exchangeName, depositCurrency)
|
||||
return cfg.GetExchangeBankAccounts(e.Name, id, depositCurrency)
|
||||
}
|
||||
|
||||
// SetCurrencyPairFormat checks the exchange request and config currency pair
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/protocol"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/banking"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -311,7 +312,7 @@ func TestGetClientBankAccounts(t *testing.T) {
|
||||
}
|
||||
|
||||
var b Base
|
||||
var r config.BankAccount
|
||||
var r *banking.Account
|
||||
r, err = b.GetClientBankAccounts("Kraken", "USD")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
@@ -321,31 +322,7 @@ func TestGetClientBankAccounts(t *testing.T) {
|
||||
t.Error("incorrect bank name")
|
||||
}
|
||||
|
||||
r, err = b.GetClientBankAccounts("MEOW", "USD")
|
||||
if err == nil {
|
||||
t.Error("an error should have been thrown for a non-existent exchange")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetExchangeBankAccounts(t *testing.T) {
|
||||
cfg := config.GetConfig()
|
||||
err := cfg.LoadConfig(config.TestFile, true)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var b Base
|
||||
var r config.BankAccount
|
||||
r, err = b.GetExchangeBankAccounts("Bitfinex", "USD")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if r.BankName != "Deutsche Bank Privat Und Geschaeftskunden AG" {
|
||||
t.Error("incorrect bank name")
|
||||
}
|
||||
|
||||
_, err = b.GetExchangeBankAccounts("MEOW", "USD")
|
||||
_, err = b.GetClientBankAccounts("MEOW", "USD")
|
||||
if err == nil {
|
||||
t.Error("an error should have been thrown for a non-existent exchange")
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -384,13 +384,13 @@ func TestWithdraw(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
_, err := e.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
@@ -407,7 +407,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := e.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -419,7 +419,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := e.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -434,25 +434,27 @@ func (e *EXMO) GetDepositAddress(cryptocurrency currency.Code, _ string) (string
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (e *EXMO) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
func (e *EXMO) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
resp, err := e.WithdrawCryptocurrency(withdrawRequest.Currency.String(),
|
||||
withdrawRequest.Address,
|
||||
withdrawRequest.AddressTag,
|
||||
withdrawRequest.Crypto.Address,
|
||||
withdrawRequest.Crypto.AddressTag,
|
||||
withdrawRequest.Amount)
|
||||
|
||||
return strconv.FormatInt(resp, 10), err
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: strconv.FormatInt(resp, 10),
|
||||
}, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (e *EXMO) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (e *EXMO) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (e *EXMO) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (e *EXMO) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -497,7 +498,7 @@ func getCryptocurrencyWithdrawalFee(c currency.Code) float64 {
|
||||
}
|
||||
|
||||
// WithdrawCrypto withdraws cryptocurrency to your selected wallet
|
||||
func (g *Gateio) WithdrawCrypto(currency, address string, amount float64) (string, error) {
|
||||
func (g *Gateio) WithdrawCrypto(currency, address string, amount float64) (*withdraw.ExchangeResponse, error) {
|
||||
type response struct {
|
||||
Result bool `json:"result"`
|
||||
Message string `json:"message"`
|
||||
@@ -512,13 +513,15 @@ func (g *Gateio) WithdrawCrypto(currency, address string, amount float64) (strin
|
||||
)
|
||||
err := g.SendAuthenticatedHTTPRequest(http.MethodPost, gateioWithdraw, params, &result)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
if !result.Result {
|
||||
return "", fmt.Errorf("code:%d message:%s", result.Code, result.Message)
|
||||
return nil, fmt.Errorf("code:%d message:%s", result.Code, result.Message)
|
||||
}
|
||||
|
||||
return result.Message, nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
Status: result.Message,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetCryptoDepositAddress returns a deposit address for a cryptocurrency
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply your own APIKEYS here for due diligence testing
|
||||
@@ -407,13 +407,13 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
@@ -434,7 +434,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := g.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -446,7 +446,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := g.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
|
||||
@@ -21,8 +21,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -539,20 +539,20 @@ func (g *Gateio) GetDepositAddress(cryptocurrency currency.Code, _ string) (stri
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (g *Gateio) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
return g.WithdrawCrypto(withdrawRequest.Currency.String(), withdrawRequest.Address, withdrawRequest.Amount)
|
||||
func (g *Gateio) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return g.WithdrawCrypto(withdrawRequest.Currency.String(), withdrawRequest.Crypto.Address, withdrawRequest.Amount)
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (g *Gateio) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (g *Gateio) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (g *Gateio) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (g *Gateio) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please enter sandbox API keys & assigned roles for better testing procedures
|
||||
@@ -479,13 +479,13 @@ func TestModifyOrder(t *testing.T) {
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
t.Parallel()
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
@@ -510,7 +510,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := g.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
@@ -525,7 +525,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := g.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -412,28 +412,30 @@ func (g *Gemini) GetDepositAddress(cryptocurrency currency.Code, _ string) (stri
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (g *Gemini) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
resp, err := g.WithdrawCrypto(withdrawRequest.Address, withdrawRequest.Currency.String(), withdrawRequest.Amount)
|
||||
func (g *Gemini) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
resp, err := g.WithdrawCrypto(withdrawRequest.Crypto.Address, withdrawRequest.Currency.String(), withdrawRequest.Amount)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
if resp.Result == "error" {
|
||||
return "", errors.New(resp.Message)
|
||||
return nil, errors.New(resp.Message)
|
||||
}
|
||||
|
||||
return resp.TXHash, err
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: resp.TXHash,
|
||||
}, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (g *Gemini) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (g *Gemini) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (g *Gemini) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (g *Gemini) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
var h HitBTC
|
||||
@@ -341,13 +341,13 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
@@ -368,7 +368,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := h.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -380,7 +380,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := h.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -484,21 +484,26 @@ func (h *HitBTC) GetDepositAddress(currency currency.Code, _ string) (string, er
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (h *HitBTC) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
_, err := h.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.Address, withdrawRequest.Amount)
|
||||
return "", err
|
||||
func (h *HitBTC) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
v, err := h.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.Crypto.Address, withdrawRequest.Amount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
Status: common.IsEnabled(v),
|
||||
}, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (h *HitBTC) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (h *HitBTC) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (h *HitBTC) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (h *HitBTC) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply you own test keys here for due diligence testing.
|
||||
@@ -557,13 +557,13 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
@@ -584,7 +584,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := h.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -596,7 +596,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := h.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -655,21 +655,26 @@ func (h *HUOBI) GetDepositAddress(cryptocurrency currency.Code, accountID string
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (h *HUOBI) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
resp, err := h.Withdraw(withdrawRequest.Currency, withdrawRequest.Address, withdrawRequest.AddressTag, withdrawRequest.Amount, withdrawRequest.FeeAmount)
|
||||
return strconv.FormatInt(resp, 10), err
|
||||
func (h *HUOBI) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
resp, err := h.Withdraw(withdrawRequest.Currency, withdrawRequest.Crypto.Address, withdrawRequest.Crypto.AddressTag, withdrawRequest.Amount, withdrawRequest.Crypto.FeeAmount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: strconv.FormatInt(resp, 10),
|
||||
}, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (h *HUOBI) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (h *HUOBI) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (h *HUOBI) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (h *HUOBI) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// IBotExchange enforces standard functions for all exchanges supported in
|
||||
@@ -54,9 +54,9 @@ type IBotExchange interface {
|
||||
GetDepositAddress(cryptocurrency currency.Code, accountID string) (string, error)
|
||||
GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)
|
||||
GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)
|
||||
WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error)
|
||||
WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error)
|
||||
WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error)
|
||||
WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)
|
||||
WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)
|
||||
WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)
|
||||
SetHTTPClientUserAgent(ua string)
|
||||
GetHTTPClientUserAgent() string
|
||||
SetClientProxyAddress(addr string) error
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
var i ItBit
|
||||
@@ -391,13 +391,13 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
@@ -415,7 +415,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := i.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -427,7 +427,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := i.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -408,20 +408,20 @@ func (i *ItBit) GetDepositAddress(cryptocurrency currency.Code, accountID string
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (i *ItBit) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (i *ItBit) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (i *ItBit) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (i *ItBit) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (i *ItBit) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (i *ItBit) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
var k Kraken
|
||||
@@ -531,14 +531,14 @@ func TestModifyOrder(t *testing.T) {
|
||||
|
||||
// TestWithdraw wrapper test
|
||||
func TestWithdraw(t *testing.T) {
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.XXBT,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
TradePassword: "Key",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
Amount: -1,
|
||||
Currency: currency.XXBT,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
TradePassword: "Key",
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
@@ -560,13 +560,11 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.EUR,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
TradePassword: "someBank",
|
||||
},
|
||||
var withdrawFiatRequest = withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.EUR,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
TradePassword: "someBank",
|
||||
}
|
||||
|
||||
_, err := k.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
@@ -584,13 +582,11 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.EUR,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
TradePassword: "someBank",
|
||||
},
|
||||
var withdrawFiatRequest = withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.EUR,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
TradePassword: "someBank",
|
||||
}
|
||||
|
||||
_, err := k.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -587,20 +587,38 @@ func (k *Kraken) GetDepositAddress(cryptocurrency currency.Code, _ string) (stri
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal
|
||||
// Populate exchange.WithdrawRequest.TradePassword with withdrawal key name, as set up on your account
|
||||
func (k *Kraken) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
return k.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.TradePassword, withdrawRequest.Amount)
|
||||
func (k *Kraken) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
v, err := k.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.TradePassword, withdrawRequest.Amount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: v,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (k *Kraken) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return k.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.TradePassword, withdrawRequest.Amount)
|
||||
func (k *Kraken) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
v, err := k.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.TradePassword, withdrawRequest.Amount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
Status: v,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (k *Kraken) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return k.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.TradePassword, withdrawRequest.Amount)
|
||||
func (k *Kraken) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
v, err := k.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.TradePassword, withdrawRequest.Amount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
Status: v,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
var l LakeBTC
|
||||
@@ -377,13 +377,13 @@ func TestModifyOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
@@ -404,7 +404,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := l.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -416,7 +416,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := l.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -420,29 +420,31 @@ func (l *LakeBTC) GetDepositAddress(cryptocurrency currency.Code, _ string) (str
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (l *LakeBTC) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
func (l *LakeBTC) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
if withdrawRequest.Currency != currency.BTC {
|
||||
return "", errors.New("only BTC supported for withdrawals")
|
||||
return nil, errors.New("only BTC supported for withdrawals")
|
||||
}
|
||||
|
||||
resp, err := l.CreateWithdraw(withdrawRequest.Amount, withdrawRequest.Description)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return strconv.FormatInt(resp.ID, 10), nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: strconv.FormatInt(resp.ID, 10),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (l *LakeBTC) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (l *LakeBTC) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (l *LakeBTC) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (l *LakeBTC) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -469,23 +469,28 @@ func (l *Lbank) GetDepositAddress(cryptocurrency currency.Code, accountID string
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (l *Lbank) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
resp, err := l.Withdraw(withdrawRequest.Address, withdrawRequest.Currency.String(),
|
||||
func (l *Lbank) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
resp, err := l.Withdraw(withdrawRequest.Crypto.Address, withdrawRequest.Currency.String(),
|
||||
strconv.FormatFloat(withdrawRequest.Amount, 'f', -1, 64), "",
|
||||
withdrawRequest.Description, "")
|
||||
return resp.WithdrawID, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: resp.WithdrawID,
|
||||
}, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (l *Lbank) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (l *Lbank) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (l *Lbank) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (l *Lbank) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply your own APIKEYS here for due diligence testing
|
||||
@@ -334,13 +334,13 @@ func TestModifyOrder(t *testing.T) {
|
||||
func TestWithdraw(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
@@ -361,7 +361,7 @@ func TestWithdraw(t *testing.T) {
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := l.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
@@ -373,7 +373,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := l.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
|
||||
@@ -21,8 +21,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -410,23 +410,26 @@ func (l *LocalBitcoins) GetDepositAddress(cryptocurrency currency.Code, _ string
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (l *LocalBitcoins) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
return "",
|
||||
l.WalletSend(withdrawRequest.Address,
|
||||
withdrawRequest.Amount,
|
||||
withdrawRequest.PIN)
|
||||
func (l *LocalBitcoins) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
err := l.WalletSend(withdrawRequest.Crypto.Address,
|
||||
withdrawRequest.Amount,
|
||||
withdrawRequest.PIN)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (l *LocalBitcoins) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (l *LocalBitcoins) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (l *LocalBitcoins) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (l *LocalBitcoins) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply you own test keys here for due diligence testing.
|
||||
@@ -1061,15 +1061,15 @@ func TestModifyOrder(t *testing.T) {
|
||||
func TestWithdraw(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
TradePassword: "Password",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
FeeAmount: 1,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
FeeAmount: 1,
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
TradePassword: "Password",
|
||||
}
|
||||
|
||||
_, err := o.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
@@ -1079,7 +1079,7 @@ func TestWithdraw(t *testing.T) {
|
||||
// TestWithdrawFiat Wrapper test
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := o.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
@@ -1089,7 +1089,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
// TestSubmitOrder Wrapper test
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := o.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply you own test keys here for due diligence testing.
|
||||
@@ -1753,15 +1753,15 @@ func TestModifyOrder(t *testing.T) {
|
||||
func TestWithdraw(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
t.Parallel()
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
TradePassword: "Password",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
FeeAmount: 1,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
FeeAmount: 1,
|
||||
Amount: -1,
|
||||
Currency: currency.BTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
TradePassword: "Password",
|
||||
}
|
||||
_, err := o.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
testStandardErrorHandling(t, err)
|
||||
@@ -1771,7 +1771,7 @@ func TestWithdraw(t *testing.T) {
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
t.Parallel()
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := o.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
@@ -1784,7 +1784,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
TestSetRealOrderDefaults(t)
|
||||
t.Parallel()
|
||||
var withdrawFiatRequest = withdraw.FiatRequest{}
|
||||
var withdrawFiatRequest = withdraw.Request{}
|
||||
_, err := o.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/orderbook"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Note: GoCryptoTrader wrapper funcs currently only support SPOT trades.
|
||||
@@ -384,38 +384,40 @@ func (o *OKGroup) GetDepositAddress(p currency.Code, accountID string) (string,
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (o *OKGroup) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
func (o *OKGroup) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
withdrawal, err := o.AccountWithdraw(AccountWithdrawRequest{
|
||||
Amount: withdrawRequest.Amount,
|
||||
Currency: withdrawRequest.Currency.Lower().String(),
|
||||
Destination: 4, // 1, 2, 3 are all internal
|
||||
Fee: withdrawRequest.FeeAmount,
|
||||
ToAddress: withdrawRequest.Address,
|
||||
Fee: withdrawRequest.Crypto.FeeAmount,
|
||||
ToAddress: withdrawRequest.Crypto.Address,
|
||||
TradePwd: withdrawRequest.TradePassword,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
if !withdrawal.Result {
|
||||
return strconv.FormatInt(withdrawal.WithdrawalID, 10),
|
||||
return nil,
|
||||
fmt.Errorf("could not withdraw currency %s to %s, no error specified",
|
||||
withdrawRequest.Currency,
|
||||
withdrawRequest.Address)
|
||||
withdrawRequest.Crypto.Address)
|
||||
}
|
||||
|
||||
return strconv.FormatInt(withdrawal.WithdrawalID, 10), nil
|
||||
return &withdraw.ExchangeResponse{
|
||||
ID: strconv.FormatInt(withdrawal.WithdrawalID, 10),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (o *OKGroup) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (o *OKGroup) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (o *OKGroup) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (o *OKGroup) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetActiveOrders retrieves any orders that are active/open
|
||||
|
||||
@@ -499,8 +499,8 @@ func (p *Poloniex) MoveOrder(orderID int64, rate, amount float64, postOnly, imme
|
||||
}
|
||||
|
||||
// Withdraw withdraws a currency to a specific delegated address
|
||||
func (p *Poloniex) Withdraw(currency, address string, amount float64) (bool, error) {
|
||||
result := Withdraw{}
|
||||
func (p *Poloniex) Withdraw(currency, address string, amount float64) (*Withdraw, error) {
|
||||
result := &Withdraw{}
|
||||
values := url.Values{}
|
||||
|
||||
values.Set("currency", currency)
|
||||
@@ -509,14 +509,14 @@ func (p *Poloniex) Withdraw(currency, address string, amount float64) (bool, err
|
||||
|
||||
err := p.SendAuthenticatedHTTPRequest(http.MethodPost, poloniexWithdraw, values, &result)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if result.Error != "" {
|
||||
return false, errors.New(result.Error)
|
||||
return nil, errors.New(result.Error)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetFeeInfo returns fee information
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/order"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// Please supply your own APIKEYS here for due diligence testing
|
||||
@@ -349,15 +349,16 @@ func TestModifyOrder(t *testing.T) {
|
||||
|
||||
func TestWithdraw(t *testing.T) {
|
||||
t.Parallel()
|
||||
withdrawCryptoRequest := withdraw.CryptoRequest{
|
||||
GenericInfo: withdraw.GenericInfo{
|
||||
Amount: 0,
|
||||
Currency: currency.LTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
withdrawCryptoRequest := withdraw.Request{
|
||||
Crypto: &withdraw.CryptoRequest{
|
||||
Address: core.BitcoinDonationAddress,
|
||||
FeeAmount: 1,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
Amount: 0,
|
||||
Currency: currency.LTC,
|
||||
Description: "WITHDRAW IT ALL",
|
||||
TradePassword: "Password",
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders && !mockTests {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
@@ -379,7 +380,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest withdraw.FiatRequest
|
||||
var withdrawFiatRequest withdraw.Request
|
||||
_, err := p.WithdrawFiatFunds(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
@@ -393,7 +394,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
var withdrawFiatRequest withdraw.FiatRequest
|
||||
var withdrawFiatRequest withdraw.Request
|
||||
_, err := p.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
||||
if err != common.ErrFunctionNotSupported {
|
||||
t.Errorf("Expected '%v', received: '%v'",
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/ticker"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
|
||||
"github.com/thrasher-corp/gocryptotrader/exchanges/withdraw"
|
||||
"github.com/thrasher-corp/gocryptotrader/log"
|
||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||
)
|
||||
|
||||
// GetDefaultConfig returns a default exchange config
|
||||
@@ -478,21 +478,26 @@ func (p *Poloniex) GetDepositAddress(cryptocurrency currency.Code, _ string) (st
|
||||
|
||||
// WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is
|
||||
// submitted
|
||||
func (p *Poloniex) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.CryptoRequest) (string, error) {
|
||||
_, err := p.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.Address, withdrawRequest.Amount)
|
||||
return "", err
|
||||
func (p *Poloniex) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
v, err := p.Withdraw(withdrawRequest.Currency.String(), withdrawRequest.Crypto.Address, withdrawRequest.Amount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &withdraw.ExchangeResponse{
|
||||
Status: v.Response,
|
||||
}, err
|
||||
}
|
||||
|
||||
// WithdrawFiatFunds returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (p *Poloniex) WithdrawFiatFunds(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (p *Poloniex) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a
|
||||
// withdrawal is submitted
|
||||
func (p *Poloniex) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.FiatRequest) (string, error) {
|
||||
return "", common.ErrFunctionNotSupported
|
||||
func (p *Poloniex) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error) {
|
||||
return nil, common.ErrFunctionNotSupported
|
||||
}
|
||||
|
||||
// GetWebsocket returns a pointer to the exchange websocket
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package withdraw
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
)
|
||||
|
||||
// Valid takes interface and passes to asset type to check the request meets requirements to submit
|
||||
func Valid(request interface{}) error {
|
||||
switch request := request.(type) {
|
||||
case *FiatRequest:
|
||||
return ValidateFiat(request)
|
||||
case *CryptoRequest:
|
||||
return ValidateCrypto(request)
|
||||
default:
|
||||
return ErrInvalidRequest
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateFiat checks if Fiat request is valid
|
||||
func ValidateFiat(request *FiatRequest) (err error) {
|
||||
if request == nil {
|
||||
return ErrRequestCannotBeNil
|
||||
}
|
||||
|
||||
var allErrors []string
|
||||
if (request.Currency != currency.Code{}) {
|
||||
if !request.Currency.IsFiatCurrency() {
|
||||
allErrors = append(allErrors, "currency is not a fiat currency")
|
||||
}
|
||||
} else {
|
||||
allErrors = append(allErrors, ErrStrNoCurrencySet)
|
||||
}
|
||||
|
||||
if request.Amount <= 0 {
|
||||
allErrors = append(allErrors, ErrStrAmountMustBeGreaterThanZero)
|
||||
}
|
||||
|
||||
if len(allErrors) > 0 {
|
||||
err = errors.New(strings.Join(allErrors, ", "))
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// ValidateCrypto checks if Crypto request is valid
|
||||
func ValidateCrypto(request *CryptoRequest) (err error) {
|
||||
if request == nil {
|
||||
return ErrRequestCannotBeNil
|
||||
}
|
||||
|
||||
var allErrors []string
|
||||
if (request.Currency != currency.Code{}) {
|
||||
if !request.Currency.IsCryptocurrency() {
|
||||
allErrors = append(allErrors, "currency is not a crypto currency")
|
||||
}
|
||||
} else {
|
||||
allErrors = append(allErrors, ErrStrNoCurrencySet)
|
||||
}
|
||||
|
||||
if request.Amount <= 0 {
|
||||
allErrors = append(allErrors, ErrStrAmountMustBeGreaterThanZero)
|
||||
}
|
||||
|
||||
if request.Address == "" {
|
||||
allErrors = append(allErrors, ErrStrAddressNotSet)
|
||||
}
|
||||
|
||||
if len(allErrors) > 0 {
|
||||
err = errors.New(strings.Join(allErrors, ", "))
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
package withdraw
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/core"
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
)
|
||||
|
||||
var (
|
||||
validFiatRequest = &FiatRequest{
|
||||
GenericInfo: GenericInfo{
|
||||
Currency: currency.AUD,
|
||||
Description: "Test Withdrawal",
|
||||
Amount: 0.1,
|
||||
},
|
||||
BankAccountName: "test-bank-account",
|
||||
BankAccountNumber: "test-bank-number",
|
||||
BankName: "test-bank-name",
|
||||
BSB: "",
|
||||
SwiftCode: "",
|
||||
IBAN: "",
|
||||
}
|
||||
|
||||
invalidFiatRequest = &FiatRequest{}
|
||||
invalidCurrencyFiatRequest = &FiatRequest{
|
||||
GenericInfo: GenericInfo{
|
||||
Currency: currency.BTC,
|
||||
Amount: 1,
|
||||
},
|
||||
}
|
||||
|
||||
validCryptoRequest = &CryptoRequest{
|
||||
GenericInfo: GenericInfo{
|
||||
Currency: currency.BTC,
|
||||
Description: "Test Withdrawal",
|
||||
Amount: 0.1,
|
||||
},
|
||||
Address: core.BitcoinDonationAddress,
|
||||
}
|
||||
invalidCryptoRequest = &CryptoRequest{}
|
||||
invalidCurrencyCryptoRequest = &CryptoRequest{
|
||||
GenericInfo: GenericInfo{
|
||||
Currency: currency.AUD,
|
||||
Amount: 0,
|
||||
},
|
||||
}
|
||||
invalidCryptoAddressRequest = &CryptoRequest{
|
||||
GenericInfo: GenericInfo{
|
||||
Currency: currency.BTC,
|
||||
Description: "Test Withdrawal",
|
||||
Amount: 0.1,
|
||||
},
|
||||
Address: "1D10TH0RS3",
|
||||
}
|
||||
)
|
||||
|
||||
func TestValid(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
request interface{}
|
||||
output interface{}
|
||||
}{
|
||||
{
|
||||
"Fiat",
|
||||
validFiatRequest,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"Crypto",
|
||||
validCryptoRequest,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"Invalid",
|
||||
nil,
|
||||
ErrInvalidRequest,
|
||||
},
|
||||
}
|
||||
for _, tests := range testCases {
|
||||
test := tests
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
err := Valid(test.request)
|
||||
if err != nil {
|
||||
if test.output.(error).Error() != err.Error() {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateFiat(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
request *FiatRequest
|
||||
output interface{}
|
||||
}{
|
||||
{
|
||||
"Valid",
|
||||
validFiatRequest,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"Invalid",
|
||||
invalidFiatRequest,
|
||||
errors.New("currency not set, amount must be greater than 0"),
|
||||
},
|
||||
{
|
||||
"NoRequest",
|
||||
nil,
|
||||
ErrRequestCannotBeNil,
|
||||
},
|
||||
{
|
||||
"CryptoCurrency",
|
||||
invalidCurrencyFiatRequest,
|
||||
errors.New("currency is not a fiat currency"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tests := range testCases {
|
||||
test := tests
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
err := ValidateFiat(test.request)
|
||||
if err != nil {
|
||||
if test.output.(error).Error() != err.Error() {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateCrypto(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
request *CryptoRequest
|
||||
output interface{}
|
||||
}{
|
||||
{
|
||||
"Valid",
|
||||
validCryptoRequest,
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"Invalid",
|
||||
invalidCryptoRequest,
|
||||
errors.New("currency not set, amount must be greater than 0, address cannot be empty"),
|
||||
},
|
||||
{
|
||||
"NoRequest",
|
||||
nil,
|
||||
ErrRequestCannotBeNil,
|
||||
},
|
||||
{
|
||||
"FiatCurrency",
|
||||
invalidCurrencyCryptoRequest,
|
||||
errors.New("currency is not a crypto currency, amount must be greater than 0, address cannot be empty"),
|
||||
},
|
||||
{
|
||||
"InvalidAddress",
|
||||
invalidCryptoAddressRequest,
|
||||
errors.New(ErrStrAddressisInvalid),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tests := range testCases {
|
||||
test := tests
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
err := ValidateCrypto(test.request)
|
||||
if err != nil {
|
||||
if test.output.(error).Error() != err.Error() {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
package withdraw
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||
)
|
||||
|
||||
const (
|
||||
// ErrStrAmountMustBeGreaterThanZero message to return when withdraw amount is less than 0
|
||||
ErrStrAmountMustBeGreaterThanZero = "amount must be greater than 0"
|
||||
// ErrStrAddressisInvalid message to return when address is invalid for crypto request
|
||||
ErrStrAddressisInvalid = "address is not valid"
|
||||
// ErrStrAddressNotSet message to return when address is empty
|
||||
ErrStrAddressNotSet = "address cannot be empty"
|
||||
// ErrStrNoCurrencySet message to return when no currency is set
|
||||
ErrStrNoCurrencySet = "currency not set"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrRequestCannotBeNil message to return when a request is nil
|
||||
ErrRequestCannotBeNil = errors.New("request cannot be nil")
|
||||
// ErrInvalidRequest message to return when a request is invalid
|
||||
ErrInvalidRequest = errors.New("invalid request type")
|
||||
)
|
||||
|
||||
// GenericInfo stores genric withdraw request info
|
||||
type GenericInfo struct {
|
||||
// General withdraw information
|
||||
Currency currency.Code
|
||||
Description string
|
||||
OneTimePassword int64
|
||||
AccountID string
|
||||
PIN int64
|
||||
TradePassword string
|
||||
Amount float64
|
||||
}
|
||||
|
||||
// CryptoRequest stores the info required for a crypto withdrawal request
|
||||
type CryptoRequest struct {
|
||||
GenericInfo
|
||||
// Crypto related information
|
||||
Address string
|
||||
AddressTag string
|
||||
FeeAmount float64
|
||||
}
|
||||
|
||||
// FiatRequest used for fiat withdrawal requests
|
||||
type FiatRequest struct {
|
||||
GenericInfo
|
||||
// FIAT related information
|
||||
BankAccountName string
|
||||
BankAccountNumber string
|
||||
BankName string
|
||||
BankAddress string
|
||||
BankCity string
|
||||
BankCountry string
|
||||
BankPostalCode string
|
||||
BSB string
|
||||
SwiftCode string
|
||||
IBAN string
|
||||
BankCode float64
|
||||
IsExpressWire bool
|
||||
// Intermediary bank information
|
||||
RequiresIntermediaryBank bool
|
||||
IntermediaryBankAccountNumber float64
|
||||
IntermediaryBankName string
|
||||
IntermediaryBankAddress string
|
||||
IntermediaryBankCity string
|
||||
IntermediaryBankCountry string
|
||||
IntermediaryBankPostalCode string
|
||||
IntermediarySwiftCode string
|
||||
IntermediaryBankCode float64
|
||||
IntermediaryIBAN string
|
||||
WireCurrency string
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user