(Exchanges) Introduce validation method and small updates (#565)

* Remove pointer reference

* Fix portfolio withdraw tests

* Add nil protection in validator method to reduce prospective panics and for future outbound checking

* Updated tests

* ch order var to not ref package

* rm comparison

* Add order ID validation check

* Add exchange name validation check

* Add in test details

* fix tests

* fix linter issues

* linter issues strikes again

* linter rabbit hole

* Addr nitterinos

* Add validation variadic interface to define sets of functionality check POC

* didn't want to add an amount other than 0, didn't want to add address to exchange withdraw, didn't want to whitlist, can change if need be

* add coverage

* Add validation method options for exchange wrappers and abstracted validation into its own package

* Add validation code for structs in exchange template generation

* remove extra validation call as this is done in wrapper

* fix niterinos for examplerinos

* Add template to documentation tool and regenerated documentation

* Addr niticles

* Fix tests due to validation update

* Add more validation checks for modify/submit orders

* update tests

* fix more tests

* Add asset type to submit variable in tests and rpc call. Regen funcs.

* Add field to modify struct in tests

* applied field asset to cancel struct across project

* fix woopsy
This commit is contained in:
Ryan O'Hara-Reid
2020-10-02 13:36:01 +10:00
committed by GitHub
parent ecbc68561f
commit 4e828a8124
93 changed files with 3070 additions and 1676 deletions

View File

@@ -14,7 +14,6 @@ import (
"github.com/thrasher-corp/gocryptotrader/database/repository"
exchangeDB "github.com/thrasher-corp/gocryptotrader/database/repository/exchange"
"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"
@@ -299,13 +298,15 @@ func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
}
for x := range v {
var tempResp = &withdraw.Response{}
newUUID, _ := uuid.FromString(v[x].ID)
var newUUID uuid.UUID
newUUID, err = uuid.FromString(v[x].ID)
if err != nil {
return nil, err
}
tempResp.ID = newUUID
tempResp.Exchange = new(withdraw.ExchangeResponse)
tempResp.Exchange.ID = v[x].ExchangeID
tempResp.Exchange.Status = v[x].Status
tempResp.RequestDetails = new(withdraw.Request)
tempResp.RequestDetails = &withdraw.Request{
tempResp.RequestDetails = withdraw.Request{
Currency: currency.NewCode(v[x].Currency),
Description: v[x].Description.String,
Amount: v[x].Amount,
@@ -346,7 +347,6 @@ func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
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
@@ -355,8 +355,6 @@ func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
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
@@ -375,11 +373,9 @@ func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
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.Status = v[x].Status
tempResp.RequestDetails = new(withdraw.Request)
tempResp.RequestDetails = &withdraw.Request{
tempResp.RequestDetails = withdraw.Request{
Currency: currency.NewCode(v[x].Currency),
Description: v[x].Description.String,
Amount: v[x].Amount,
@@ -402,7 +398,6 @@ func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
}
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
@@ -411,12 +406,10 @@ func getByColumns(q []qm.QueryMod) ([]*withdraw.Response, error) {
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

View File

@@ -112,27 +112,36 @@ func seedWithdrawData() {
for x := 0; x < 20; x++ {
test := fmt.Sprintf("test-%v", x)
resp := &withdraw.Response{
Exchange: &withdraw.ExchangeResponse{
Exchange: withdraw.ExchangeResponse{
Name: testExchanges[0].Name,
ID: test,
Status: test,
},
RequestDetails: &withdraw.Request{
RequestDetails: withdraw.Request{
Exchange: testExchanges[0].Name,
Description: test,
Amount: 1.0,
Fiat: withdraw.FiatRequest{
Bank: banking.Account{
Enabled: false,
ID: fmt.Sprintf("test-%v", x),
BankName: fmt.Sprintf("test-%v-bank", x),
AccountName: "hello",
AccountNumber: fmt.Sprintf("test-%v", x),
BSBNumber: "123456",
SupportedCurrencies: "BTC-AUD",
SupportedExchanges: testExchanges[0].Name,
},
},
},
}
rnd := rand.Intn(2) // nolint:gosec // used for generating test data, no need to import crypo/rand
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