-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) Added example script for all queries and messages in the chain…
… `distribution` module
- Loading branch information
abel
committed
Mar 5, 2024
1 parent
bd9ffbe
commit 0e0b7a2
Showing
16 changed files
with
973 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
examples/chain/distribution/1_SetWithdrawAddress/example.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
"os" | ||
|
||
"github.com/InjectiveLabs/sdk-go/client" | ||
chainclient "github.com/InjectiveLabs/sdk-go/client/chain" | ||
"github.com/InjectiveLabs/sdk-go/client/common" | ||
rpchttp "github.com/cometbft/cometbft/rpc/client/http" | ||
) | ||
|
||
func main() { | ||
network := common.LoadNetwork("testnet", "lb") | ||
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | ||
os.Getenv("HOME")+"/.injectived", | ||
"injectived", | ||
"file", | ||
"inj-user", | ||
"12345678", | ||
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
false, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
withdrawAddress := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" | ||
|
||
msg := &types.MsgSetWithdrawAddress{ | ||
DelegatorAddress: senderAddress.String(), | ||
WithdrawAddress: withdrawAddress, | ||
} | ||
|
||
//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg | ||
response, err := chainClient.AsyncBroadcastMsg(msg) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
str, _ := json.MarshalIndent(response, "", " ") | ||
fmt.Print(string(str)) | ||
} |
File renamed without changes.
73 changes: 73 additions & 0 deletions
73
examples/chain/distribution/3_WithdrawValidatorCommission/example.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
"os" | ||
|
||
"github.com/InjectiveLabs/sdk-go/client" | ||
chainclient "github.com/InjectiveLabs/sdk-go/client/chain" | ||
"github.com/InjectiveLabs/sdk-go/client/common" | ||
rpchttp "github.com/cometbft/cometbft/rpc/client/http" | ||
) | ||
|
||
func main() { | ||
network := common.LoadNetwork("testnet", "lb") | ||
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | ||
os.Getenv("HOME")+"/.injectived", | ||
"injectived", | ||
"file", | ||
"inj-user", | ||
"12345678", | ||
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
false, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
validatorAddress := "injvaloper1ultw9r29l8nxy5u6thcgusjn95vsy2caw722q5" | ||
|
||
msg := &types.MsgWithdrawValidatorCommission{ | ||
ValidatorAddress: validatorAddress, | ||
} | ||
|
||
//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg | ||
response, err := chainClient.AsyncBroadcastMsg(msg) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
str, _ := json.MarshalIndent(response, "", " ") | ||
fmt.Print(string(str)) | ||
} |
75 changes: 75 additions & 0 deletions
75
examples/chain/distribution/4_FundCommunityPool/example.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/cosmos/cosmos-sdk/types" | ||
distriutiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" | ||
"os" | ||
|
||
"github.com/InjectiveLabs/sdk-go/client" | ||
chainclient "github.com/InjectiveLabs/sdk-go/client/chain" | ||
"github.com/InjectiveLabs/sdk-go/client/common" | ||
rpchttp "github.com/cometbft/cometbft/rpc/client/http" | ||
) | ||
|
||
func main() { | ||
network := common.LoadNetwork("testnet", "lb") | ||
tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( | ||
os.Getenv("HOME")+"/.injectived", | ||
"injectived", | ||
"file", | ||
"inj-user", | ||
"12345678", | ||
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided | ||
false, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx, err := chainclient.NewClientContext( | ||
network.ChainId, | ||
senderAddress.String(), | ||
cosmosKeyring, | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) | ||
|
||
chainClient, err := chainclient.NewChainClient( | ||
clientCtx, | ||
network, | ||
common.OptionGasPrices(client.DefaultGasPriceWithDenom), | ||
) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
amount := types.NewCoin("inj", types.NewInt(1)) | ||
|
||
msg := &distriutiontypes.MsgFundCommunityPool{ | ||
Amount: []types.Coin{amount}, | ||
Depositor: senderAddress.String(), | ||
} | ||
|
||
//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg | ||
response, err := chainClient.AsyncBroadcastMsg(msg) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
str, _ := json.MarshalIndent(response, "", " ") | ||
fmt.Print(string(str)) | ||
} |
Oops, something went wrong.