parent
7ac7dcc127
commit
101a4aef80
@ -0,0 +1,146 @@ |
||||
diff --git a/build/cosmwasmclient.js b/build/cosmwasmclient.js
|
||||
index 8f6305b0263886c5c31fab661c9235723ba1e6e9..a3c7f20135babd6dd7774e4f2ac7e79cb0462db1 100644
|
||||
--- a/build/cosmwasmclient.js
|
||||
+++ b/build/cosmwasmclient.js
|
||||
@@ -10,6 +10,112 @@ const utils_1 = require("@cosmjs/utils");
|
||||
const abci_1 = require("cosmjs-types/cosmos/base/abci/v1beta1/abci");
|
||||
const types_1 = require("cosmjs-types/cosmwasm/wasm/v1/types");
|
||||
const modules_1 = require("./modules");
|
||||
+
|
||||
+/* Code copied in from injective SDK to avoid importing all 9Mb of the library */
|
||||
+// node_modules/@injectivelabs/core-proto-ts/cjs/google/protobuf/any.js
|
||||
+const minimal_1 = require("protobufjs/minimal");
|
||||
+const Any = {
|
||||
+ decode(input, length) {
|
||||
+ const reader = input instanceof minimal_1.Reader ? input : minimal_1.Reader.create(input);
|
||||
+ let end = length === undefined ? reader.len : reader.pos + length;
|
||||
+ const message = { typeUrl: "", value: new Uint8Array(0) };
|
||||
+ while (reader.pos < end) {
|
||||
+ const tag = reader.uint32();
|
||||
+ switch (tag >>> 3) {
|
||||
+ case 1:
|
||||
+ if (tag !== 10) {
|
||||
+ break;
|
||||
+ }
|
||||
+ message.typeUrl = reader.string();
|
||||
+ continue;
|
||||
+ case 2:
|
||||
+ if (tag !== 18) {
|
||||
+ break;
|
||||
+ }
|
||||
+ message.value = reader.bytes();
|
||||
+ continue;
|
||||
+ }
|
||||
+ if ((tag & 7) === 4 || tag === 0) {
|
||||
+ break;
|
||||
+ }
|
||||
+ reader.skipType(tag & 7);
|
||||
+ }
|
||||
+ return message;
|
||||
+ },
|
||||
+ };
|
||||
+ // node_modules/@injectivelabs/core-proto-ts/cjs/cosmos/auth/v1beta1/auth.js
|
||||
+const BaseAccount = {
|
||||
+ decode(input, length) {
|
||||
+ const reader = input instanceof minimal_1.Reader ? input : minimal_1.Reader.create(input);
|
||||
+ let end = length === undefined ? reader.len : reader.pos + length;
|
||||
+ const message = { address: "", pubKey: undefined, accountNumber: "0", sequence: "0" };
|
||||
+ while (reader.pos < end) {
|
||||
+ const tag = reader.uint32();
|
||||
+ switch (tag >>> 3) {
|
||||
+ case 1:
|
||||
+ if (tag !== 10) {
|
||||
+ break;
|
||||
+ }
|
||||
+ message.address = reader.string();
|
||||
+ continue;
|
||||
+ case 2:
|
||||
+ if (tag !== 18) {
|
||||
+ break;
|
||||
+ }
|
||||
+ message.pubKey = Any.decode(reader, reader.uint32());
|
||||
+ continue;
|
||||
+ case 3:
|
||||
+ if (tag !== 24) {
|
||||
+ break;
|
||||
+ }
|
||||
+ message.accountNumber = longToString(reader.uint64());
|
||||
+ continue;
|
||||
+ case 4:
|
||||
+ if (tag !== 32) {
|
||||
+ break;
|
||||
+ }
|
||||
+ message.sequence = longToString(reader.uint64());
|
||||
+ continue;
|
||||
+ }
|
||||
+ if ((tag & 7) === 4 || tag === 0) {
|
||||
+ break;
|
||||
+ }
|
||||
+ reader.skipType(tag & 7);
|
||||
+ }
|
||||
+ return message;
|
||||
+ },
|
||||
+};
|
||||
+// node_modules/@injectivelabs/core-proto-ts/cjs/injective/types/v1beta1/account.js
|
||||
+const EthAccount = {
|
||||
+ decode(input, length) {
|
||||
+ const reader = input instanceof minimal_1.Reader ? input : minimal_1.Reader.create(input);
|
||||
+ let end = length === undefined ? reader.len : reader.pos + length;
|
||||
+ const message = { baseAccount: undefined, codeHash: new Uint8Array(0) };
|
||||
+ while (reader.pos < end) {
|
||||
+ const tag = reader.uint32();
|
||||
+ switch (tag >>> 3) {
|
||||
+ case 1:
|
||||
+ if (tag !== 10) {
|
||||
+ break;
|
||||
+ }
|
||||
+ message.baseAccount = BaseAccount.decode(reader, reader.uint32());
|
||||
+ continue;
|
||||
+ case 2:
|
||||
+ if (tag !== 18) {
|
||||
+ break;
|
||||
+ }
|
||||
+ message.codeHash = reader.bytes();
|
||||
+ continue;
|
||||
+ }
|
||||
+ if ((tag & 7) === 4 || tag === 0) {
|
||||
+ break;
|
||||
+ }
|
||||
+ reader.skipType(tag & 7);
|
||||
+ }
|
||||
+ return message;
|
||||
+ },
|
||||
+};
|
||||
+
|
||||
class CosmWasmClient {
|
||||
/**
|
||||
* Creates an instance by connecting to the given Tendermint RPC endpoint.
|
||||
@@ -78,9 +184,28 @@ class CosmWasmClient {
|
||||
const status = await this.forceGetTmClient().status();
|
||||
return status.syncInfo.latestBlockHeight;
|
||||
}
|
||||
+ decodeInjectiveAccount(injAccount){
|
||||
+ const account = EthAccount.decode(injAccount.value);
|
||||
+ const baseAccount = account.baseAccount;
|
||||
+ const pubKey = baseAccount.pubKey;
|
||||
+ return {
|
||||
+ address: baseAccount.address,
|
||||
+ pubkey: pubKey
|
||||
+ ? {
|
||||
+ type: '/injective.crypto.v1beta1.ethsecp256k1.PubKey',
|
||||
+ value: Buffer.from(pubKey.value).toString('base64'),
|
||||
+ }
|
||||
+ : null,
|
||||
+ accountNumber: parseInt(baseAccount.accountNumber, 10),
|
||||
+ sequence: parseInt(baseAccount.sequence, 10),
|
||||
+ };
|
||||
+ }
|
||||
async getAccount(searchAddress) {
|
||||
try {
|
||||
const account = await this.forceGetQueryClient().auth.account(searchAddress);
|
||||
+ if (searchAddress.startsWith('inj')) {
|
||||
+ return this.decodeInjectiveAccount(account);
|
||||
+ }
|
||||
return account ? (0, stargate_1.accountFromAny)(account) : null;
|
||||
}
|
||||
catch (error) {
|
After Width: | Height: | Size: 1.3 KiB |
Loading…
Reference in new issue