Skip to content

Commit 62e3f0e

Browse files
author
Fabrice Bascoulergue
authored
Upgrade to SDK v0.44.0 (#27)
* Refactor implementation by implementing extensions on site * Improve faucet request implementation * Upgrade to SDK v0.44.0 * Bump version to 0.5.0
1 parent 7936931 commit 62e3f0e

File tree

35 files changed

+3599
-196
lines changed

35 files changed

+3599
-196
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lum-network/sdk-javascript",
3-
"version": "0.4.9",
3+
"version": "0.5.0",
44
"license": "Apache-2.0",
55
"description": "Javascript SDK library for NodeJS and Web browsers to interact with the Lum Network.",
66
"homepage": "https://github.com/lum-network/sdk-javascript#readme",
@@ -35,7 +35,7 @@
3535
"format": "prettier --write '**/*.{js,jsx,ts,tsx,css,json,md,html,yml}'",
3636
"bump": "npm version",
3737
"preget-proto": "rm -rf proto",
38-
"get-proto": "CREF=v0.42.0 LREF=master sh ./scripts/get-proto.sh",
38+
"get-proto": "COSMOS_REF=v0.44.0 IBC_REF=v1.2.0 LUM_REF=master sh ./scripts/get-proto.sh",
3939
"define-proto": "sh ./scripts/define-proto.sh",
4040
"postdefine-proto": "prettier --write \"src/codec/**/*.ts\""
4141
},

scripts/define-proto.sh

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ ROOT_PROTO_DIR="./proto/cosmos/cosmos-sdk"
66
COSMOS_PROTO_DIR="$ROOT_PROTO_DIR/proto"
77
THIRD_PARTY_PROTO_DIR="$ROOT_PROTO_DIR/third_party/proto"
88

9+
ROOT_IBC_PROTO_DIR="./proto/ibc/ibc-go"
10+
IBC_PROTO_DIR="$ROOT_IBC_PROTO_DIR/proto"
11+
912
ROOT_LUM_PROTO_DIR="./proto/lum-network/chain"
1013
LUM_PROTO_DIR="$ROOT_LUM_PROTO_DIR/proto"
1114

@@ -19,6 +22,7 @@ protoc \
1922
--proto_path="$COSMOS_PROTO_DIR" \
2023
--proto_path="$THIRD_PARTY_PROTO_DIR" \
2124
--proto_path="$LUM_PROTO_DIR" \
25+
--proto_path="$IBC_PROTO_DIR" \
2226
--ts_proto_opt="esModuleInterop=true,forceLong=long,useOptionals=true" \
2327
"$COSMOS_PROTO_DIR/cosmos/auth/v1beta1/auth.proto" \
2428
"$COSMOS_PROTO_DIR/cosmos/auth/v1beta1/query.proto" \
@@ -44,18 +48,19 @@ protoc \
4448
"$COSMOS_PROTO_DIR/cosmos/tx/signing/v1beta1/signing.proto" \
4549
"$COSMOS_PROTO_DIR/cosmos/tx/v1beta1/tx.proto" \
4650
"$COSMOS_PROTO_DIR/cosmos/vesting/v1beta1/vesting.proto" \
47-
"$COSMOS_PROTO_DIR/ibc/applications/transfer/v1/tx.proto" \
48-
"$COSMOS_PROTO_DIR/ibc/core/channel/v1/channel.proto" \
49-
"$COSMOS_PROTO_DIR/ibc/core/channel/v1/query.proto" \
50-
"$COSMOS_PROTO_DIR/ibc/core/channel/v1/tx.proto" \
51-
"$COSMOS_PROTO_DIR/ibc/core/client/v1/client.proto" \
52-
"$COSMOS_PROTO_DIR/ibc/core/client/v1/query.proto" \
53-
"$COSMOS_PROTO_DIR/ibc/core/client/v1/tx.proto" \
54-
"$COSMOS_PROTO_DIR/ibc/core/commitment/v1/commitment.proto" \
55-
"$COSMOS_PROTO_DIR/ibc/core/connection/v1/connection.proto" \
56-
"$COSMOS_PROTO_DIR/ibc/core/connection/v1/query.proto" \
57-
"$COSMOS_PROTO_DIR/ibc/core/connection/v1/tx.proto" \
58-
"$COSMOS_PROTO_DIR/ibc/lightclients/tendermint/v1/tendermint.proto" \
51+
"$IBC_PROTO_DIR/ibc/applications/transfer/v1/tx.proto" \
52+
"$IBC_PROTO_DIR/ibc/applications/transfer/v1/query.proto" \
53+
"$IBC_PROTO_DIR/ibc/core/channel/v1/channel.proto" \
54+
"$IBC_PROTO_DIR/ibc/core/channel/v1/query.proto" \
55+
"$IBC_PROTO_DIR/ibc/core/channel/v1/tx.proto" \
56+
"$IBC_PROTO_DIR/ibc/core/client/v1/client.proto" \
57+
"$IBC_PROTO_DIR/ibc/core/client/v1/query.proto" \
58+
"$IBC_PROTO_DIR/ibc/core/client/v1/tx.proto" \
59+
"$IBC_PROTO_DIR/ibc/core/commitment/v1/commitment.proto" \
60+
"$IBC_PROTO_DIR/ibc/core/connection/v1/connection.proto" \
61+
"$IBC_PROTO_DIR/ibc/core/connection/v1/query.proto" \
62+
"$IBC_PROTO_DIR/ibc/core/connection/v1/tx.proto" \
63+
"$IBC_PROTO_DIR/ibc/lightclients/tendermint/v1/tendermint.proto" \
5964
"$THIRD_PARTY_PROTO_DIR/confio/proofs.proto" \
6065
"$THIRD_PARTY_PROTO_DIR/tendermint/abci/types.proto" \
6166
"$THIRD_PARTY_PROTO_DIR/tendermint/crypto/keys.proto" \

