Skip to content

Commit

Permalink
feat: Add CalcualteFee in GRPC (#601)
Browse files Browse the repository at this point in the history
* change bug to protoc for protoBuffer generating and test it

* Revert "chore: Blockchain typo (#598)"

* update buf to v1.25.0

* fix: update buf protoBuffer

* fix: proto generate

* define GetTransactionFee

* feat: Add CalcualteFee in GRPC

---------

Co-authored-by: b00f <mostafa.sedaghat@gmail.com>
  • Loading branch information
ZigBalthazar and b00f authored Jul 30, 2023
1 parent d30f0a2 commit 75b718e
Show file tree
Hide file tree
Showing 34 changed files with 2,226 additions and 209 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ BUILD_LDFLAGS= -ldflags "-X github.com/pactus-project/pactus/version.build=`git

ifneq (,$(filter $(OS),Windows_NT MINGW64))
EXE = .exe
RM = del /q
else
RM = rm -rf
endif


all: build test

########################################
Expand Down Expand Up @@ -47,9 +51,9 @@ docker:
########################################
### proto
proto:
cd www/grpc/ && rm -rf gen && buf generate proto
cd www/grpc/ && $(RM) gen && buf generate proto

# Generate static assets for Swagger-UI
# Generate static assets for Swagger-UI
cd www/grpc/ && statik -m -f -src swagger-ui/

########################################
Expand Down
3 changes: 2 additions & 1 deletion cmd/gtk/dialog_transaction_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/gotk3/gotk3/gtk"
"github.com/pactus-project/pactus/crypto"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/wallet"
)
Expand Down Expand Up @@ -54,7 +55,7 @@ func broadcastTransactionBond(wallet *wallet.Wallet, valAddrs []crypto.Address)

onAmountChanged := func() {
amtStr, _ := amountEntry.GetText()
updateFeeHint(amountHint, amtStr, wallet)
updateFeeHint(amountHint, amtStr, wallet, payload.PayloadTypeBond)
}

onSend := func() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"

"github.com/gotk3/gotk3/gtk"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/wallet"
)
Expand Down Expand Up @@ -46,7 +47,7 @@ func broadcastTransactionSend(wallet *wallet.Wallet) {

onAmountChanged := func() {
amtStr, _ := amountEntry.GetText()
updateFeeHint(amountHint, amtStr, wallet)
updateFeeHint(amountHint, amtStr, wallet, payload.PayloadTypeTransfer)
}

onSend := func() {
Expand Down
9 changes: 7 additions & 2 deletions cmd/gtk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/gotk3/gotk3/glib"
"github.com/gotk3/gotk3/gtk"
"github.com/pactus-project/pactus/types/tx"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/wallet"
)
Expand Down Expand Up @@ -176,12 +177,16 @@ func updateAccountHint(lbl *gtk.Label, addr string, w *wallet.Wallet) {
}
}

