Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lum-network/sdk-javascript",
"version": "0.4.9",
"version": "0.5.0",
"license": "Apache-2.0",
"description": "Javascript SDK library for NodeJS and Web browsers to interact with the Lum Network.",
"homepage": "https://github.com/lum-network/sdk-javascript#readme",
Expand Down Expand Up @@ -35,7 +35,7 @@
"format": "prettier --write '**/*.{js,jsx,ts,tsx,css,json,md,html,yml}'",
"bump": "npm version",
"preget-proto": "rm -rf proto",
"get-proto": "CREF=v0.42.0 LREF=master sh ./scripts/get-proto.sh",
"get-proto": "COSMOS_REF=v0.44.0 IBC_REF=v1.2.0 LUM_REF=master sh ./scripts/get-proto.sh",
"define-proto": "sh ./scripts/define-proto.sh",
"postdefine-proto": "prettier --write \"src/codec/**/*.ts\""
},
Expand Down
29 changes: 17 additions & 12 deletions scripts/define-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ ROOT_PROTO_DIR="./proto/cosmos/cosmos-sdk"
COSMOS_PROTO_DIR="$ROOT_PROTO_DIR/proto"
THIRD_PARTY_PROTO_DIR="$ROOT_PROTO_DIR/third_party/proto"

ROOT_IBC_PROTO_DIR="./proto/ibc/ibc-go"
IBC_PROTO_DIR="$ROOT_IBC_PROTO_DIR/proto"

ROOT_LUM_PROTO_DIR="./proto/lum-network/chain"
LUM_PROTO_DIR="$ROOT_LUM_PROTO_DIR/proto"

Expand All @@ -19,6 +22,7 @@ protoc \
--proto_path="$COSMOS_PROTO_DIR" \
--proto_path="$THIRD_PARTY_PROTO_DIR" \
--proto_path="$LUM_PROTO_DIR" \
--proto_path="$IBC_PROTO_DIR" \
--ts_proto_opt="esModuleInterop=true,forceLong=long,useOptionals=true" \
"$COSMOS_PROTO_DIR/cosmos/auth/v1beta1/auth.proto" \
"$COSMOS_PROTO_DIR/cosmos/auth/v1beta1/query.proto" \
Expand All @@ -44,18 +48,19 @@ protoc \
"$COSMOS_PROTO_DIR/cosmos/tx/signing/v1beta1/signing.proto" \
"$COSMOS_PROTO_DIR/cosmos/tx/v1beta1/tx.proto" \
"$COSMOS_PROTO_DIR/cosmos/vesting/v1beta1/vesting.proto" \
"$COSMOS_PROTO_DIR/ibc/applications/transfer/v1/tx.proto" \
"$COSMOS_PROTO_DIR/ibc/core/channel/v1/channel.proto" \
"$COSMOS_PROTO_DIR/ibc/core/channel/v1/query.proto" \
"$COSMOS_PROTO_DIR/ibc/core/channel/v1/tx.proto" \
"$COSMOS_PROTO_DIR/ibc/core/client/v1/client.proto" \
"$COSMOS_PROTO_DIR/ibc/core/client/v1/query.proto" \
"$COSMOS_PROTO_DIR/ibc/core/client/v1/tx.proto" \
"$COSMOS_PROTO_DIR/ibc/core/commitment/v1/commitment.proto" \
"$COSMOS_PROTO_DIR/ibc/core/connection/v1/connection.proto" \
"$COSMOS_PROTO_DIR/ibc/core/connection/v1/query.proto" \
"$COSMOS_PROTO_DIR/ibc/core/connection/v1/tx.proto" \
"$COSMOS_PROTO_DIR/ibc/lightclients/tendermint/v1/tendermint.proto" \
"$IBC_PROTO_DIR/ibc/applications/transfer/v1/tx.proto" \
"$IBC_PROTO_DIR/ibc/applications/transfer/v1/query.proto" \
"$IBC_PROTO_DIR/ibc/core/channel/v1/channel.proto" \
"$IBC_PROTO_DIR/ibc/core/channel/v1/query.proto" \
"$IBC_PROTO_DIR/ibc/core/channel/v1/tx.proto" \
"$IBC_PROTO_DIR/ibc/core/client/v1/client.proto" \
"$IBC_PROTO_DIR/ibc/core/client/v1/query.proto" \
"$IBC_PROTO_DIR/ibc/core/client/v1/tx.proto" \
"$IBC_PROTO_DIR/ibc/core/commitment/v1/commitment.proto" \
"$IBC_PROTO_DIR/ibc/core/connection/v1/connection.proto" \
"$IBC_PROTO_DIR/ibc/core/connection/v1/query.proto" \
"$IBC_PROTO_DIR/ibc/core/connection/v1/tx.proto" \
"$IBC_PROTO_DIR/ibc/lightclients/tendermint/v1/tendermint.proto" \
"$THIRD_PARTY_PROTO_DIR/confio/proofs.proto" \
"$THIRD_PARTY_PROTO_DIR/tendermint/abci/types.proto" \
"$THIRD_PARTY_PROTO_DIR/tendermint/crypto/keys.proto" \
Expand Down
78 changes: 55 additions & 23 deletions scripts/get-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,68 @@ set -o errexit -o nounset -o pipefail
command -v shellcheck >/dev/null && shellcheck "$0"

