forked from ranjbar-dev/tron-wallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fee.go
44 lines (31 loc) · 1 KB
/
fee.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package tronWallet
import (
"crypto/ecdsa"
"github.com/ranjbar-dev/tron-wallet/enums"
"github.com/ranjbar-dev/tron-wallet/grpcClient"
)
func estimateTrc10TransactionFee(node enums.Node, privateKey *ecdsa.PrivateKey, fromAddressBase58 string, toAddressBase58 string, amountInSun int64) (int64, error) {
tx, err := createTransactionInput(node, fromAddressBase58, toAddressBase58, amountInSun)
if err != nil {
return 0, err
}
singedTx, err := signTransaction(tx, privateKey)
if err != nil {
return 0, err
}
temp := (len(singedTx.Transaction.Signature[0]) + len(singedTx.Transaction.RawData.String())) / 2
bandwidthNeed := int64(temp + 68)
c, _ := grpcClient.GetGrpcClient(enums.SHASTA_NODE)
res, err := c.GetAccountResource(fromAddressBase58)
if err != nil {
return 0, err
}
avaialable := res.FreeNetLimit - res.FreeNetUsed
if avaialable > bandwidthNeed {
return 0, nil
}
return bandwidthNeed * 1000, err
}
func estimateTrc20TransactionFee() (int64, error) {
return trc20FeeLimit, nil
}