Expose methods required for the stream sync service #147
@ -30,7 +30,7 @@ const (
|
|||||||
DATA_PUBLIC_KEY_REVERSE
|
DATA_PUBLIC_KEY_REVERSE
|
||||||
DATA_ACTIVE_DECIMAL
|
DATA_ACTIVE_DECIMAL
|
||||||
DATA_ACTIVE_ADDRESS
|
DATA_ACTIVE_ADDRESS
|
||||||
|
DATA_TRANSACTIONS
|
||||||
)
|
)
|
||||||
|
|
||||||
func typToBytes(typ DataTyp) []byte {
|
func typToBytes(typ DataTyp) []byte {
|
||||||
|
@ -37,6 +37,15 @@ func ProcessVouchers(holdings []dataserviceapi.TokenHoldings) VoucherMetadata {
|
|||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//func StoreVouchers(db storage.PrefixDb, data VoucherMetadata) {
|
||||||
|
// value, err := db.Put(ctx, []byte(key))
|
||||||
|
// if err != nil {
|
||||||
|
// return nil, fmt.Errorf("failed to get %s: %v", key, err)
|
||||||
|
// }
|
||||||
|
// data[key] = string(value)
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
// GetVoucherData retrieves and matches voucher data
|
// GetVoucherData retrieves and matches voucher data
|
||||||
func GetVoucherData(ctx context.Context, db storage.PrefixDb, input string) (*dataserviceapi.TokenHoldings, error) {
|
func GetVoucherData(ctx context.Context, db storage.PrefixDb, input string) (*dataserviceapi.TokenHoldings, error) {
|
||||||
keys := []string{"sym", "bal", "deci", "addr"}
|
keys := []string{"sym", "bal", "deci", "addr"}
|
||||||
|
@ -22,6 +22,7 @@ type AccountServiceInterface interface {
|
|||||||
CreateAccount(ctx context.Context) (*models.AccountResult, error)
|
CreateAccount(ctx context.Context) (*models.AccountResult, error)
|
||||||
TrackAccountStatus(ctx context.Context, publicKey string) (*models.TrackStatusResult, error)
|
TrackAccountStatus(ctx context.Context, publicKey string) (*models.TrackStatusResult, error)
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AccountService struct {
|
type AccountService struct {
|
||||||
@ -100,13 +101,18 @@ func (as *AccountService) CreateAccount(ctx context.Context) (*models.AccountRes
|
|||||||
return &r, nil
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchVouchers retrieves the token holdings for a given public key from the custodial holdings API endpoint
|
// FetchVouchers retrieves the token holdings for a given public key from the data indexer API endpoint
|
||||||
// Parameters:
|
// Parameters:
|
||||||
// - publicKey: The public key associated with the account.
|
// - publicKey: The public key associated with the account.
|
||||||
func (as *AccountService) FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
|
func (as *AccountService) FetchVouchers(ctx context.Context, publicKey string) ([]dataserviceapi.TokenHoldings, error) {
|
||||||
var r []dataserviceapi.TokenHoldings
|
var r []dataserviceapi.TokenHoldings
|
||||||
|
|
||||||
req, err := http.NewRequest("GET", config.VoucherHoldingsURL, nil)
|
ep, err := url.JoinPath(config.VoucherHoldingsURL, publicKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest("GET", ep, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -119,6 +125,32 @@ func (as *AccountService) FetchVouchers(ctx context.Context, publicKey string) (
|
|||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// FetchTransactions retrieves the last 10 transactions for a given public key from the data indexer API endpoint
|
||||||
|
// Parameters:
|
||||||
|
// - publicKey: The public key associated with the account.
|
||||||
|
func (as *AccountService) FetchTransactions(ctx context.Context, publicKey string) ([]dataserviceapi.Last10TxResponse, error) {
|
||||||
|
var r []dataserviceapi.Last10TxResponse
|
||||||
|
|
||||||
|
ep, err := url.JoinPath(config.VoucherTransfersURL, publicKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest("GET", ep, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = doDataRequest(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