From 488c35ff83584e1f8adc3bd602bb50bc3ccb0019 Mon Sep 17 00:00:00 2001 From: Zakhar Petukhov Date: Mon, 11 Sep 2023 15:13:41 +0700 Subject: [PATCH] change string to tlb type of account status --- pkg/api/account_converters.go | 4 ++-- pkg/api/account_handlers.go | 3 +++ pkg/core/account.go | 3 ++- pkg/core/converters.go | 8 ++++---- pkg/core/converters_test.go | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/api/account_converters.go b/pkg/api/account_converters.go index e6c6ce1c..5d9889d4 100644 --- a/pkg/api/account_converters.go +++ b/pkg/api/account_converters.go @@ -13,7 +13,7 @@ func convertToRawAccount(account *core.Account) oas.BlockchainRawAccount { Address: account.AccountAddress.ToRaw(), Balance: account.TonBalance, LastTransactionLt: int64(account.LastTransactionLt), - Status: account.Status, + Status: string(account.Status), Storage: oas.AccountStorageInfo{ UsedCells: account.Storage.UsedCells.Int64(), UsedBits: account.Storage.UsedBits.Int64(), @@ -43,7 +43,7 @@ func convertToAccount(account *core.Account, ab *addressbook.KnownAddress, state Address: account.AccountAddress.ToRaw(), Balance: account.TonBalance, LastActivity: account.LastActivityTime, - Status: account.Status, + Status: string(account.Status), Interfaces: account.Interfaces, GetMethods: account.GetMethods, } diff --git a/pkg/api/account_handlers.go b/pkg/api/account_handlers.go index afb303be..1fe886b9 100644 --- a/pkg/api/account_handlers.go +++ b/pkg/api/account_handlers.go @@ -145,6 +145,9 @@ func (h Handler) ExecGetMethodForBlockchainAccount(ctx context.Context, params o } exitCode, stack, err := h.executor.RunSmcMethodByID(ctx, accountID, utils.MethodIdFromName(params.MethodName), stack) if err != nil { + if errors.Is(err, core.ErrEntityNotFound) { + return nil, toError(http.StatusBadRequest, err) + } return nil, toError(http.StatusInternalServerError, err) } result := oas.MethodExecutionResult{ diff --git a/pkg/core/account.go b/pkg/core/account.go index 0b73791c..a5ba2c7c 100644 --- a/pkg/core/account.go +++ b/pkg/core/account.go @@ -6,12 +6,13 @@ import ( "github.com/shopspring/decimal" "github.com/tonkeeper/tongo" "github.com/tonkeeper/tongo/boc" + "github.com/tonkeeper/tongo/tlb" ) // Account holds low-level details about a particular account taken directly from the blockchain. type Account struct { AccountAddress tongo.AccountID - Status string + Status tlb.AccountStatus TonBalance int64 ExtraBalances map[uint32]decimal.Decimal LastTransactionLt uint64 diff --git a/pkg/core/converters.go b/pkg/core/converters.go index 93061a98..66253efd 100644 --- a/pkg/core/converters.go +++ b/pkg/core/converters.go @@ -364,7 +364,7 @@ func ConvertToAccount(accountId tongo.AccountID, acc tlb.Account) (*Account, err Code: []byte{}, } if acc.SumType == "AccountNone" { - res.Status = string(tlb.AccountNone) + res.Status = tlb.AccountNone return res, nil } balance := acc.Account.Storage.Balance @@ -380,15 +380,15 @@ func ConvertToAccount(accountId tongo.AccountID, acc tlb.Account) (*Account, err } res.LastTransactionLt = acc.Account.Storage.LastTransLt if acc.Account.Storage.State.SumType == "AccountUninit" { - res.Status = string(tlb.AccountUninit) + res.Status = tlb.AccountUninit return res, nil } if acc.Account.Storage.State.SumType == "AccountFrozen" { res.FrozenHash = g.Pointer(tongo.Bits256(acc.Account.Storage.State.AccountFrozen.StateHash)) - res.Status = string(tlb.AccountFrozen) + res.Status = tlb.AccountFrozen return res, nil } - res.Status = string(tlb.AccountActive) + res.Status = tlb.AccountActive if acc.Account.Storage.State.AccountActive.StateInit.Data.Exists { data, err := acc.Account.Storage.State.AccountActive.StateInit.Data.Value.Value.ToBoc() if err != nil { diff --git a/pkg/core/converters_test.go b/pkg/core/converters_test.go index 5cf33411..288a0162 100644 --- a/pkg/core/converters_test.go +++ b/pkg/core/converters_test.go @@ -42,7 +42,7 @@ func TestConvertToAccount(t *testing.T) { accountID: tongo.MustParseAccountID("EQDendoireMDFMufOUzkqNpFIay83GnjV2tgGMbA64wA3siV"), want: &Account{ AccountAddress: tongo.MustParseAccountID("EQDendoireMDFMufOUzkqNpFIay83GnjV2tgGMbA64wA3siV"), - Status: "active", + Status: tlb.AccountActive, TonBalance: 989109352, ExtraBalances: nil, LastTransactionLt: 31236013000006,