Skip to content

Commit

Permalink
Merge pull request #188 from tonkeeper/fix_account_methods
Browse files Browse the repository at this point in the history
change string to tlb type of account status
  • Loading branch information
mr-tron authored Sep 11, 2023
2 parents e3c5cc8 + 488c35f commit e9f887c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/api/account_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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,
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/api/account_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
3 changes: 2 additions & 1 deletion pkg/core/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/core/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/converters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e9f887c

Please sign in to comment.