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

Update IBC-Go to canonical v3.4.0 #632

Merged
merged 26 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
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
2 changes: 2 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [main]
pull_request:
branches: [main]
paths-ignore:
shaspitz marked this conversation as resolved.
Show resolved Hide resolved
- "ibc"
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ jobs:

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you put the removed newline back?

run:
skip-dirs:
shaspitz marked this conversation as resolved.
Show resolved Hide resolved
- ibc/
2 changes: 1 addition & 1 deletion .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: -exclude-generated ./...
args: -exclude-dir=ibc ./... -exclude-generated ./...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ docs/tla/states/
*.out
vendor/
.vscode
.idea
6 changes: 3 additions & 3 deletions app/consumer-democracy/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ import (
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
ibctestingcore "github.com/cosmos/interchain-security/ibc/core"
ibctesting "github.com/cosmos/interchain-security/ibc/testing"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand Down Expand Up @@ -108,7 +109,6 @@ import (

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
)

const (
Expand Down Expand Up @@ -813,7 +813,7 @@ func (app *App) GetBaseApp() *baseapp.BaseApp {
}

// GetStakingKeeper implements the TestingApp interface.
func (app *App) GetStakingKeeper() ibcclienttypes.StakingKeeper {
func (app *App) GetStakingKeeper() ibctestingcore.StakingKeeper {
return app.ConsumerKeeper
}

Expand Down
2 changes: 1 addition & 1 deletion app/consumer-democracy/proposals_whitelisting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package app_test
import (
"testing"

ibctesting "github.com/cosmos/ibc-go/v3/testing"
appConsumer "github.com/cosmos/interchain-security/app/consumer-democracy"
ibctesting "github.com/cosmos/interchain-security/ibc/testing"
icstestingutils "github.com/cosmos/interchain-security/testutil/ibc_testing"
"github.com/stretchr/testify/require"
)
Expand Down
7 changes: 4 additions & 3 deletions app/consumer/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ import (
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
ibctestingcore "github.com/cosmos/interchain-security/ibc/core"
ibctesting "github.com/cosmos/interchain-security/ibc/testing"
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
Expand All @@ -84,7 +85,7 @@ import (

// unnamed import of statik for swagger UI support
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
//ibcclienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
shaspitz marked this conversation as resolved.
Show resolved Hide resolved
)

const (
Expand Down Expand Up @@ -681,7 +682,7 @@ func (app *App) GetBaseApp() *baseapp.BaseApp {
}

// GetStakingKeeper implements the TestingApp interface.
func (app *App) GetStakingKeeper() ibcclienttypes.StakingKeeper {
func (app *App) GetStakingKeeper() ibctestingcore.StakingKeeper {
return app.ConsumerKeeper
}

Expand Down
5 changes: 3 additions & 2 deletions app/provider/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ import (
porttypes "github.com/cosmos/ibc-go/v3/modules/core/05-port/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v3/modules/core/keeper"
ibctesting "github.com/cosmos/ibc-go/v3/testing"
ibctestingcore "github.com/cosmos/interchain-security/ibc/core"
ibctesting "github.com/cosmos/interchain-security/ibc/testing"

"github.com/gorilla/mux"
"github.com/gravity-devs/liquidity/x/liquidity"
Expand Down Expand Up @@ -834,7 +835,7 @@ func (app *App) GetBaseApp() *baseapp.BaseApp {
}

// GetStakingKeeper implements the TestingApp interface.
func (app *App) GetStakingKeeper() ibcclienttypes.StakingKeeper {
func (app *App) GetStakingKeeper() ibctestingcore.StakingKeeper {
return app.StakingKeeper
}

Expand Down
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ module github.com/cosmos/interchain-security
go 1.18

require (
github.com/cosmos/cosmos-sdk v0.45.12-0.20221116140330-9c145c827001
github.com/cosmos/gaia/v8 v8.0.0-20221209131454-f73f97517b5b
github.com/cosmos/cosmos-sdk v0.45.11-ics
github.com/cosmos/ibc-go/v3 v3.4.0
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
Expand Down Expand Up @@ -70,7 +69,6 @@ require (
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect
github.com/gogo/gateway v1.1.0 // indirect
github.com/golang/glog v1.0.0 // indirect
Expand Down Expand Up @@ -120,7 +118,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.14.0 // indirect
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tendermint/btcd v0.1.1 // indirect
Expand All @@ -139,7 +137,6 @@ require (

replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
github.com/cosmos/ibc-go/v3 => github.com/informalsystems/ibc-go/v3 v3.4.1-0.20221202165607-3dc5ba251371
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/stretchr/testify => github.com/stretchr/testify v1.7.1
google.golang.org/grpc => google.golang.org/grpc v1.33.2
Expand Down
16 changes: 6 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,8 @@ github.com/cosmos/btcutil v1.0.4 h1:n7C2ngKXo7UC9gNyMNLbzqz7Asuf+7Qv4gnX/rOdQ44=
github.com/cosmos/btcutil v1.0.4/go.mod h1:Ffqc8Hn6TJUdDgHBwIZLtrLQC1KdJ9jGJl/TvgUaxbU=
github.com/cosmos/cosmos-sdk v0.44.2/go.mod h1:fwQJdw+aECatpTvQTo1tSfHEsxACdZYU80QCZUPnHr4=
github.com/cosmos/cosmos-sdk v0.44.3/go.mod h1:bA3+VenaR/l/vDiYzaiwbWvRPWHMBX2jG0ygiFtiBp0=
github.com/cosmos/cosmos-sdk v0.45.12-0.20221116140330-9c145c827001 h1:p81moZK9wKhQxhivK4N8m5mxk8AOCJA9Ru/P14hmjH0=
github.com/cosmos/cosmos-sdk v0.45.12-0.20221116140330-9c145c827001/go.mod h1:knmcuR38eVg8I8U+AYhTtSLtcsHzYCROaUCbNcUgfDU=
github.com/cosmos/gaia/v8 v8.0.0-20221209131454-f73f97517b5b h1:lJJZeudSmu+PCna2yDuNnBNcpxKoKcSlwbBj2kOJeu8=
github.com/cosmos/gaia/v8 v8.0.0-20221209131454-f73f97517b5b/go.mod h1:yTINtn8zJdwQIg4H7cqOY5alJoI9M/sjIoJKrJ39nRM=
github.com/cosmos/cosmos-sdk v0.45.11-ics h1:nTxsjRKwP93V3eR9rEUIVaDuEYYJ8n8GyugX4sxyF/c=
github.com/cosmos/cosmos-sdk v0.45.11-ics/go.mod h1:knmcuR38eVg8I8U+AYhTtSLtcsHzYCROaUCbNcUgfDU=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand All @@ -279,6 +277,8 @@ github.com/cosmos/iavl v0.17.1/go.mod h1:7aisPZK8yCpQdy3PMvKeO+bhq1NwDjUwjzxwwRO
github.com/cosmos/iavl v0.19.4 h1:t82sN+Y0WeqxDLJRSpNd8YFX5URIrT+p8n6oJbJ2Dok=
github.com/cosmos/iavl v0.19.4/go.mod h1:X9PKD3J0iFxdmgNLa7b2LYWdsGd90ToV5cAONApkEPw=
github.com/cosmos/ibc-go v1.2.2/go.mod h1:XmYjsRFOs6Q9Cz+CSsX21icNoH27vQKb3squgnCOCbs=
github.com/cosmos/ibc-go/v3 v3.4.0 h1:ha3cqEG36pqMWqA1D+kxDWBTZXpeFMd/aZIQF7I0xro=
github.com/cosmos/ibc-go/v3 v3.4.0/go.mod h1:VwB/vWu4ysT5DN2aF78d17LYmx3omSAdq6gpKvM7XRA=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8=
github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4=
Expand Down Expand Up @@ -400,8 +400,8 @@ github.com/getkin/kin-openapi v0.61.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
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/gin-gonic/gin v1.7.0 h1:jGB9xAJQ12AIGNB4HguylppmDK1Am9ppF7XnGXXJuoU=
github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs=
Expand Down Expand Up @@ -434,7 +434,6 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE=
github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4=
github.com/go-redis/redis v6.15.8+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
Expand Down Expand Up @@ -703,8 +702,6 @@ github.com/influxdata/promql/v2 v2.12.0/go.mod h1:fxOPu+DY0bqCTCECchSRtWfc+0X19y
github.com/influxdata/roaring v0.4.13-0.20180809181101-fc520f41fab6/go.mod h1:bSgUQ7q5ZLSO+bKBGqJiCBGAl+9DxyW63zLTujjUlOE=
github.com/influxdata/tdigest v0.0.0-20181121200506-bf2b5ad3c0a9/go.mod h1:Js0mqiSBE6Ffsg94weZZ2c+v/ciT8QRHFOap7EKDrR0=
github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368/go.mod h1:Wbbw6tYNvwa5dlB6304Sd+82Z3f7PmVZHVKU637d4po=
github.com/informalsystems/ibc-go/v3 v3.4.1-0.20221202165607-3dc5ba251371 h1:7apovdVgBXg4HRPlPOy9LFPoSqKgjVqDNr/2Hmiz998=
github.com/informalsystems/ibc-go/v3 v3.4.1-0.20221202165607-3dc5ba251371/go.mod h1:r4wFZXupXSNeoaxJGRNmcqiwvgRvKCQWSTqOVnw7WSo=
github.com/jackpal/go-nat-pmp v1.0.2-0.20160603034137-1fa385a6f458/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
github.com/jedisct1/go-minisign v0.0.0-20190909160543-45766022959e/go.mod h1:G1CVv03EnqU1wYL2dFwXxW2An0az9JTl/ZsqXQeBlkU=
Expand Down Expand Up @@ -1177,15 +1174,14 @@ github.com/ssgreg/nlreturn/v2 v2.1.0/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRk
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8OR4w3TdeIHIh1g6EMY5p0gVNOovcWC+1vpc7naMuAw=
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU=
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.0.0 h1:V1RVRa2hga4TV//RQpk2PCt314slS3N12024TsJoJUo=
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.0.0/go.mod h1:sRBHb6KwuHQVc07vy8Ice9wUKVdvzn7eEms9scr2Zco=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
Expand Down
41 changes: 41 additions & 0 deletions ibc/core/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package core

shaspitz marked this conversation as resolved.
Show resolved Hide resolved
import (
"strconv"

abci "github.com/tendermint/tendermint/abci/types"

clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v3/modules/core/04-channel/types"
)

// ReconstructPacketFromEvent recreates a packet from an appropriate provided event
func ReconstructPacketFromEvent(event abci.Event) (packet types.Packet, err error) {
attrMap := make(map[string][]byte)
for _, attr := range event.Attributes {
attrMap[string(attr.Key)] = attr.Value
}

sequence, err := strconv.Atoi(string(attrMap[string(types.AttributeKeySequence)]))
if err != nil {
return packet, err
}
timeoutTimestamp, err := strconv.Atoi(string(attrMap[string(types.AttributeKeyTimeoutTimestamp)]))
if err != nil {
return packet, err
}
timeoutHeight, err := clienttypes.ParseHeight(string(attrMap[string(types.AttributeKeyTimeoutHeight)]))
if err != nil {
return packet, err
}
return types.NewPacket(
attrMap[string(types.AttributeKeyData)], // data
uint64(sequence),
string(attrMap[string(types.AttributeKeySrcPort)]), //sourcePort,
string(attrMap[string(types.AttributeKeySrcChannel)]), //sourceChannel,
string(attrMap[string(types.AttributeKeyDstPort)]), //destinationPort,
string(attrMap[string(types.AttributeKeyDstChannel)]), //destinationChannel string,
timeoutHeight,
uint64(timeoutTimestamp),
), nil
}
12 changes: 12 additions & 0 deletions ibc/core/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package core

import (
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"time"
)

type StakingKeeper interface {
GetHistoricalInfo(ctx sdk.Context, height int64) (stakingtypes.HistoricalInfo, bool)
UnbondingTime(ctx sdk.Context) time.Duration
}
77 changes: 77 additions & 0 deletions ibc/simapp/helpers/test_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package helpers

import (
"github.com/cosmos/cosmos-sdk/client"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
authsign "github.com/cosmos/cosmos-sdk/x/auth/signing"
"math/rand"
)

// SimAppChainID hardcoded chainID for simulation
const (
DefaultGenTxGas = 1000000
)

// GenTx generates a signed mock transaction.
func GenTx(gen client.TxConfig, msgs []sdk.Msg, feeAmt sdk.Coins, gas uint64, chainID string, accNums, accSeqs []uint64, priv ...cryptotypes.PrivKey) (sdk.Tx, error) {
sigs := make([]signing.SignatureV2, len(priv))

// create a random length memo
r := rand.New(rand.NewSource(rand.Int63()))

memo := simulation.RandStringOfLength(r, simulation.RandIntBetween(r, 0, 100))

signMode := gen.SignModeHandler().DefaultMode()

// 1st round: set SignatureV2 with empty signatures, to set correct
// signer infos.
for i, p := range priv {
sigs[i] = signing.SignatureV2{
PubKey: p.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: signMode,
},
Sequence: accSeqs[i],
}
}

tx := gen.NewTxBuilder()
err := tx.SetMsgs(msgs...)
if err != nil {
return nil, err
}
err = tx.SetSignatures(sigs...)
if err != nil {
return nil, err
}
tx.SetMemo(memo)
tx.SetFeeAmount(feeAmt)
tx.SetGasLimit(gas)

// 2nd round: once all signer infos are set, every signer can sign.
for i, p := range priv {
signerData := authsign.SignerData{
ChainID: chainID,
AccountNumber: accNums[i],
Sequence: accSeqs[i],
}
signBytes, err := gen.SignModeHandler().GetSignBytes(signMode, signerData, tx.GetTx())
if err != nil {
panic(err)
}
sig, err := p.Sign(signBytes)
if err != nil {
panic(err)
}
sigs[i].Data.(*signing.SingleSignatureData).Signature = sig
err = tx.SetSignatures(sigs...)
if err != nil {
panic(err)
}
}

return tx.GetTx(), nil
}
Loading