Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gnoclient): add MultiCall #1565

Merged
merged 45 commits into from
Feb 1, 2024
Merged
Changes from 5 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bf6a79f
wip save
leohhhn Jan 20, 2024
738f70c
add msgcall wrapper & add batchcall func
leohhhn Jan 21, 2024
2de3712
remove comment
leohhhn Jan 21, 2024
de83a5b
add comment
leohhhn Jan 21, 2024
05aedff
fix lint
leohhhn Jan 21, 2024
ebaf516
remove multicall func, update struct, remove aliasing
leohhhn Jan 22, 2024
9a5fd71
extract errors to pkg level
leohhhn Jan 22, 2024
bdb9f60
remove aliasing
leohhhn Jan 22, 2024
fb2416d
add preliminary tests, remove some error wrapping
leohhhn Jan 22, 2024
948dc9f
Merge branch 'master' into feat/gnoclient-batchcall
leohhhn Jan 23, 2024
79cbe36
Merge branch 'master' into feat/gnoclient-batchcall
leohhhn Jan 24, 2024
ced737b
inline caller
leohhhn Jan 25, 2024
9c91240
add baseTxCfg, modify Call flow
leohhhn Jan 25, 2024
c9e85ea
add basecfg validation, comments, errors
leohhhn Jan 25, 2024
bb828df
add more unit tests, comments
leohhhn Jan 25, 2024
175bd5e
made unit tests better
leohhhn Jan 25, 2024
f0958d8
add testcase
leohhhn Jan 25, 2024
3ad650e
Merge branch 'master' into feat/gnoclient-batchcall
leohhhn Jan 26, 2024
a6fb52d
make errors public
leohhhn Jan 29, 2024
8be378e
remove fmt.errorf
leohhhn Jan 29, 2024
def2e0b
make error names clearer
leohhhn Jan 29, 2024
4f9febf
mocking wip
leohhhn Jan 29, 2024
cb7496f
add rpcclient mock, wip tests
leohhhn Jan 31, 2024
2cd4af3
expand txbroadcast res
leohhhn Jan 31, 2024
9f6cd76
wip more tests
leohhhn Jan 31, 2024
23fb5b4
add full rpcclient mock infra
leohhhn Jan 31, 2024
3ecf8f0
simplify tests
leohhhn Jan 31, 2024
a190219
typo fix
leohhhn Jan 31, 2024
7caf692
remove comment
leohhhn Jan 31, 2024
085ce3f
fix lint
leohhhn Jan 31, 2024
849ede2
fix test err
leohhhn Jan 31, 2024
788ccb9
Merge branch 'master' into feat/gnoclient-batchcall
leohhhn Jan 31, 2024
800d188
parallel test
leohhhn Feb 1, 2024
9e8c7e2
replace assert with require
leohhhn Feb 1, 2024
a4bf5cb
add errors.Is
leohhhn Feb 1, 2024
44a0657
remove panics
leohhhn Feb 1, 2024
1bad3de
add pointer receivers
leohhhn Feb 1, 2024
a663e8e
make fmt
leohhhn Feb 1, 2024
cd707ad
Merge branch 'master' into feat/gnoclient-batchcall
leohhhn Feb 1, 2024
f6e78d2
update imports, fix assert.ErrorIs
leohhhn Feb 1, 2024
c7481f0
Merge branch 'master' into feat/gnoclient-batchcall
leohhhn Feb 1, 2024
bd9ac4b
make fmt
leohhhn Feb 1, 2024
0e6300e
remove double assert
leohhhn Feb 1, 2024
60b5963
rename mock to mock_test
leohhhn Feb 1, 2024
7354457
Merge branch 'master' into feat/gnoclient-batchcall
leohhhn Feb 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 98 additions & 9 deletions gno.land/pkg/gnoclient/client_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,34 @@
"github.com/gnolang/gno/tm2/pkg/std"
)

// MsgCall - syntax sugar for vm.MsgCall
type MsgCall struct {
PkgPath string // Package path
FuncName string // Function name
Args []string // Function arguments
Send string // Send amount
}