PROTO_DIR="./proto"

##
## Cosmos SDK
##
COSMOS_DIR="$PROTO_DIR/cosmos"
COSMOS_SDK_DIR="$COSMOS_DIR/cosmos-sdk"
ZIP_FILE="$COSMOS_DIR/tmp.zip"
COSMOS_ZIP_FILE="$COSMOS_DIR/tmp.zip"

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

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

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

# Create the cosmos dir
mkdir -p "$COSMOS_DIR"
##
## IBC SDK
##

IBC_DIR="$PROTO_DIR/ibc"
IBC_SDK_DIR="$IBC_DIR/ibc-go"
IBC_ZIP_FILE="$IBC_DIR/tmp.zip"

# Init IBC REF
IBC_REF=${IBC_REF:-"master"}
IBC_SUFFIX=${IBC_REF}
[[ $IBC_SUFFIX =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.+)?$ ]] && IBC_SUFFIX=${IBC_SUFFIX#v}

# Create the IBC dir
mkdir -p "$IBC_DIR"

# Download the IBC archive
wget -qO "$IBC_ZIP_FILE" "https://github.com/cosmos/ibc-go/archive/$IBC_REF.zip"
unzip "$IBC_ZIP_FILE" "*.proto" -d "$IBC_DIR"
mv "$IBC_SDK_DIR-$IBC_SUFFIX" "$IBC_SDK_DIR"
rm "$IBC_ZIP_FILE"

##
## LUM SDK
##

LUM_DIR="$PROTO_DIR/lum-network"
LUM_SDK_DIR="$LUM_DIR/chain"
LUM_ZIP_FILE="$LUM_DIR/tmp.zip"

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

# Create the lum network dir
mkdir -p "$LUM_NETWORK_DIR"
# Create the LUM dir
mkdir -p "$LUM_DIR"

# Download the beam archive
wget -qO "$ZIP_LUM_FILE" "https://github.com/lum-network/chain/archive/$LREF.zip"
unzip "$ZIP_LUM_FILE" "*.proto" -d "$LUM_NETWORK_DIR"
mv "$LUM_NETWORK_SDK_DIR-$LSUFFIX" "$LUM_NETWORK_SDK_DIR"
rm "$ZIP_LUM_FILE"
wget -qO "$LUM_ZIP_FILE" "https://github.com/lum-network/chain/archive/$LUM_REF.zip"
unzip "$LUM_ZIP_FILE" "*.proto" -d "$LUM_DIR"
mv "$LUM_SDK_DIR-$LUM_SUFFIX" "$LUM_SDK_DIR"
rm "$LUM_ZIP_FILE"
73 changes: 27 additions & 46 deletions src/client/LumClient.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import { Tendermint34Client, StatusResponse } from '@cosmjs/tendermint-rpc';
import { QueryClient as StargateQueryClient, accountFromAny } from '@cosmjs/stargate';

import { LumWallet, LumUtils, LumTypes } from '..';
import {
QueryClient as StargateQueryClient,
setupAuthExtension as StargateSetupAuthExtension,
setupBankExtension as StargateSetupBankExtension,
setupDistributionExtension as StargateDistributionExtension,
setupStakingExtension as StargateStakingExtension,
setupGovExtension as StargateGovExtension,
AuthExtension,
setupAuthExtension,
BankExtension,
StakingExtension,
setupBankExtension,
BeamExtension,
setupBeamExtension,
DistributionExtension,
setupDistributionExtension,
GovExtension,
accountFromAny,
} from '@cosmjs/stargate';

import { LumWallet, LumUtils, LumTypes } from '..';
import { BeamExtension, setupBeamExtension as BeamSetupBeamExtension, MintExtension, setupMintExtension as MintSetupExtension } from '../extensions';
setupGovExtension,
IbcExtension,
setupIbcExtension,
MintExtension,
setupMintExtension,
StakingExtension,
setupStakingExtension,
} from '../extensions';

