added the TokenTransfer functionality and mocks
This commit is contained in:
parent
c10e1a6a1b
commit
c34906cb1f
@ -28,7 +28,6 @@ func (m *MockAccountService) TrackAccountStatus(ctx context.Context, trackingId
|
|||||||
return args.Get(0).(*models.TrackStatusResult), args.Error(1)
|
return args.Get(0).(*models.TrackStatusResult), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (m *MockAccountService) FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
|
func (m *MockAccountService) FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
|
||||||
args := m.Called(publicKey)
|
args := m.Called(publicKey)
|
||||||
return args.Get(0).([]dataserviceapi.TokenHoldings), args.Error(1)
|
return args.Get(0).([]dataserviceapi.TokenHoldings), args.Error(1)
|
||||||
@ -39,7 +38,12 @@ func (m *MockAccountService) FetchTransactions(ctx context.Context, publicKey st
|
|||||||
return args.Get(0).([]dataserviceapi.Last10TxResponse), args.Error(1)
|
return args.Get(0).([]dataserviceapi.Last10TxResponse), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func(m MockAccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
|
func (m *MockAccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
|
||||||
args := m.Called(address)
|
args := m.Called(address)
|
||||||
return args.Get(0).(*models.VoucherDataResult), args.Error(1)
|
return args.Get(0).(*models.VoucherDataResult), args.Error(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *MockAccountService) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) {
|
||||||
|
args := m.Called()
|
||||||
|
return args.Get(0).(*models.TokenTransferResponse), args.Error(1)
|
||||||
|
}
|
||||||
|
@ -50,3 +50,9 @@ func (tas *TestAccountService) FetchTransactions(ctx context.Context, publicKey
|
|||||||
func (m TestAccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
|
func (m TestAccountService) VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error) {
|
||||||
return &models.VoucherDataResult{}, nil
|
return &models.VoucherDataResult{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tas *TestAccountService) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) {
|
||||||
|
return &models.TokenTransferResponse{
|
||||||
|
TrackingId: "e034d147-747d-42ea-928d-b5a7cb3426af",
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
@ -23,6 +23,7 @@ type AccountServiceInterface interface {
|
|||||||
FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error)
|
FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error)
|
||||||
FetchTransactions(ctx context.Context, publicKey string) ([]dataserviceapi.Last10TxResponse, error)
|
FetchTransactions(ctx context.Context, publicKey string) ([]dataserviceapi.Last10TxResponse, error)
|
||||||
VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error)
|
VoucherData(ctx context.Context, address string) (*models.VoucherDataResult, error)
|
||||||
|
TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountService struct {
|
type AccountService struct {
|
||||||
@ -167,6 +168,41 @@ func (as *AccountService) VoucherData(ctx context.Context, address string) (*mod
|
|||||||
return &voucherDataResult, err
|
return &voucherDataResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TokenTransfer creates a new token transfer in the custodial system.
|
||||||
|
// Returns:
|
||||||
|
// - *models.TokenTransferResponse: A pointer to an TokenTransferResponse struct containing the trackingId.
|
||||||
|
// If there is an error during the request or processing, this will be nil.
|
||||||
|
// - error: An error if any occurred during the HTTP request, reading the response, or unmarshalling the JSON data.
|
||||||
|
// If no error occurs, this will be nil.
|
||||||
|
func (as *AccountService) TokenTransfer(ctx context.Context, amount, from, to, tokenAddress string) (*models.TokenTransferResponse, error) {
|
||||||
|
var r models.TokenTransferResponse
|
||||||
|
|
||||||
|
// Create request payload
|
||||||
|
payload := map[string]string{
|
||||||
|
"amount": amount,
|
||||||
|
"from": from,
|
||||||
|
"to": to,
|
||||||
|
"tokenAddress": tokenAddress,
|
||||||
|
}
|
||||||
|
|
||||||
|
payloadBytes, err := json.Marshal(payload)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new request
|
||||||
|
req, err := http.NewRequest("POST", config.TokenTransferURL, bytes.NewBuffer(payloadBytes))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = doCustodialRequest(ctx, req, &r)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &r, nil
|
||||||
|
}
|
||||||
|
|
||||||
func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
|
func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
|
||||||
var okResponse api.OKResponse
|
var okResponse api.OKResponse
|
||||||
var errResponse api.ErrResponse
|
var errResponse api.ErrResponse
|
||||||
|
Loading…
Reference in New Issue
Block a user