// CallCfg contains configuration options for executing a contract call.
type CallCfg struct {
PkgPath string // Package path
FuncName string // Function name
Args []string // Function arguments
GasFee string // Gas fee
GasWanted int64 // Gas wanted
Send string // Send amount
AccountNumber uint64 // Account number
SequenceNumber uint64 // Sequence number
Memo string // Memo
MsgCall
GasFee string // Gas fee
GasWanted int64 // Gas wanted
AccountNumber uint64 // Account number
SequenceNumber uint64 // Sequence number
Memo string // Memo
}

// MultiCallCfg contains configuration options for executing a contract call.
type MultiCallCfg struct {
Msgs []MsgCall

// Per Tx
GasFee string // Gas fee
GasWanted int64 // Gas wanted
AccountNumber uint64 // Account number
SequenceNumber uint64 // Sequence number
Memo string // Memo
}

// Call executes a contract call on the blockchain.
Expand Down Expand Up @@ -81,6 +98,78 @@
return c.signAndBroadcastTxCommit(tx, accountNumber, sequenceNumber)
}

// MultiCall executes a contract call on the blockchain.
func (c *Client) MultiCall(cfg MultiCallCfg) (*ctypes.ResultBroadcastTxCommit, error) {
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
// Validate required client fields.
if err := c.validateSigner(); err != nil {
return nil, errors.Wrap(err, "validate signer")
}
if err := c.validateRPCClient(); err != nil {
return nil, errors.Wrap(err, "validate RPC client")
}

Check warning on line 109 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L102-L109

Added lines #L102 - L109 were not covered by tests

sequenceNumber := cfg.SequenceNumber
accountNumber := cfg.AccountNumber

msgs := make([]vm.MsgCall, 0, len(cfg.Msgs))
for _, msg := range cfg.Msgs {
pkgPath := msg.PkgPath
funcName := msg.FuncName
args := msg.Args
send := msg.Send
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved

// Validate config.
if pkgPath == "" {
return nil, errors.New("missing PkgPath")
}
if funcName == "" {
return nil, errors.New("missing FuncName")
}

Check warning on line 127 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L111-L127

Added lines #L111 - L127 were not covered by tests
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved

// Parse send amount.
sendCoins, err := std.ParseCoins(send)
if err != nil {
return nil, errors.Wrap(err, "parsing send coins")
}

Check warning on line 133 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L130-L133

Added lines #L130 - L133 were not covered by tests

if err != nil {
return nil, errors.Wrap(err, "parsing gas fee coin")
}

Check warning on line 137 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L135-L137

Added lines #L135 - L137 were not covered by tests
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved

caller := c.Signer.Info().GetAddress()
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved

msgs = append(msgs, vm.MsgCall{
Caller: caller,
Send: sendCoins,
PkgPath: pkgPath,
Func: funcName,
Args: args,
})

Check warning on line 147 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L139-L147

Added lines #L139 - L147 were not covered by tests
}

// Cast vm.MsgCall back into std.Msg
stdMsgs := make([]std.Msg, len(msgs))
for i, msg := range msgs {
stdMsgs[i] = msg
}

Check warning on line 154 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L151-L154

Added lines #L151 - L154 were not covered by tests

// Parse gas wanted & fee.
gasFeeCoins, err := std.ParseCoin(cfg.GasFee)
if err != nil {
return nil, errors.Wrap(err, "parsing gas fee coin")
}

Check warning on line 160 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L157-L160

Added lines #L157 - L160 were not covered by tests

// Pack transaction
tx := std.Tx{
Msgs: stdMsgs,
Fee: std.NewFee(cfg.GasWanted, gasFeeCoins),
Signatures: nil,
Memo: "",
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
}

return c.signAndBroadcastTxCommit(tx, accountNumber, sequenceNumber)

Check warning on line 170 in gno.land/pkg/gnoclient/client_txs.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoclient/client_txs.go#L163-L170

Added lines #L163 - L170 were not covered by tests
}

// signAndBroadcastTxCommit signs a transaction and broadcasts it, returning the result.
func (c Client) signAndBroadcastTxCommit(tx std.Tx, accountNumber, sequenceNumber uint64) (*ctypes.ResultBroadcastTxCommit, error) {
caller := c.Signer.Info().GetAddress()
Expand Down
Loading