Skip to content

Commit

Permalink
Merge pull request #217 from tonkeeper/pointer-receiver
Browse files Browse the repository at this point in the history
Change (h Handler) to (h *Handler)
  • Loading branch information
mr-tron authored Oct 10, 2023
2 parents bb263b2 + 694b8bb commit b608f4d
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 95 deletions.
28 changes: 14 additions & 14 deletions pkg/api/account_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
walletTongo "github.com/tonkeeper/tongo/wallet"
)

func (h Handler) GetBlockchainRawAccount(ctx context.Context, params oas.GetBlockchainRawAccountParams) (*oas.BlockchainRawAccount, error) {
func (h *Handler) GetBlockchainRawAccount(ctx context.Context, params oas.GetBlockchainRawAccountParams) (*oas.BlockchainRawAccount, error) {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand All @@ -40,7 +40,7 @@ func (h Handler) GetBlockchainRawAccount(ctx context.Context, params oas.GetBloc
return &res, nil
}

func (h Handler) GetAccount(ctx context.Context, params oas.GetAccountParams) (*oas.Account, error) {
func (h *Handler) GetAccount(ctx context.Context, params oas.GetAccountParams) (*oas.Account, error) {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand All @@ -65,7 +65,7 @@ func (h Handler) GetAccount(ctx context.Context, params oas.GetAccountParams) (*
return &res, nil
}

func (h Handler) GetAccounts(ctx context.Context, request oas.OptGetAccountsReq) (*oas.Accounts, error) {
func (h *Handler) GetAccounts(ctx context.Context, request oas.OptGetAccountsReq) (*oas.Accounts, error) {
if len(request.Value.AccountIds) == 0 {
return nil, toError(http.StatusBadRequest, fmt.Errorf("empty list of ids"))
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func (h Handler) GetAccounts(ctx context.Context, request oas.OptGetAccountsReq)
return &oas.Accounts{Accounts: results}, nil
}

func (h Handler) GetBlockchainAccountTransactions(ctx context.Context, params oas.GetBlockchainAccountTransactionsParams) (*oas.Transactions, error) {
func (h *Handler) GetBlockchainAccountTransactions(ctx context.Context, params oas.GetBlockchainAccountTransactionsParams) (*oas.Transactions, error) {
accountID, err := tongo.ParseAddress(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand All @@ -133,7 +133,7 @@ func (h Handler) GetBlockchainAccountTransactions(ctx context.Context, params oa
return &result, nil
}

func (h Handler) ExecGetMethodForBlockchainAccount(ctx context.Context, params oas.ExecGetMethodForBlockchainAccountParams) (*oas.MethodExecutionResult, error) {
func (h *Handler) ExecGetMethodForBlockchainAccount(ctx context.Context, params oas.ExecGetMethodForBlockchainAccountParams) (*oas.MethodExecutionResult, error) {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand Down Expand Up @@ -179,7 +179,7 @@ func (h Handler) ExecGetMethodForBlockchainAccount(ctx context.Context, params o
return &result, nil
}

func (h Handler) SearchAccounts(ctx context.Context, params oas.SearchAccountsParams) (*oas.FoundAccounts, error) {
func (h *Handler) SearchAccounts(ctx context.Context, params oas.SearchAccountsParams) (*oas.FoundAccounts, error) {
accounts := h.addressBook.SearchAttachedAccountsByPrefix(params.Name)
var (
response oas.FoundAccounts
Expand Down Expand Up @@ -209,7 +209,7 @@ func (h Handler) SearchAccounts(ctx context.Context, params oas.SearchAccountsPa
}

// ReindexAccount updates internal cache for a particular account.
func (h Handler) ReindexAccount(ctx context.Context, params oas.ReindexAccountParams) error {
func (h *Handler) ReindexAccount(ctx context.Context, params oas.ReindexAccountParams) error {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return toError(http.StatusBadRequest, err)
Expand All @@ -220,7 +220,7 @@ func (h Handler) ReindexAccount(ctx context.Context, params oas.ReindexAccountPa
return nil
}

func (h Handler) GetAccountDnsExpiring(ctx context.Context, params oas.GetAccountDnsExpiringParams) (*oas.DnsExpiring, error) {
func (h *Handler) GetAccountDnsExpiring(ctx context.Context, params oas.GetAccountDnsExpiringParams) (*oas.DnsExpiring, error) {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand Down Expand Up @@ -269,7 +269,7 @@ func (h Handler) GetAccountDnsExpiring(ctx context.Context, params oas.GetAccoun
return &response, nil
}

func (h Handler) GetAccountPublicKey(ctx context.Context, params oas.GetAccountPublicKeyParams) (*oas.GetAccountPublicKeyOK, error) {
func (h *Handler) GetAccountPublicKey(ctx context.Context, params oas.GetAccountPublicKeyParams) (*oas.GetAccountPublicKeyOK, error) {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand All @@ -288,7 +288,7 @@ func (h Handler) GetAccountPublicKey(ctx context.Context, params oas.GetAccountP
return &oas.GetAccountPublicKeyOK{PublicKey: hex.EncodeToString(pubKey)}, nil
}

func (h Handler) GetAccountSubscriptions(ctx context.Context, params oas.GetAccountSubscriptionsParams) (*oas.Subscriptions, error) {
func (h *Handler) GetAccountSubscriptions(ctx context.Context, params oas.GetAccountSubscriptionsParams) (*oas.Subscriptions, error) {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand Down Expand Up @@ -316,7 +316,7 @@ func (h Handler) GetAccountSubscriptions(ctx context.Context, params oas.GetAcco
return &response, nil
}

func (h Handler) GetAccountTraces(ctx context.Context, params oas.GetAccountTracesParams) (*oas.TraceIDs, error) {
func (h *Handler) GetAccountTraces(ctx context.Context, params oas.GetAccountTracesParams) (*oas.TraceIDs, error) {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand All @@ -339,7 +339,7 @@ func (h Handler) GetAccountTraces(ctx context.Context, params oas.GetAccountTrac
return &traces, nil
}

func (h Handler) GetAccountDiff(ctx context.Context, params oas.GetAccountDiffParams) (*oas.GetAccountDiffOK, error) {
func (h *Handler) GetAccountDiff(ctx context.Context, params oas.GetAccountDiffParams) (*oas.GetAccountDiffOK, error) {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand All @@ -351,7 +351,7 @@ func (h Handler) GetAccountDiff(ctx context.Context, params oas.GetAccountDiffPa
return &oas.GetAccountDiffOK{BalanceChange: balanceChange}, nil
}

func (h Handler) GetAccountNftHistory(ctx context.Context, params oas.GetAccountNftHistoryParams) (*oas.AccountEvents, error) {
func (h *Handler) GetAccountNftHistory(ctx context.Context, params oas.GetAccountNftHistoryParams) (*oas.AccountEvents, error) {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand All @@ -367,7 +367,7 @@ func (h Handler) GetAccountNftHistory(ctx context.Context, params oas.GetAccount
return &oas.AccountEvents{Events: events, NextFrom: lastLT}, nil
}

func (h Handler) BlockchainAccountInspect(ctx context.Context, params oas.BlockchainAccountInspectParams) (*oas.BlockchainAccountInspect, error) {
func (h *Handler) BlockchainAccountInspect(ctx context.Context, params oas.BlockchainAccountInspectParams) (*oas.BlockchainAccountInspect, error) {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/api/account_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package api
import (
"context"
"fmt"
"github.com/tonkeeper/opentonapi/pkg/chainstate"
"testing"

"github.com/tonkeeper/opentonapi/pkg/chainstate"

"github.com/stretchr/testify/require"
"go.uber.org/zap"

Expand Down Expand Up @@ -126,7 +127,7 @@ func TestHandler_GetAccounts(t *testing.T) {

liteStorage, err := litestorage.NewLiteStorage(logger)
require.Nil(t, err)
h := Handler{
h := &Handler{
addressBook: addressbook.NewAddressBook(logger, config.AddressPath, config.JettonPath, config.CollectionPath),
storage: liteStorage,
state: chainstate.NewChainState(liteStorage),
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/auction_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/tonkeeper/opentonapi/pkg/oas"
)

func (h Handler) GetAllAuctions(ctx context.Context, params oas.GetAllAuctionsParams) (*oas.Auctions, error) {
func (h *Handler) GetAllAuctions(ctx context.Context, params oas.GetAllAuctionsParams) (*oas.Auctions, error) {
auctions, err := h.storage.GetAllAuctions(ctx)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand All @@ -34,7 +34,7 @@ func (h Handler) GetAllAuctions(ctx context.Context, params oas.GetAllAuctionsPa
return &auctionsRes, nil
}

func (h Handler) GetDomainBids(ctx context.Context, params oas.GetDomainBidsParams) (*oas.DomainBids, error) {
func (h *Handler) GetDomainBids(ctx context.Context, params oas.GetDomainBidsParams) (*oas.DomainBids, error) {
domain := strings.ToLower(params.DomainName)
bids, err := h.storage.GetDomainBids(ctx, strings.TrimSuffix(domain, ".ton"))
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/api/blockchain_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/tonkeeper/tongo/tlb"
)

func (h Handler) GetBlockchainBlock(ctx context.Context, params oas.GetBlockchainBlockParams) (*oas.BlockchainBlock, error) {
func (h *Handler) GetBlockchainBlock(ctx context.Context, params oas.GetBlockchainBlockParams) (*oas.BlockchainBlock, error) {
id, err := blockIdFromString(params.BlockID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand All @@ -30,7 +30,7 @@ func (h Handler) GetBlockchainBlock(ctx context.Context, params oas.GetBlockchai
return &res, nil
}

func (h Handler) GetBlockchainBlockTransactions(ctx context.Context, params oas.GetBlockchainBlockTransactionsParams) (*oas.Transactions, error) {
func (h *Handler) GetBlockchainBlockTransactions(ctx context.Context, params oas.GetBlockchainBlockTransactionsParams) (*oas.Transactions, error) {
id, err := blockIdFromString(params.BlockID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand All @@ -48,7 +48,7 @@ func (h Handler) GetBlockchainBlockTransactions(ctx context.Context, params oas.
return &res, nil
}

func (h Handler) GetBlockchainTransaction(ctx context.Context, params oas.GetBlockchainTransactionParams) (*oas.Transaction, error) {
func (h *Handler) GetBlockchainTransaction(ctx context.Context, params oas.GetBlockchainTransactionParams) (*oas.Transaction, error) {
hash, err := tongo.ParseHash(params.TransactionID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand All @@ -74,7 +74,7 @@ func (h Handler) GetBlockchainTransaction(ctx context.Context, params oas.GetBlo
return &transaction, nil
}

func (h Handler) GetBlockchainTransactionByMessageHash(ctx context.Context, params oas.GetBlockchainTransactionByMessageHashParams) (*oas.Transaction, error) {
func (h *Handler) GetBlockchainTransactionByMessageHash(ctx context.Context, params oas.GetBlockchainTransactionByMessageHashParams) (*oas.Transaction, error) {
hash, err := tongo.ParseHash(params.MsgID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand All @@ -93,15 +93,15 @@ func (h Handler) GetBlockchainTransactionByMessageHash(ctx context.Context, para
return &transaction, nil
}

func (h Handler) GetBlockchainMasterchainHead(ctx context.Context) (*oas.BlockchainBlock, error) {
func (h *Handler) GetBlockchainMasterchainHead(ctx context.Context) (*oas.BlockchainBlock, error) {
header, err := h.storage.LastMasterchainBlockHeader(ctx)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
}
return g.Pointer(convertBlockHeader(*header)), nil
}

func (h Handler) GetBlockchainConfig(ctx context.Context) (*oas.BlockchainConfig, error) {
func (h *Handler) GetBlockchainConfig(ctx context.Context) (*oas.BlockchainConfig, error) {
cfg, err := h.storage.GetLastConfig(ctx)
if err != nil {
return nil, toError(http.StatusInternalServerError, err)
Expand Down
9 changes: 5 additions & 4 deletions pkg/api/dns_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ import (
"context"
"errors"
"fmt"
"github.com/tonkeeper/tongo/contract/dns"
"net/http"
"strings"

"github.com/tonkeeper/tongo/contract/dns"

"github.com/tonkeeper/opentonapi/pkg/oas"
"github.com/tonkeeper/opentonapi/pkg/references"
"github.com/tonkeeper/tongo"
"github.com/tonkeeper/tongo/tlb"
)

func (h Handler) AccountDnsBackResolve(ctx context.Context, params oas.AccountDnsBackResolveParams) (*oas.DomainNames, error) {
func (h *Handler) AccountDnsBackResolve(ctx context.Context, params oas.AccountDnsBackResolveParams) (*oas.DomainNames, error) {
accountID, err := tongo.ParseAccountID(params.AccountID)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand Down Expand Up @@ -51,7 +52,7 @@ func (h Handler) AccountDnsBackResolve(ctx context.Context, params oas.AccountDn
return &oas.DomainNames{Domains: result}, nil
}

func (h Handler) DnsResolve(ctx context.Context, params oas.DnsResolveParams) (*oas.DnsRecord, error) {
func (h *Handler) DnsResolve(ctx context.Context, params oas.DnsResolveParams) (*oas.DnsRecord, error) {
if len(params.DomainName) == 48 || len(params.DomainName) == 52 {
return nil, toError(http.StatusBadRequest, fmt.Errorf("domains with length 48 and 52 can't be resolved by security issues"))
}
Expand Down Expand Up @@ -95,7 +96,7 @@ func (h Handler) DnsResolve(ctx context.Context, params oas.DnsResolveParams) (*
return &result, nil
}

func (h Handler) GetDnsInfo(ctx context.Context, params oas.GetDnsInfoParams) (*oas.DomainInfo, error) {
func (h *Handler) GetDnsInfo(ctx context.Context, params oas.GetDnsInfoParams) (*oas.DomainInfo, error) {
name, err := convertDomainName(params.DomainName)
if err != nil {
return nil, toError(http.StatusBadRequest, err)
Expand Down
22 changes: 11 additions & 11 deletions pkg/api/event_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func convertTrace(t core.Trace, book addressBook) oas.Trace {
return trace
}

func (h Handler) convertRisk(ctx context.Context, risk wallet.Risk, walletAddress tongo.AccountID) (oas.Risk, error) {
func (h *Handler) convertRisk(ctx context.Context, risk wallet.Risk, walletAddress tongo.AccountID) (oas.Risk, error) {
oasRisk := oas.Risk{
TransferAllRemainingBalance: risk.TransferAllRemainingBalance,
// TODO: verify there is no overflow
Expand Down Expand Up @@ -115,7 +115,7 @@ func signedValue(value string, viewer *tongo.AccountID, source, destination tong
return value
}

func (h Handler) convertActionTonTransfer(t *bath.TonTransferAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptTonTransferAction, oas.ActionSimplePreview, bool) {
func (h *Handler) convertActionTonTransfer(t *bath.TonTransferAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptTonTransferAction, oas.ActionSimplePreview, bool) {
var spamDetected bool
if t.Amount < int64(ton.OneTON) && t.Comment != nil {
if spamAction := rules.CheckAction(h.spamFilter.GetRules(), *t.Comment); spamAction == rules.Drop {
Expand Down Expand Up @@ -155,7 +155,7 @@ func (h Handler) convertActionTonTransfer(t *bath.TonTransferAction, acceptLangu
return action, simplePreview, spamDetected
}

func (h Handler) convertActionNftTransfer(t *bath.NftTransferAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptNftItemTransferAction, oas.ActionSimplePreview, bool) {
func (h *Handler) convertActionNftTransfer(t *bath.NftTransferAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptNftItemTransferAction, oas.ActionSimplePreview, bool) {
var spamDetected bool
if t.Comment != nil {
if spamAction := rules.CheckAction(h.spamFilter.GetRules(), *t.Comment); spamAction == rules.Drop {
Expand Down Expand Up @@ -184,7 +184,7 @@ func (h Handler) convertActionNftTransfer(t *bath.NftTransferAction, acceptLangu
return action, simplePreview, spamDetected
}

func (h Handler) convertActionJettonTransfer(ctx context.Context, t *bath.JettonTransferAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptJettonTransferAction, oas.ActionSimplePreview, bool) {
func (h *Handler) convertActionJettonTransfer(ctx context.Context, t *bath.JettonTransferAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptJettonTransferAction, oas.ActionSimplePreview, bool) {
var spamDetected bool
if t.Comment != nil {
if spamAction := rules.CheckAction(h.spamFilter.GetRules(), *t.Comment); spamAction == rules.Drop {
Expand Down Expand Up @@ -226,7 +226,7 @@ func (h Handler) convertActionJettonTransfer(ctx context.Context, t *bath.Jetton
return action, simplePreview, spamDetected
}

func (h Handler) convertActionJettonMint(ctx context.Context, m *bath.JettonMintAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptJettonMintAction, oas.ActionSimplePreview) {
func (h *Handler) convertActionJettonMint(ctx context.Context, m *bath.JettonMintAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptJettonMintAction, oas.ActionSimplePreview) {
meta := h.GetJettonNormalizedMetadata(ctx, m.Jetton)
preview := jettonPreview(m.Jetton, meta)
var action oas.OptJettonMintAction
Expand Down Expand Up @@ -259,7 +259,7 @@ func (h Handler) convertActionJettonMint(ctx context.Context, m *bath.JettonMint
return action, simplePreview
}

func (h Handler) convertDepositStake(d *bath.DepositStakeAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptDepositStakeAction, oas.ActionSimplePreview) {
func (h *Handler) convertDepositStake(d *bath.DepositStakeAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptDepositStakeAction, oas.ActionSimplePreview) {
var action oas.OptDepositStakeAction
action.SetTo(oas.DepositStakeAction{
Amount: d.Amount,
Expand All @@ -284,7 +284,7 @@ func (h Handler) convertDepositStake(d *bath.DepositStakeAction, acceptLanguage
return action, simplePreview
}

func (h Handler) convertWithdrawStakeRequest(d *bath.WithdrawStakeRequestAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptWithdrawStakeRequestAction, oas.ActionSimplePreview) {
func (h *Handler) convertWithdrawStakeRequest(d *bath.WithdrawStakeRequestAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptWithdrawStakeRequestAction, oas.ActionSimplePreview) {
var action oas.OptWithdrawStakeRequestAction
action.SetTo(oas.WithdrawStakeRequestAction{
Amount: g.Opt(d.Amount),
Expand Down Expand Up @@ -314,7 +314,7 @@ func (h Handler) convertWithdrawStakeRequest(d *bath.WithdrawStakeRequestAction,
return action, simplePreview
}

func (h Handler) convertWithdrawStake(d *bath.WithdrawStakeAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptWithdrawStakeAction, oas.ActionSimplePreview) {
func (h *Handler) convertWithdrawStake(d *bath.WithdrawStakeAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptWithdrawStakeAction, oas.ActionSimplePreview) {
var action oas.OptWithdrawStakeAction
action.SetTo(oas.WithdrawStakeAction{
Amount: d.Amount,
Expand All @@ -337,7 +337,7 @@ func (h Handler) convertWithdrawStake(d *bath.WithdrawStakeAction, acceptLanguag
return action, simplePreview
}

func (h Handler) convertAction(ctx context.Context, viewer *tongo.AccountID, a bath.Action, acceptLanguage oas.OptString) (oas.Action, bool, error) {
func (h *Handler) convertAction(ctx context.Context, viewer *tongo.AccountID, a bath.Action, acceptLanguage oas.OptString) (oas.Action, bool, error) {
action := oas.Action{
Type: oas.ActionType(a.Type),
}
Expand Down Expand Up @@ -675,7 +675,7 @@ func convertAccountValueFlow(accountID tongo.AccountID, flow *bath.AccountValueF
return valueFlow
}

func (h Handler) toEvent(ctx context.Context, trace *core.Trace, result *bath.ActionsList, lang oas.OptString) (oas.Event, error) {
func (h *Handler) toEvent(ctx context.Context, trace *core.Trace, result *bath.ActionsList, lang oas.OptString) (oas.Event, error) {
event := oas.Event{
EventID: trace.Hash.Hex(),
Timestamp: trace.Utime,
Expand Down Expand Up @@ -710,7 +710,7 @@ func (h Handler) toEvent(ctx context.Context, trace *core.Trace, result *bath.Ac
return event, nil
}

func (h Handler) toAccountEvent(ctx context.Context, account tongo.AccountID, trace *core.Trace, result *bath.ActionsList, lang oas.OptString, subjectOnly bool) (oas.AccountEvent, error) {
func (h *Handler) toAccountEvent(ctx context.Context, account tongo.AccountID, trace *core.Trace, result *bath.ActionsList, lang oas.OptString, subjectOnly bool) (oas.AccountEvent, error) {
e := oas.AccountEvent{
EventID: trace.Hash.Hex(),
Account: convertAccountAddress(account, h.addressBook),
Expand Down
Loading

0 comments on commit b608f4d

Please sign in to comment.