fixed trx source #177
@@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/tech/sendico/gateway/chain/internal/service/gateway/driver"
|
"github.com/tech/sendico/gateway/chain/internal/service/gateway/driver"
|
||||||
|
"github.com/tech/sendico/gateway/chain/internal/service/gateway/shared"
|
||||||
"github.com/tech/sendico/pkg/api/routers/gsresponse"
|
"github.com/tech/sendico/pkg/api/routers/gsresponse"
|
||||||
"github.com/tech/sendico/pkg/merrors"
|
"github.com/tech/sendico/pkg/merrors"
|
||||||
"github.com/tech/sendico/pkg/mservice"
|
"github.com/tech/sendico/pkg/mservice"
|
||||||
@@ -84,19 +85,28 @@ func (c *estimateTransferFeeCommand) Execute(ctx context.Context, req *chainv1.E
|
|||||||
return gsresponse.InvalidArgument[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, err)
|
return gsresponse.InvalidArgument[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
walletForFee := sourceWallet
|
||||||
|
nativeCurrency := shared.NativeCurrency(networkCfg)
|
||||||
|
if nativeCurrency != "" && strings.EqualFold(nativeCurrency, amount.GetCurrency()) {
|
||||||
|
copyWallet := *sourceWallet
|
||||||
|
copyWallet.ContractAddress = ""
|
||||||
|
copyWallet.TokenSymbol = nativeCurrency
|
||||||
|
walletForFee = ©Wallet
|
||||||
|
}
|
||||||
|
|
||||||
driverDeps := driver.Deps{
|
driverDeps := driver.Deps{
|
||||||
Logger: c.deps.Logger,
|
Logger: c.deps.Logger,
|
||||||
Registry: c.deps.Networks,
|
Registry: c.deps.Networks,
|
||||||
RPCTimeout: c.deps.RPCTimeout,
|
RPCTimeout: c.deps.RPCTimeout,
|
||||||
}
|
}
|
||||||
feeMoney, err := chainDriver.EstimateFee(ctx, driverDeps, networkCfg, sourceWallet, destinationAddress, amount)
|
feeMoney, err := chainDriver.EstimateFee(ctx, driverDeps, networkCfg, walletForFee, destinationAddress, amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.deps.Logger.Warn("fee estimation failed", zap.Error(err))
|
c.deps.Logger.Warn("fee estimation failed", zap.Error(err))
|
||||||
return gsresponse.Auto[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, err)
|
return gsresponse.Auto[chainv1.EstimateTransferFeeResponse](c.deps.Logger, mservice.ChainGateway, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
contextLabel := "erc20_transfer"
|
contextLabel := "erc20_transfer"
|
||||||
if strings.TrimSpace(sourceWallet.ContractAddress) == "" {
|
if strings.TrimSpace(walletForFee.ContractAddress) == "" {
|
||||||
contextLabel = "native_transfer"
|
contextLabel = "native_transfer"
|
||||||
}
|
}
|
||||||
resp := &chainv1.EstimateTransferFeeResponse{
|
resp := &chainv1.EstimateTransferFeeResponse{
|
||||||
|
|||||||
@@ -113,6 +113,14 @@ func (c *submitTransferCommand) Execute(ctx context.Context, req *chainv1.Submit
|
|||||||
netAmount := shared.CloneMoney(amount)
|
netAmount := shared.CloneMoney(amount)
|
||||||
netAmount.Amount = netDec.String()
|
netAmount.Amount = netDec.String()
|
||||||
|
|
||||||
|
effectiveTokenSymbol := sourceWallet.TokenSymbol
|
||||||
|
effectiveContractAddress := sourceWallet.ContractAddress
|
||||||
|
nativeCurrency := shared.NativeCurrency(networkCfg)
|
||||||
|
if nativeCurrency != "" && strings.EqualFold(nativeCurrency, amountCurrency) {
|
||||||
|
effectiveTokenSymbol = nativeCurrency
|
||||||
|
effectiveContractAddress = ""
|
||||||
|
}
|
||||||
|
|
||||||
transfer := &model.Transfer{
|
transfer := &model.Transfer{
|
||||||
IdempotencyKey: idempotencyKey,
|
IdempotencyKey: idempotencyKey,
|
||||||
TransferRef: shared.GenerateTransferRef(),
|
TransferRef: shared.GenerateTransferRef(),
|
||||||
@@ -120,8 +128,8 @@ func (c *submitTransferCommand) Execute(ctx context.Context, req *chainv1.Submit
|
|||||||
SourceWalletRef: sourceWalletRef,
|
SourceWalletRef: sourceWalletRef,
|
||||||
Destination: destination,
|
Destination: destination,
|
||||||
Network: sourceWallet.Network,
|
Network: sourceWallet.Network,
|
||||||
TokenSymbol: sourceWallet.TokenSymbol,
|
TokenSymbol: effectiveTokenSymbol,
|
||||||
ContractAddress: sourceWallet.ContractAddress,
|
ContractAddress: effectiveContractAddress,
|
||||||
RequestedAmount: shared.CloneMoney(amount),
|
RequestedAmount: shared.CloneMoney(amount),
|
||||||
NetAmount: netAmount,
|
NetAmount: netAmount,
|
||||||
Fees: fees,
|
Fees: fees,
|
||||||
|
|||||||
@@ -119,6 +119,15 @@ func TransferStatusToProto(status model.TransferStatus) chainv1.TransferStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NativeCurrency returns the canonical native token symbol for a network.
|
||||||
|
func NativeCurrency(network Network) string {
|
||||||
|
currency := strings.ToUpper(strings.TrimSpace(network.NativeToken))
|
||||||
|
if currency == "" {
|
||||||
|
currency = strings.ToUpper(strings.TrimSpace(network.Name))
|
||||||
|
}
|
||||||
|
return currency
|
||||||
|
}
|
||||||
|
|
||||||
// Network describes a supported blockchain network and known token contracts.
|
// Network describes a supported blockchain network and known token contracts.
|
||||||
type Network struct {
|
type Network struct {
|
||||||
Name string
|
Name string
|
||||||
|
|||||||
Reference in New Issue
Block a user