func updateFeeHint(lbl *gtk.Label, amtStr string, w *wallet.Wallet) {
func updateFeeHint(lbl *gtk.Label, amtStr string, w *wallet.Wallet, payloadType payload.Type) {
amount, err := util.StringToChange(amtStr)
if err != nil {
updateHintLabel(lbl, "")
} else {
fee := w.CalculateFee(amount)
fee, err := w.CalculateFee(amount, payloadType)
if err != nil {
errorCheck(err)
return
}
hint := fmt.Sprintf("payable: %v, fee: %v",
util.ChangeToString(fee+amount), util.ChangeToString(fee))
updateHintLabel(lbl, hint)
Expand Down
6 changes: 3 additions & 3 deletions execution/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package execution
import (
"github.com/pactus-project/pactus/execution/executor"
"github.com/pactus-project/pactus/sandbox"
"github.com/pactus-project/pactus/types/param"
"github.com/pactus-project/pactus/types/tx"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/util"
Expand Down Expand Up @@ -122,16 +123,15 @@ func (exe *Execution) checkFee(trx *tx.Tx, sb sandbox.Sandbox) error {
return errors.Errorf(errors.ErrInvalidTx, "fee is wrong, expected: 0, got: %v", trx.Fee())
}
} else {
fee := calculateFee(trx.Payload().Value(), sb)
fee := CalculateFee(trx.Payload().Value(), sb.Params())
if trx.Fee() != fee {
return errors.Errorf(errors.ErrInvalidFee, "fee is wrong, expected: %v, got: %v", fee, trx.Fee())
}
}
return nil
}

func calculateFee(amt int64, sb sandbox.Sandbox) int64 {
params := sb.Params()
func CalculateFee(amt int64, params param.Params) int64 {
fee := int64(float64(amt) * params.FeeFraction)
fee = util.Max(fee, params.MinimumFee)
fee = util.Min(fee, params.MaximumFee)
Expand Down
2 changes: 1 addition & 1 deletion execution/execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func TestFee(t *testing.T) {
assert.Equal(t, errors.Code(err), test.expectedErrCode,
"test %v failed. unexpected error", i)

assert.Equal(t, calculateFee(test.amount, sb), test.expectedFee,
assert.Equal(t, CalculateFee(test.amount, sb.Params()), test.expectedFee,
"test %v failed. invalid fee", i)
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/google/uuid v1.3.0
github.com/gorilla/handlers v1.5.1
github.com/gorilla/mux v1.8.0
github.com/gotk3/gotk3 v0.6.1
github.com/gotk3/gotk3 v0.6.2
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0
github.com/hashicorp/golang-lru v0.6.0
github.com/jawher/mow.cli v1.2.0
Expand All @@ -19,7 +19,6 @@ require (
github.com/multiformats/go-multiaddr v0.9.0
github.com/pelletier/go-toml v1.9.5
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.14.0
github.com/rakyll/statik v0.1.7
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.2
Expand Down Expand Up @@ -110,6 +109,7 @@ require (
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
Expand Down
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down Expand Up @@ -176,6 +177,8 @@ github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWm
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gotk3/gotk3 v0.6.1 h1:GJ400a0ecEEWrzjBvzBzH+pB/esEMIGdB9zPSmBdoeo=
github.com/gotk3/gotk3 v0.6.1/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
github.com/gotk3/gotk3 v0.6.2 h1:sx/PjaKfKULJPTPq8p2kn2ZbcNFxpOJqi4VLzMbEOO8=
github.com/gotk3/gotk3 v0.6.2/go.mod h1:/hqFpkNa9T3JgNAE2fLvCdov7c5bw//FHNZrZ3Uv9/Q=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.0 h1:1JYBfzqrWPcCclBwxFCPAou9n+q86mfnu7NAeHfte7A=
Expand Down Expand Up @@ -221,12 +224,15 @@ github.com/jbenet/go-temp-err-catcher v0.1.0/go.mod h1:0kJRvmDZXNMIiJirNPEYfhpPw
github.com/jbenet/goprocess v0.1.4 h1:DRGOFReOMqqDNXwW70QkacFW0YN9QnwLV0Vqk+3oU0o=
github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZlqdZVfqY4=
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kilic/bls12-381 v0.1.0 h1:encrdjqKMEvabVQ7qYOKu1OvhqpK4s47wDYtNiPtlp4=
github.com/kilic/bls12-381 v0.1.0/go.mod h1:vDTTHJONJ6G+P2R74EhnyotQDTliQDnFEwhdmfzw1ig=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
Expand Down Expand Up @@ -318,6 +324,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mr-tron/base58 v1.1.2/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/mr-tron/base58 v1.1.3/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
Expand Down Expand Up @@ -348,6 +355,7 @@ github.com/multiformats/go-varint v0.0.1/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXS
github.com/multiformats/go-varint v0.0.5/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8=
github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo=
github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down Expand Up @@ -703,6 +711,7 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewNode(genDoc *genesis.Genesis, conf *config.Config,
// Initialize the logger
logger.InitLogger(conf.Logger)

logger.Info("You are running a pactus Blockchain",
logger.Info("You are running a Pactus blockchain",
"version", version.Version(),
"network", genDoc.ChainType())

Expand Down
2 changes: 2 additions & 0 deletions state/facade.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/pactus-project/pactus/types/block"
"github.com/pactus-project/pactus/types/param"
"github.com/pactus-project/pactus/types/tx"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/types/validator"
)

Expand Down Expand Up @@ -49,4 +50,5 @@ type Facade interface {
Params() param.Params
Close() error
Fingerprint() string
CalculateFee(amount int64, payloadType payload.Type) (int64, error)
}
21 changes: 21 additions & 0 deletions state/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/pactus-project/pactus/types/block"
"github.com/pactus-project/pactus/types/param"
"github.com/pactus-project/pactus/types/tx"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/types/validator"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/util/errors"
Expand Down Expand Up @@ -209,3 +210,23 @@ func (m *MockState) AddPendingTxAndBroadcast(trx *tx.Tx) error {
func (m *MockState) Params() param.Params {
return m.TestParams
}

func (m *MockState) CalculateFee(_ int64, payloadType payload.Type) (int64, error) {
switch payloadType {
case payload.PayloadTypeTransfer,
payload.PayloadTypeBond,
payload.PayloadTypeWithdraw:
{
return m.ts.RandInt64(1e9), nil
}

case payload.PayloadTypeUnbond,
payload.PayloadTypeSortition:
{
return 0, nil
}

default:
return 0, errors.Errorf(errors.ErrInvalidTx, "unexpected tx type: %v", payloadType)
}
}
21 changes: 21 additions & 0 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/pactus-project/pactus/types/block"
"github.com/pactus-project/pactus/types/param"
"github.com/pactus-project/pactus/types/tx"
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/types/validator"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/util/errors"
Expand Down Expand Up @@ -702,3 +703,23 @@ func (st *state) publishEvents(height uint32, block *block.Block) {
st.eventCh <- TxEvent
}
}

func (st *state) CalculateFee(amount int64, payloadType payload.Type) (int64, error) {
switch payloadType {
case payload.PayloadTypeTransfer,
payload.PayloadTypeBond,
payload.PayloadTypeWithdraw:
{
return execution.CalculateFee(amount, st.params), nil
}

case payload.PayloadTypeUnbond,
payload.PayloadTypeSortition:
{
return 0, nil
}

default:
return 0, errors.Errorf(errors.ErrInvalidTx, "unexpected tx type: %v", payloadType)
}
}
35 changes: 35 additions & 0 deletions state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/pactus-project/pactus/types/tx/payload"
"github.com/pactus-project/pactus/types/validator"
"github.com/pactus-project/pactus/util"
"github.com/pactus-project/pactus/util/errors"
"github.com/pactus-project/pactus/util/testsuite"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -728,3 +729,37 @@ func TestCommittingInvalidBlock(t *testing.T) {
// It is possible that the same block would be considered valid by td.state2.
assert.Error(t, td.state1.CommitBlock(2, b, c))
}

func TestCalcFee(t *testing.T) {
td := setup(t)
tests := []struct {
amount int64
pldType payload.Type
fee int64
expectedFee int64
expectedErrCode int
}{
{1, payload.PayloadTypeTransfer, 1, td.state1.params.MinimumFee, errors.ErrInvalidFee},
{1, payload.PayloadTypeWithdraw, 1001, td.state1.params.MinimumFee, errors.ErrInvalidFee},
{1, payload.PayloadTypeBond, 1000, td.state1.params.MinimumFee, errors.ErrNone},

{1 * 1e9, payload.PayloadTypeTransfer, 1, 100000, errors.ErrInvalidFee},
{1 * 1e9, payload.PayloadTypeWithdraw, 100001, 100000, errors.ErrInvalidFee},
{1 * 1e9, payload.PayloadTypeBond, 100000, 100000, errors.ErrNone},

{1 * 1e12, payload.PayloadTypeTransfer, 1, 1000000, errors.ErrInvalidFee},
{1 * 1e12, payload.PayloadTypeWithdraw, 1000001, 1000000, errors.ErrInvalidFee},
{1 * 1e12, payload.PayloadTypeBond, 1000000, 1000000, errors.ErrNone},

{1 * 1e12, payload.PayloadTypeSortition, 0, 0, errors.ErrInvalidFee},
{1 * 1e12, payload.PayloadTypeUnbond, 0, 0, errors.ErrNone},
}
for _, test := range tests {
fee, err := td.state2.CalculateFee(test.amount, test.pldType)
assert.NoError(t, err)
assert.Equal(t, test.expectedFee, fee)

_, err = td.state2.CalculateFee(test.amount, 6)
assert.Error(t, err)
}
}
11 changes: 11 additions & 0 deletions wallet/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/pactus-project/pactus/crypto"
"github.com/pactus-project/pactus/crypto/hash"
"github.com/pactus-project/pactus/types/tx"
"github.com/pactus-project/pactus/types/tx/payload"
pactus "github.com/pactus-project/pactus/www/grpc/gen/go"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand Down Expand Up @@ -73,6 +74,7 @@ func (c *grpcClient) sendTx(tx *tx.Tx) (tx.ID, error) {
return hash.FromBytes(res.Id)
}

// TODO: check the return value type
func (c *grpcClient) getTransaction(id tx.ID) (*pactus.GetTransactionResponse, error) {
res, err := c.transactionClient.GetTransaction(context.Background(), &pactus.GetTransactionRequest{
Id: id.Bytes(),
Expand All @@ -84,3 +86,12 @@ func (c *grpcClient) getTransaction(id tx.ID) (*pactus.GetTransactionResponse, e

return res, nil
}

func (c *grpcClient) getFee(amount int64, payloadType payload.Type) (int64, error) {
res, err := c.transactionClient.CalculateFee(context.Background(), &pactus.CalculateFeeRequest{
Amount: amount, PayloadType: pactus.PayloadType(payloadType)})
if err != nil {
return 0, err
}
return res.Fee, nil
}
5 changes: 5 additions & 0 deletions wallet/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ func (s *transactionServer) GetTransaction(_ context.Context,
return nil, nil
}

func (s *transactionServer) CalculateFee(_ context.Context,
_ *pactus.CalculateFeeRequest) (*pactus.CalculateFeeResponse, error) {
return &pactus.CalculateFeeResponse{Fee: 0}, nil
}

func (s *transactionServer) SendRawTransaction(_ context.Context,
req *pactus.SendRawTransactionRequest) (*pactus.SendRawTransactionResponse, error) {
trx, _ := tx.FromBytes(req.Data)
Expand Down
Loading

0 comments on commit 75b718e

Please sign in to comment.