scripts/get-proto.sh

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,68 @@ set -o errexit -o nounset -o pipefail
33
command -v shellcheck >/dev/null && shellcheck "$0"
44

55
PROTO_DIR="./proto"
6+
7+
##
8+
## Cosmos SDK
9+
##
610
COSMOS_DIR="$PROTO_DIR/cosmos"
711
COSMOS_SDK_DIR="$COSMOS_DIR/cosmos-sdk"
8-
ZIP_FILE="$COSMOS_DIR/tmp.zip"
12+
COSMOS_ZIP_FILE="$COSMOS_DIR/tmp.zip"
913

10-
LUM_NETWORK_DIR="$PROTO_DIR/lum-network"
11-
LUM_NETWORK_SDK_DIR="$LUM_NETWORK_DIR/chain"
12-
ZIP_LUM_FILE="$LUM_NETWORK_DIR/tmp.zip"
14+
# Init Cosmos REF
15+
COSMOS_REF=${COSMOS_REF:-"master"}
16+
COSMOS_SUFFIX=${COSMOS_REF}
17+
[[ $COSMOS_SUFFIX =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]] && COSMOS_SUFFIX=${COSMOS_SUFFIX#v}
1318

14-
CREF=${CREF:-"master"}
15-
CSUFFIX=${CREF}
16-
[[ $CSUFFIX =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]] && CSUFFIX=${CSUFFIX#v}
19+
# Create the Cosmos dir
20+
mkdir -p "$COSMOS_DIR"
1721

18-
LREF=${LREF:-"master"}
19-
LSUFFIX=${LREF}
20-
[[ $LSUFFIX =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]] && LSUFFIX=${LSUFFIX#v}
22+
# Download the Cosmos archive
23+
wget -qO "$COSMOS_ZIP_FILE" "https://github.com/cosmos/cosmos-sdk/archive/$COSMOS_REF.zip"
24+
unzip "$COSMOS_ZIP_FILE" "*.proto" -d "$COSMOS_DIR"
25+
mv "$COSMOS_SDK_DIR-$COSMOS_SUFFIX" "$COSMOS_SDK_DIR"
26+
rm "$COSMOS_ZIP_FILE"
2127

22-
# Create the cosmos dir
23-
mkdir -p "$COSMOS_DIR"
28+
##
29+
## IBC SDK
30+
##
31+
32+
IBC_DIR="$PROTO_DIR/ibc"
33+
IBC_SDK_DIR="$IBC_DIR/ibc-go"
34+
IBC_ZIP_FILE="$IBC_DIR/tmp.zip"
35+
36+
# Init IBC REF
37+
IBC_REF=${IBC_REF:-"master"}
38+
IBC_SUFFIX=${IBC_REF}
39+
[[ $IBC_SUFFIX =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]] && IBC_SUFFIX=${IBC_SUFFIX#v}
40+
41+
# Create the IBC dir
42+
mkdir -p "$IBC_DIR"
43+
44+
# Download the IBC archive
45+
wget -qO "$IBC_ZIP_FILE" "https://github.com/cosmos/ibc-go/archive/$IBC_REF.zip"
46+
unzip "$IBC_ZIP_FILE" "*.proto" -d "$IBC_DIR"
47+
mv "$IBC_SDK_DIR-$IBC_SUFFIX" "$IBC_SDK_DIR"
48+
rm "$IBC_ZIP_FILE"
49+
50+
##
51+
## LUM SDK
52+
##
53+
54+
LUM_DIR="$PROTO_DIR/lum-network"
55+
LUM_SDK_DIR="$LUM_DIR/chain"
56+
LUM_ZIP_FILE="$LUM_DIR/tmp.zip"
2457

25-
# Download the cosmos archive
26-
wget -qO "$ZIP_FILE" "https://github.com/cosmos/cosmos-sdk/archive/$CREF.zip"
27-
unzip "$ZIP_FILE" "*.proto" -d "$COSMOS_DIR"
28-
mv "$COSMOS_SDK_DIR-$CSUFFIX" "$COSMOS_SDK_DIR"
29-
rm "$ZIP_FILE"
58+
# Init LUM REF
59+
LUM_REF=${LUM_REF:-"master"}
60+
LUM_SUFFIX=${LUM_REF}
61+
[[ $LUM_SUFFIX =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]] && LUM_SUFFIX=${LUM_SUFFIX#v}
3062

31-
# Create the lum network dir
32-
mkdir -p "$LUM_NETWORK_DIR"
63+
# Create the LUM dir
64+
mkdir -p "$LUM_DIR"
3365

3466
# Download the beam archive
35-
wget -qO "$ZIP_LUM_FILE" "https://github.com/lum-network/chain/archive/$LREF.zip"
36-
unzip "$ZIP_LUM_FILE" "*.proto" -d "$LUM_NETWORK_DIR"
37-
mv "$LUM_NETWORK_SDK_DIR-$LSUFFIX" "$LUM_NETWORK_SDK_DIR"
38-
rm "$ZIP_LUM_FILE"
67+
wget -qO "$LUM_ZIP_FILE" "https://github.com/lum-network/chain/archive/$LUM_REF.zip"
68+
unzip "$LUM_ZIP_FILE" "*.proto" -d "$LUM_DIR"
69+
mv "$LUM_SDK_DIR-$LUM_SUFFIX" "$LUM_SDK_DIR"
70+
rm "$LUM_ZIP_FILE"

src/client/LumClient.ts

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
import { Tendermint34Client, StatusResponse } from '@cosmjs/tendermint-rpc';
2+
import { QueryClient as StargateQueryClient, accountFromAny } from '@cosmjs/stargate';
3+
4+
import { LumWallet, LumUtils, LumTypes } from '..';
25
import {
3-
QueryClient as StargateQueryClient,
4-
setupAuthExtension as StargateSetupAuthExtension,
5-
setupBankExtension as StargateSetupBankExtension,
6-
setupDistributionExtension as StargateDistributionExtension,
7-
setupStakingExtension as StargateStakingExtension,
8-
setupGovExtension as StargateGovExtension,
96
AuthExtension,
7+
setupAuthExtension,
108
BankExtension,
11-
StakingExtension,
9+
setupBankExtension,
10+
BeamExtension,
11+
setupBeamExtension,
1212
DistributionExtension,
13+
setupDistributionExtension,
1314
GovExtension,
14-
accountFromAny,
15-
} from '@cosmjs/stargate';
16-
17-
import { LumWallet, LumUtils, LumTypes } from '..';
18-
import { BeamExtension, setupBeamExtension as BeamSetupBeamExtension, MintExtension, setupMintExtension as MintSetupExtension } from '../extensions';
15+
setupGovExtension,
16+
IbcExtension,
17+
setupIbcExtension,
18+
MintExtension,
19+
setupMintExtension,
20+
StakingExtension,
21+
setupStakingExtension,
22+
} from '../extensions';
1923

2024
export class LumClient {
2125
readonly tmClient: Tendermint34Client;
22-
readonly queryClient: StargateQueryClient & AuthExtension & BankExtension & DistributionExtension & StakingExtension & GovExtension & MintExtension & BeamExtension;
26+
readonly queryClient: StargateQueryClient & AuthExtension & BankExtension & BeamExtension & DistributionExtension & GovExtension & IbcExtension & MintExtension & StakingExtension;
2327
private chainId?: string;
2428

2529
/**
@@ -31,13 +35,14 @@ export class LumClient {
3135
this.tmClient = tmClient;
3236
this.queryClient = StargateQueryClient.withExtensions(
3337
tmClient,
34-
StargateSetupAuthExtension,
35-
StargateSetupBankExtension,
36-
StargateDistributionExtension,
37-
StargateStakingExtension,
38-
StargateGovExtension,
39-
MintSetupExtension,
40-
BeamSetupBeamExtension,
38+
setupAuthExtension,
39+
setupBankExtension,
40+
setupBeamExtension,
41+
setupDistributionExtension,
42+
setupGovExtension,
43+
setupIbcExtension,
44+
setupMintExtension,
45+
setupStakingExtension,
4146
);
4247

4348
// Used for debugging while gasWanted, gasUsed and codespace are still waiting to be included in the code lib
@@ -136,19 +141,6 @@ export class LumClient {
136141
* @param address wallet address
137142
*/
138143
getAccount = async (address: string): Promise<LumTypes.Account | null> => {
139-
const anyAccount = await this.queryClient.auth.verified.account(address);
140-
if (!anyAccount) {
141-
return null;
142-
}
143-
return accountFromAny(anyAccount);
144-
};
145-
146-
/**
147-
* Get account information without verifying its existence
148-
*
149-
* @param address wallet address
150-
*/
151-
getAccountUnverified = async (address: string): Promise<LumTypes.Account | null> => {
152144
const anyAccount = await this.queryClient.auth.account(address);
153145
if (!anyAccount) {
154146
return null;
@@ -163,27 +155,16 @@ export class LumClient {
163155
* @param searchDenom Coin denomination (ex: lum)
164156
*/
165157
getBalance = async (address: string, searchDenom: string): Promise<LumTypes.Coin | null> => {
166-
const balance = await this.queryClient.bank.verified.balance(address, searchDenom);
167-
return balance ? balance : null;
168-
};
169-
170-
/**
171-
* Get an account balance without verifying their existence
172-
*
173-
* @param address wallet address
174-
* @param searchDenom Coin denomination (ex: lum)
175-
*/
176-
getBalanceUnverified = async (address: string, searchDenom: string): Promise<LumTypes.Coin | null> => {
177158
const balance = await this.queryClient.bank.balance(address, searchDenom);
178159
return balance ? balance : null;
179160
};
180161

181162
/**
182-
* Get all account balances without verifying their existence
163+
* Get all account balances
183164
*
184165
* @param address wallet address
185166
*/
186-
getAllBalancesUnverified = async (address: string): Promise<LumTypes.Coin[]> => {
167+
getAllBalances = async (address: string): Promise<LumTypes.Coin[]> => {
187168
const balances = await this.queryClient.bank.allBalances(address);
188169
return balances;
189170
};

0 commit comments

Comments
 (0)