exchanges/engine: Add multichain deposit/withdrawal support (#794)

* Add exchange multichain support

* Start tidying up

* Add multichain transfer support for Bitfinex and fix poloniex bug

* Add Coinbene multichain support

* Start adjusting the deposit address manager

* Fix deposit tests and further enhancements

* Cleanup

* Add bypass flag, expand tests plus error coverage for Huobi

Adjust helpers

* Address nitterinos

* BFX wd changes

* Address nitterinos

* Minor fixes rebasing on master

* Fix BFX acceptableMethods test

* Add some TO-DOs for 2 tests WRT races

* Fix acceptableMethods test round 2

* Address nitterinos
This commit is contained in:
Adrian Gallagher
2021-10-15 15:55:38 +11:00
committed by GitHub
parent b093a7df19
commit 0c00b7e1df
145 changed files with 46329 additions and 5507 deletions

View File

@@ -3,7 +3,7 @@ echo "GoCryptoTrader: Generating gRPC, proxy and swagger files."
# $GOPATH/pkg/mod/github.com/grpc-ecosystem/grpc-gateway/v2@v2.0.1/third_party/googleapis
export GOPATH=$(go env GOPATH)
protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=. rpc.proto
protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go-grpc_out=. rpc.proto
protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=logtostderr=true:. rpc.proto
protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=paths=source_relative:. rpc.proto
protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go-grpc_out=paths=source_relative:. rpc.proto
protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --grpc-gateway_out=paths=source_relative,logtostderr=true:. rpc.proto
protoc -I=. -I=$GOPATH/src -I=$GOPATH/src/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --openapiv2_out=logtostderr=true:. rpc.proto

View File

@@ -3,7 +3,7 @@ echo GoCryptoTrader: Generating gRPC, proxy and swagger files.
REM You may need to include the go mod package for the annotations file:
REM %GOPATH%\pkg\mod\github.com\grpc-ecosystem\grpc-gateway\v2@v2.0.1\third_party\googleapis
protoc -I=. -I=%GOPATH%\src -I=%GOPATH%\src\github.com\grpc-ecosystem\grpc-gateway\third_party\googleapis --go_out=. rpc.proto
protoc -I=. -I=%GOPATH%\src -I=%GOPATH%\src\github.com\grpc-ecosystem\grpc-gateway\third_party\googleapis --go-grpc_out=. rpc.proto
protoc -I=. -I=%GOPATH%\src -I=%GOPATH%\src\github.com\grpc-ecosystem\grpc-gateway\third_party\googleapis --grpc-gateway_out=logtostderr=true:. rpc.proto
protoc -I=. -I=%GOPATH%\src -I=%GOPATH%\src\github.com\grpc-ecosystem\grpc-gateway\third_party\googleapis --go_out=paths=source_relative:. rpc.proto
protoc -I=. -I=%GOPATH%\src -I=%GOPATH%\src\github.com\grpc-ecosystem\grpc-gateway\third_party\googleapis --go-grpc_out=paths=source_relative:. rpc.proto
protoc -I=. -I=%GOPATH%\src -I=%GOPATH%\src\github.com\grpc-ecosystem\grpc-gateway\third_party\googleapis --grpc-gateway_out=paths=source_relative,logtostderr=true:. rpc.proto
protoc -I=. -I=%GOPATH%\src -I=%GOPATH%\src\github.com\grpc-ecosystem\grpc-gateway\third_party\googleapis --openapiv2_out=logtostderr=true:. rpc.proto

File diff suppressed because it is too large Load Diff

View File

@@ -1157,6 +1157,40 @@ func local_request_GoCryptoTrader_GetCryptocurrencyDepositAddress_0(ctx context.
}
func request_GoCryptoTrader_GetAvailableTransferChains_0(ctx context.Context, marshaler runtime.Marshaler, client GoCryptoTraderClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetAvailableTransferChainsRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.GetAvailableTransferChains(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_GoCryptoTrader_GetAvailableTransferChains_0(ctx context.Context, marshaler runtime.Marshaler, server GoCryptoTraderServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetAvailableTransferChainsRequest
var metadata runtime.ServerMetadata
newReader, berr := utilities.IOReaderFactory(req.Body)
if berr != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", berr)
}
if err := marshaler.NewDecoder(newReader()).Decode(&protoReq); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.GetAvailableTransferChains(ctx, &protoReq)
return msg, metadata, err
}
func request_GoCryptoTrader_WithdrawFiatFunds_0(ctx context.Context, marshaler runtime.Marshaler, client GoCryptoTraderClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq WithdrawFiatRequest
var metadata runtime.ServerMetadata
@@ -3876,6 +3910,29 @@ func RegisterGoCryptoTraderHandlerServer(ctx context.Context, mux *runtime.Serve
})
mux.Handle("POST", pattern_GoCryptoTrader_GetAvailableTransferChains_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/gctrpc.GoCryptoTrader/GetAvailableTransferChains", runtime.WithHTTPPathPattern("/v1/getavailabletransferchains"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_GoCryptoTrader_GetAvailableTransferChains_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_GoCryptoTrader_GetAvailableTransferChains_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_GoCryptoTrader_WithdrawFiatFunds_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@@ -5859,6 +5916,26 @@ func RegisterGoCryptoTraderHandlerClient(ctx context.Context, mux *runtime.Serve
})
mux.Handle("POST", pattern_GoCryptoTrader_GetAvailableTransferChains_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/gctrpc.GoCryptoTrader/GetAvailableTransferChains", runtime.WithHTTPPathPattern("/v1/getavailabletransferchains"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_GoCryptoTrader_GetAvailableTransferChains_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_GoCryptoTrader_GetAvailableTransferChains_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_GoCryptoTrader_WithdrawFiatFunds_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@@ -7021,6 +7098,8 @@ var (
pattern_GoCryptoTrader_GetCryptocurrencyDepositAddress_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getcryptodepositaddress"}, ""))
pattern_GoCryptoTrader_GetAvailableTransferChains_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getavailabletransferchains"}, ""))
pattern_GoCryptoTrader_WithdrawFiatFunds_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "withdrawfiatfunds"}, ""))
pattern_GoCryptoTrader_WithdrawCryptocurrencyFunds_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "withdrawithdrawcryptofundswfiatfunds"}, ""))
@@ -7209,6 +7288,8 @@ var (
forward_GoCryptoTrader_GetCryptocurrencyDepositAddress_0 = runtime.ForwardResponseMessage
forward_GoCryptoTrader_GetAvailableTransferChains_0 = runtime.ForwardResponseMessage
forward_GoCryptoTrader_WithdrawFiatFunds_0 = runtime.ForwardResponseMessage
forward_GoCryptoTrader_WithdrawCryptocurrencyFunds_0 = runtime.ForwardResponseMessage

View File

@@ -461,17 +461,39 @@ message GetCryptocurrencyDepositAddressesRequest {
string exchange = 1;
}
message DepositAddress {
string address = 1;
string tag = 2;
string chain = 3;
}
message DepositAddresses {
repeated DepositAddress addresses = 1;
}
message GetCryptocurrencyDepositAddressesResponse {
map<string, string> addresses = 1;
map<string, DepositAddresses> addresses = 1;
}
message GetCryptocurrencyDepositAddressRequest {
string exchange = 1;
string cryptocurrency = 2;
string chain = 3;
bool bypass = 4;
}
message GetCryptocurrencyDepositAddressResponse {
string address = 1;
string tag = 2;
}
message GetAvailableTransferChainsRequest {
string exchange = 1;
string cryptocurrency = 2;
}
message GetAvailableTransferChainsResponse {
repeated string chains = 1;
}
message WithdrawFiatRequest {
@@ -490,6 +512,7 @@ message WithdrawCryptoRequest {
double amount = 5;
double fee = 6;
string description = 7;
string chain = 8;
}
message WithdrawResponse {
@@ -1254,6 +1277,12 @@ service GoCryptoTrader {
};
}
rpc GetAvailableTransferChains(GetAvailableTransferChainsRequest) returns (GetAvailableTransferChainsResponse) {
option (google.api.http) = {
post: "/v1/getavailabletransferchains"
body: "*"
};
}
rpc WithdrawFiatFunds(WithdrawFiatRequest) returns (WithdrawResponse) {
option (google.api.http) = {

View File

@@ -1127,6 +1127,38 @@
]
}
},
"/v1/getavailabletransferchains": {
"post": {
"operationId": "GoCryptoTrader_GetAvailableTransferChains",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/gctrpcGetAvailableTransferChainsResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/gctrpcGetAvailableTransferChainsRequest"
}
}
],
"tags": [
"GoCryptoTrader"
]
}
},
"/v1/getcommunicationrelayers": {
"get": {
"operationId": "GoCryptoTrader_GetCommunicationRelayers",
@@ -3656,6 +3688,31 @@
}
}
},
"gctrpcDepositAddress": {
"type": "object",
"properties": {
"address": {
"type": "string"
},
"tag": {
"type": "string"
},
"chain": {
"type": "string"
}
}
},
"gctrpcDepositAddresses": {
"type": "object",
"properties": {
"addresses": {
"type": "array",
"items": {
"$ref": "#/definitions/gctrpcDepositAddress"
}
}
}
},
"gctrpcFiatWithdrawalEvent": {
"type": "object",
"properties": {
@@ -3891,6 +3948,28 @@
}
}
},
"gctrpcGetAvailableTransferChainsRequest": {
"type": "object",
"properties": {
"exchange": {
"type": "string"
},
"cryptocurrency": {
"type": "string"
}
}
},
"gctrpcGetAvailableTransferChainsResponse": {
"type": "object",
"properties": {
"chains": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"gctrpcGetCommunicationRelayersResponse": {
"type": "object",
"properties": {
@@ -3919,6 +3998,12 @@
},
"cryptocurrency": {
"type": "string"
},
"chain": {
"type": "string"
},
"bypass": {
"type": "boolean"
}
}
},
@@ -3927,6 +4012,9 @@
"properties": {
"address": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
@@ -3944,7 +4032,7 @@
"addresses": {
"type": "object",
"additionalProperties": {
"type": "string"
"$ref": "#/definitions/gctrpcDepositAddresses"
}
}
}
@@ -5075,6 +5163,9 @@
},
"description": {
"type": "string"
},
"chain": {
"type": "string"
}
}
},

