define importable token list

This commit is contained in:
Carlosokumu 2024-10-08 13:41:09 +03:00
parent 221db4e998
commit 7b374ad801
Signed by untrusted user: carlos
GPG Key ID: 7BD6BC8160A5C953
3 changed files with 100 additions and 34 deletions

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"io" "io"
"net/http" "net/http"
"os"
"git.grassecon.net/urdt/ussd/config" "git.grassecon.net/urdt/ussd/config"
"git.grassecon.net/urdt/ussd/internal/models" "git.grassecon.net/urdt/ussd/internal/models"
@ -18,8 +19,6 @@ type AccountServiceInterface interface {
type AccountService struct { type AccountService struct {
} }
// CheckAccountStatus retrieves the status of an account transaction based on the provided tracking ID. // CheckAccountStatus retrieves the status of an account transaction based on the provided tracking ID.
// //
// Parameters: // Parameters:
@ -27,12 +26,10 @@ type AccountService struct {
// CreateAccount or a similar function that returns an AccountResponse. The `trackingId` field in the // CreateAccount or a similar function that returns an AccountResponse. The `trackingId` field in the
// AccountResponse struct can be used here to check the account status during a transaction. // AccountResponse struct can be used here to check the account status during a transaction.
// //
//
// Returns: // Returns:
// - string: The status of the transaction as a string. If there is an error during the request or processing, this will be an empty string. // - string: The status of the transaction as a string. If there is an error during the request or processing, this will be an empty string.
// - error: An error if any occurred during the HTTP request, reading the response, or unmarshalling the JSON data. // - 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. // If no error occurs, this will be nil.
//
func (as *AccountService) CheckAccountStatus(trackingId string) (string, error) { func (as *AccountService) CheckAccountStatus(trackingId string) (string, error) {
resp, err := http.Get(config.TrackStatusURL + trackingId) resp, err := http.Get(config.TrackStatusURL + trackingId)
if err != nil { if err != nil {
@ -56,7 +53,6 @@ func (as *AccountService) CheckAccountStatus(trackingId string) (string, error)
return status, nil return status, nil
} }
// CheckBalance retrieves the balance for a given public key from the custodial balance API endpoint. // CheckBalance retrieves the balance for a given public key from the custodial balance API endpoint.
// Parameters: // Parameters:
// - publicKey: The public key associated with the account whose balance needs to be checked. // - publicKey: The public key associated with the account whose balance needs to be checked.
@ -83,8 +79,7 @@ func (as *AccountService) CheckBalance(publicKey string) (string, error) {
return balance, nil return balance, nil
} }
// CreateAccount creates a new account in the custodial system.
//CreateAccount creates a new account in the custodial system.
// Returns: // Returns:
// - *models.AccountResponse: A pointer to an AccountResponse struct containing the details of the created account. // - *models.AccountResponse: A pointer to an AccountResponse struct containing the details of the created account.
// If there is an error during the request or processing, this will be nil. // If there is an error during the request or processing, this will be nil.
@ -110,3 +105,16 @@ func (as *AccountService) CreateAccount() (*models.AccountResponse, error) {
return &accountResp, nil return &accountResp, nil
} }
func GetTokenList() (*models.ApiResponse, error) {
file, err := os.Open("sample_tokens.json")
if err != nil {
return nil, err
}
defer file.Close()
var apiResponse models.ApiResponse
if err := json.NewDecoder(file).Decode(&apiResponse); err != nil {
return nil, err
}
return &apiResponse, nil
}

View File

@ -256,36 +256,50 @@ func (h *Handlers) SaveTemporaryPin(ctx context.Context, sym string, input []byt
func (h *Handlers) GetVoucherList(ctx context.Context,sym string,input []byte) (resource.Result,error){ func (h *Handlers) GetVoucherList(ctx context.Context,sym string,input []byte) (resource.Result,error){
var res resource.Result res := resource.Result{}
vouchers := []string{ //as := h.accountService.(*server.AccountService)
"SRF", tokenList,err := server.GetTokenList()
"CRF", fmt.Println("Error here:",err)
"VCF", if err != nil {
"VSAPA", return res,err
"FSTMP",
"FSAW",
"PTAQ",
"VCRXT",
"VSGAQ",
"QPWIQQ",
"FSTMP",
"FSAW",
"PTAQ",
"VCRXT",
"VSGAQ",
"QPWIQQ",
"FSTMP",
"FSAW",
"PTAQ",
"VCRXT",
"VSGAQ",
"QPWIQQ",
} }
var numberedVouchers []string holdings := tokenList.Result.Holdings
for i, voucher := range vouchers { fmt.Println("TokenList:",tokenList.Result.Holdings)
numberedVouchers = append(numberedVouchers, fmt.Sprintf("%d:%s", i+1, voucher))
// vouchers := []string{
// "SRF",
// "CRF",
// "VCF",
// "VSAPA",
// "FSTMP",
// "FSAW",
// "PTAQ",
// "VCRXT",
// "VSGAQ",
// "QPWIQQ",
// "FSTMP",
// "FSAW",
// "PTAQ",
// "VCRXT",
// "VSGAQ",
// "QPWIQQ",
// "FSTMP",
// "FSAW",
// "PTAQ",
// "VCRXT",
// "VSGAQ",
// "QPWIQQ",
// }
var numberedVouchers []string
for i,token := range holdings {
numberedVouchers = append(numberedVouchers, fmt.Sprintf("%d:%s", i+1, token.TokenSymbol))
} }
// var numberedVouchers []string
// for i, voucher := range vouchers {
// numberedVouchers = append(numberedVouchers, fmt.Sprintf("%d:%s", i+1, voucher))
// }
res.Content = strings.Join(numberedVouchers,"\n") res.Content = strings.Join(numberedVouchers,"\n")
return res,nil return res,nil

44
sample_tokens.json Normal file
View File

@ -0,0 +1,44 @@
{
"ok": true,
"description": "Token holdings with current balances",
"result": {
"holdings": [
{
"contractAddress": "0x6CC75A06ac72eB4Db2eE22F781F5D100d8ec03ee",
"tokenSymbol": "FSPTST",
"tokenDecimals": "6",
"balance": "8869964242"
},
{
"contractAddress": "0x724F2910D790B54A39a7638282a45B1D83564fFA",
"tokenSymbol": "GEO",
"tokenDecimals": "6",
"balance": "9884"
},
{
"contractAddress": "0x2105a206B7bec31E2F90acF7385cc8F7F5f9D273",
"tokenSymbol": "MFNK",
"tokenDecimals": "6",
"balance": "19788697"
},
{
"contractAddress": "0x63DE2Ac8D1008351Cc69Fb8aCb94Ba47728a7E83",
"tokenSymbol": "MILO",
"tokenDecimals": "6",
"balance": "75"
},
{
"contractAddress": "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9",
"tokenSymbol": "SOHAIL",
"tokenDecimals": "6",
"balance": "27874115"
},
{
"contractAddress": "0x45d747172e77d55575c197CbA9451bC2CD8F4958",
"tokenSymbol": "SRF",
"tokenDecimals": "6",
"balance": "2745987"
}
]
}
}