export class LumClient {
readonly tmClient: Tendermint34Client;
readonly queryClient: StargateQueryClient & AuthExtension & BankExtension & DistributionExtension & StakingExtension & GovExtension & MintExtension & BeamExtension;
readonly queryClient: StargateQueryClient & AuthExtension & BankExtension & BeamExtension & DistributionExtension & GovExtension & IbcExtension & MintExtension & StakingExtension;
private chainId?: string;

/**
Expand All @@ -31,13 +35,14 @@ export class LumClient {
this.tmClient = tmClient;
this.queryClient = StargateQueryClient.withExtensions(
tmClient,
StargateSetupAuthExtension,
StargateSetupBankExtension,
StargateDistributionExtension,
StargateStakingExtension,
StargateGovExtension,
MintSetupExtension,
BeamSetupBeamExtension,
setupAuthExtension,
setupBankExtension,
setupBeamExtension,
setupDistributionExtension,
setupGovExtension,
setupIbcExtension,
setupMintExtension,
setupStakingExtension,
);

// Used for debugging while gasWanted, gasUsed and codespace are still waiting to be included in the code lib
Expand Down Expand Up @@ -136,19 +141,6 @@ export class LumClient {
* @param address wallet address
*/
getAccount = async (address: string): Promise<LumTypes.Account | null> => {
const anyAccount = await this.queryClient.auth.verified.account(address);
if (!anyAccount) {
return null;
}
return accountFromAny(anyAccount);
};

/**
* Get account information without verifying its existence
*
* @param address wallet address
*/
getAccountUnverified = async (address: string): Promise<LumTypes.Account | null> => {
const anyAccount = await this.queryClient.auth.account(address);
if (!anyAccount) {
return null;
Expand All @@ -163,27 +155,16 @@ export class LumClient {
* @param searchDenom Coin denomination (ex: lum)
*/
getBalance = async (address: string, searchDenom: string): Promise<LumTypes.Coin | null> => {
const balance = await this.queryClient.bank.verified.balance(address, searchDenom);
return balance ? balance : null;
};

/**
* Get an account balance without verifying their existence
*
* @param address wallet address
* @param searchDenom Coin denomination (ex: lum)
*/
getBalanceUnverified = async (address: string, searchDenom: string): Promise<LumTypes.Coin | null> => {
const balance = await this.queryClient.bank.balance(address, searchDenom);
return balance ? balance : null;
};

/**
* Get all account balances without verifying their existence
* Get all account balances
*
* @param address wallet address
*/
getAllBalancesUnverified = async (address: string): Promise<LumTypes.Coin[]> => {
getAllBalances = async (address: string): Promise<LumTypes.Coin[]> => {
const balances = await this.queryClient.bank.allBalances(address);
return balances;
};
Expand Down
Loading