-
Notifications
You must be signed in to change notification settings - Fork 3
/
prepare.go
49 lines (41 loc) · 1.21 KB
/
prepare.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
45
46
47
48
49
package faucet
import (
"github.com/gnolang/faucet/estimate"
"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/sdk/bank"
"github.com/gnolang/gno/tm2/pkg/std"
)
// PrepareTxMessageFn is the callback method that
// constructs the faucet fund transaction message
type PrepareTxMessageFn func(PrepareCfg) std.Msg
// PrepareCfg specifies the tx prepare configuration
type PrepareCfg struct {
SendAmount std.Coins // the amount to be sent
FromAddress crypto.Address // the faucet address
ToAddress crypto.Address // the beneficiary address
}
// defaultPrepareTxMessage constructs the default
// native currency transfer message
func defaultPrepareTxMessage(cfg PrepareCfg) std.Msg {
return bank.MsgSend{
FromAddress: cfg.FromAddress,
ToAddress: cfg.ToAddress,
Amount: cfg.SendAmount,
}
}
// prepareTransaction prepares the transaction for signing
func prepareTransaction(
estimator estimate.Estimator,
msg std.Msg,
) *std.Tx {
// Construct the transaction
tx := &std.Tx{
Msgs: []std.Msg{msg},
Signatures: nil,
}
// Prepare the gas fee
gasFee := estimator.EstimateGasFee()
gasWanted := estimator.EstimateGasWanted(tx)
tx.Fee = std.NewFee(gasWanted, gasFee)
return tx
}