add options to querier constructor

add readme
This commit is contained in:
Laurent Le Houerou 2022-04-07 15:11:26 +04:00
parent c8099af2c9
commit a7c79b7106
2 changed files with 90 additions and 2 deletions

84
README.md Normal file
View File

@ -0,0 +1,84 @@
# Terra
---
A terra client with some protocol partial implementations (anchor, prism, terraswap type routers, ...)
To be able to compile, you need to add the following replace in your go.mod :
```
replace (
github.com/99designs/keyring => github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76
github.com/cosmos/cosmos-sdk => github.com/terra-money/cosmos-sdk v0.44.5-terra.2
github.com/cosmos/ledger-cosmos-go => github.com/terra-money/ledger-terra-go v0.11.2
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
github.com/tecbot/gorocksdb => github.com/cosmos/gorocksdb v1.2.0
github.com/tendermint/tendermint => github.com/terra-money/tendermint v0.34.14-terra.2
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
```
## Examples
---
### Querying Anchor borrow limit
```
ctx := context.Background()
querier := terra.NewQuerier(
httpClient := &http.Client{
Timeout: 30 * time.Second,
},
"https://lcd.terra.dev")
walletAddress, err := cosmos.AccAddressFromBech32("walletAddress")
anc, err := anchor.NewAnchor(querier)
if err != nil {
panic(err)
}
borrowLimit, err := anc.Overseer.BorrowLimit(ctx, walletAddress)
if err != nil {
panic(err)
}
```
### Depositing UST to Anchor
```
ctx := context.Background()
querier := terra.NewQuerier(
httpClient := &http.Client{
Timeout: 30 * time.Second,
},
"https://lcd.terra.dev")
wallet, err := terra.NewWalletFromMnemonic(
querier,
"mnemonic",
0,
0)
if err != nil {
panic(err)
}
anc, err := anchor.NewAnchor(querier)
if err != nil {
panic(err)
}
err = terra.NewTransaction(querier).
Message(func() (cosmos.Msg, error) {
return anc.Market.NewDepositUSTMessage(wallet.Address(), decimal.NewFromInt(100))
}).
ExecuteAndWaitFor(ctx, wallet)
```

View File

@ -33,13 +33,17 @@ func WithChainId(chainId string) QuerierOption {
} }
} }
func NewQuerier(httpClient *http.Client, url string) *Querier { func NewQuerier(httpClient *http.Client, url string, options ...QuerierOption) *Querier {
return &Querier{ q := &Querier{
url: url, url: url,
httpClient: httpClient, httpClient: httpClient,
encodingConfig: terraappparams.MakeEncodingConfig(), encodingConfig: terraappparams.MakeEncodingConfig(),
chainId: "columbus-5", chainId: "columbus-5",
} }
for _, option := range options {
q = option(q)
}
return q
} }
func (q Querier) ChainId() string { func (q Querier) ChainId() string {