View File

@@ -57,6 +57,7 @@ type GoCryptoTraderClient interface {
RemoveEvent(ctx context.Context, in *RemoveEventRequest, opts ...grpc.CallOption) (*GenericResponse, error)
GetCryptocurrencyDepositAddresses(ctx context.Context, in *GetCryptocurrencyDepositAddressesRequest, opts ...grpc.CallOption) (*GetCryptocurrencyDepositAddressesResponse, error)
GetCryptocurrencyDepositAddress(ctx context.Context, in *GetCryptocurrencyDepositAddressRequest, opts ...grpc.CallOption) (*GetCryptocurrencyDepositAddressResponse, error)
GetAvailableTransferChains(ctx context.Context, in *GetAvailableTransferChainsRequest, opts ...grpc.CallOption) (*GetAvailableTransferChainsResponse, error)
WithdrawFiatFunds(ctx context.Context, in *WithdrawFiatRequest, opts ...grpc.CallOption) (*WithdrawResponse, error)
WithdrawCryptocurrencyFunds(ctx context.Context, in *WithdrawCryptoRequest, opts ...grpc.CallOption) (*WithdrawResponse, error)
WithdrawalEventByID(ctx context.Context, in *WithdrawalEventByIDRequest, opts ...grpc.CallOption) (*WithdrawalEventByIDResponse, error)
@@ -495,6 +496,15 @@ func (c *goCryptoTraderClient) GetCryptocurrencyDepositAddress(ctx context.Conte
return out, nil
}
func (c *goCryptoTraderClient) GetAvailableTransferChains(ctx context.Context, in *GetAvailableTransferChainsRequest, opts ...grpc.CallOption) (*GetAvailableTransferChainsResponse, error) {
out := new(GetAvailableTransferChainsResponse)
err := c.cc.Invoke(ctx, "/gctrpc.GoCryptoTrader/GetAvailableTransferChains", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *goCryptoTraderClient) WithdrawFiatFunds(ctx context.Context, in *WithdrawFiatRequest, opts ...grpc.CallOption) (*WithdrawResponse, error) {
out := new(WithdrawResponse)
err := c.cc.Invoke(ctx, "/gctrpc.GoCryptoTrader/WithdrawFiatFunds", in, out, opts...)
@@ -1139,6 +1149,7 @@ type GoCryptoTraderServer interface {
RemoveEvent(context.Context, *RemoveEventRequest) (*GenericResponse, error)
GetCryptocurrencyDepositAddresses(context.Context, *GetCryptocurrencyDepositAddressesRequest) (*GetCryptocurrencyDepositAddressesResponse, error)
GetCryptocurrencyDepositAddress(context.Context, *GetCryptocurrencyDepositAddressRequest) (*GetCryptocurrencyDepositAddressResponse, error)
GetAvailableTransferChains(context.Context, *GetAvailableTransferChainsRequest) (*GetAvailableTransferChainsResponse, error)
WithdrawFiatFunds(context.Context, *WithdrawFiatRequest) (*WithdrawResponse, error)
WithdrawCryptocurrencyFunds(context.Context, *WithdrawCryptoRequest) (*WithdrawResponse, error)
WithdrawalEventByID(context.Context, *WithdrawalEventByIDRequest) (*WithdrawalEventByIDResponse, error)
@@ -1317,6 +1328,9 @@ func (UnimplementedGoCryptoTraderServer) GetCryptocurrencyDepositAddresses(conte
func (UnimplementedGoCryptoTraderServer) GetCryptocurrencyDepositAddress(context.Context, *GetCryptocurrencyDepositAddressRequest) (*GetCryptocurrencyDepositAddressResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetCryptocurrencyDepositAddress not implemented")
}
func (UnimplementedGoCryptoTraderServer) GetAvailableTransferChains(context.Context, *GetAvailableTransferChainsRequest) (*GetAvailableTransferChainsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetAvailableTransferChains not implemented")
}
func (UnimplementedGoCryptoTraderServer) WithdrawFiatFunds(context.Context, *WithdrawFiatRequest) (*WithdrawResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method WithdrawFiatFunds not implemented")
}
@@ -2197,6 +2211,24 @@ func _GoCryptoTrader_GetCryptocurrencyDepositAddress_Handler(srv interface{}, ct
return interceptor(ctx, in, info, handler)
}
func _GoCryptoTrader_GetAvailableTransferChains_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetAvailableTransferChainsRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(GoCryptoTraderServer).GetAvailableTransferChains(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/gctrpc.GoCryptoTrader/GetAvailableTransferChains",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(GoCryptoTraderServer).GetAvailableTransferChains(ctx, req.(*GetAvailableTransferChainsRequest))
}
return interceptor(ctx, in, info, handler)
}
func _GoCryptoTrader_WithdrawFiatFunds_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(WithdrawFiatRequest)
if err := dec(in); err != nil {
@@ -3343,6 +3375,10 @@ var GoCryptoTrader_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetCryptocurrencyDepositAddress",
Handler: _GoCryptoTrader_GetCryptocurrencyDepositAddress_Handler,
},
{
MethodName: "GetAvailableTransferChains",
Handler: _GoCryptoTrader_GetAvailableTransferChains_Handler,
},
{
MethodName: "WithdrawFiatFunds",
Handler: _GoCryptoTrader_WithdrawFiatFunds_Handler,