Skip to content

Commit 66314ee

Browse files
committed
upgrade telescope, regen and test
1 parent 612a6de commit 66314ee

File tree

13 files changed

+162
-124
lines changed

13 files changed

+162
-124
lines changed

examples/telescope/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"devDependencies": {
5050
"@cosmjson/wasmswap": "^0.0.9",
51-
"@cosmology/telescope": "^0.104.0",
51+
"@cosmology/telescope": "^0.106.0",
5252
"@protobufs/cosmos": "^0.1.0",
5353
"@protobufs/cosmwasm": "^0.1.1",
5454
"@protobufs/ibc": "^0.1.0",

examples/telescope/pages/validator-test.tsx

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { useRpcClient, useRpcEndpoint } from '../src/codegen';
4646
import { QueryValidatorRequest } from '../src/codegen/cosmos/staking/v1beta1/query';
4747
import { PubKey } from '../src/codegen/cosmos/crypto/ed25519/keys';
4848
import { AnyAmino } from '../src/codegen/google/protobuf/any';
49+
import { Validator } from '../src/codegen/cosmos/staking/v1beta1/staking';
4950

5051
(BigInt.prototype as any).toJSON = function () {
5152
return this.toString();
@@ -189,75 +190,13 @@ export default function Home() {
189190
});
190191

191192
if (validator) {
192-
// toAmino
193-
// use the logic the same with interface.enabled
194-
// to decide Which PubKey to use(ed25519? secp256k1? secp256r1)
195-
const pubkey = PubKey.decode(validator!.validator!.consensusPubkey!.value);
196-
197-
//dhhD3I5QbtC870Il4IzML5Q2AwVDiSn9/HJ9w09Rgdg=
198-
//not crypto encoded
199-
const pubKeyString = toBase64(pubkey.key);
200-
201-
//cosmos1zcjduepqwcvy8hyw2phdp080ggj7prxv972rvqc9gwyjnl0uwf7uxn63s8vquhs900
202-
const cryptoEncodedPubkey = encodeBech32Pubkey(
203-
{
204-
type: pubkeyType.ed25519,
205-
value: pubKeyString,
206-
},
207-
'cosmos'
208-
);
209-
210-
const consensus_pubkey: AnyAmino = {
211-
type: validator!.validator!.consensusPubkey!.typeUrl,
212-
value: {
213-
key: new TextEncoder().encode(cryptoEncodedPubkey),
214-
},
215-
};
193+
const aminoValidator = Validator.toAmino(validator!.validator!);
216194

217-
console.log(
218-
JSON.stringify(
219-
{
220-
pubKeyString,
221-
cryptoEncodedPubkey,
222-
consensus_pubkey,
223-
isValidatorLoaded,
224-
isFetchingValidator,
225-
},
226-
null,
227-
2
228-
)
229-
);
230-
231-
//fromAmino
232-
const decodedAminoAny = consensus_pubkey;
233-
234-
const cryptoEncodedKeyString = new TextDecoder().decode(
235-
decodedAminoAny.value.key
236-
);
237-
238-
const cryptoDecodedPubkey = decodeBech32Pubkey(cryptoEncodedKeyString);
239-
240-
const consensusPubkey: {
241-
typeUrl: string;
242-
value: PubKey;
243-
} = {
244-
typeUrl: decodedAminoAny.type,
245-
value: {
246-
key: new TextEncoder().encode(cryptoDecodedPubkey.value),
247-
},
248-
};
195+
console.log(aminoValidator);
249196

250-
console.log(
251-
JSON.stringify(
252-
{
253-
cryptoEncodedKeyString,
254-
cryptoDecodedPubkey,
255-
consensusPubkey,
256-
},
257-
null,
258-
2
259-
)
260-
);
197+
const protoValidator = Validator.fromAmino(aminoValidator);
198+
199+
console.log(protoValidator);
261200
}
262201

263202
return (
@@ -311,7 +250,7 @@ export default function Home() {
311250
balance={
312251
isValidatorLoaded
313252
? Number(validator?.validator?.unbondingHeight)
314-
: ''
253+
: 0
315254
}
316255
isFetchingBalance={isFetchingValidator}
317256
response={resp}

examples/telescope/src/codegen/binary.ts

Lines changed: 88 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This file and any referenced files were automatically generated by @cosmology/telescope@0.104.0
2+
* This file and any referenced files were automatically generated by @cosmology/telescope@0.106.0
33
* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
44
* and run the transpile command or yarn proto command to regenerate this bundle.
55
*/
@@ -68,14 +68,38 @@ export enum WireType {
6868
}
6969

7070
// Reader
71+
export interface IBinaryReader {
72+
buf: Uint8Array;
73+
pos: number;
74+
type: number;
75+
len: number;
76+
tag(): [number, WireType, number];
77+
skip(length?: number): this;
78+
skipType(wireType: number): this;
79+
uint32(): number;
80+
int32(): number;
81+
sint32(): number;
82+
fixed32(): number;
83+
sfixed32(): number;
84+
int64(): bigint;
85+
uint64(): bigint;
86+
sint64(): bigint;
87+
fixed64(): bigint;
88+
sfixed64(): bigint;
89+
float(): number;
90+
double(): number;
91+
bool(): boolean;
92+
bytes(): Uint8Array;
93+
string(): string;
94+
}
7195

72-
export class BinaryReader {
96+
export class BinaryReader implements IBinaryReader {
7397
buf: Uint8Array;
7498
pos: number;
7599
type: number;
76100
len: number;
77101

78-
protected assertBounds(): void {
102+
assertBounds(): void {
79103
if (this.pos > this.len) throw new RangeError("premature EOF");
80104
}
81105

@@ -217,35 +241,73 @@ export class BinaryReader {
217241
}
218242

219243
// Writer
244+
export interface IBinaryWriter {
245+
len: number;
246+
head: IOp;
247+
tail: IOp;
248+
states: State | null;
249+
finish(): Uint8Array;
250+
fork(): IBinaryWriter;
251+
reset(): IBinaryWriter;
252+
ldelim(): IBinaryWriter;
253+
tag(fieldNo: number, type: WireType): IBinaryWriter;
254+
uint32(value: number): IBinaryWriter;
255+
int32(value: number): IBinaryWriter;
256+
sint32(value: number): IBinaryWriter;
257+
int64(value: string | number | bigint): IBinaryWriter;
258+
uint64: (value: string | number | bigint) => IBinaryWriter;
259+
sint64(value: string | number | bigint): IBinaryWriter;
260+
fixed64(value: string | number | bigint): IBinaryWriter;
261+
sfixed64: (value: string | number | bigint) => IBinaryWriter;
262+
bool(value: boolean): IBinaryWriter;
263+
fixed32(value: number): IBinaryWriter;
264+
sfixed32: (value: number) => IBinaryWriter;
265+
float(value: number): IBinaryWriter;
266+
double(value: number): IBinaryWriter;
267+
bytes(value: Uint8Array): IBinaryWriter;
268+
string(value: string): IBinaryWriter;
269+
}
220270

221-
type OpVal = string | number | object | Uint8Array;
271+
interface IOp {
272+
len: number;
273+
next?: IOp;
274+
proceed(buf: Uint8Array | number[], pos: number): void;
275+
}
222276

223-
class Op {
224-
fn?: (val: OpVal, buf: Uint8Array | number[], pos: number) => void;
277+
class Op<T> implements IOp {
278+
fn?: ((val: T, buf: Uint8Array | number[], pos: number) => void) | null;
225279
len: number;
226-
val: OpVal;
227-
next?: Op;
280+
val: T;
281+
next?: IOp;
228282

229283
constructor(
230-
fn: (
231-
val: OpVal,
232-
buf: Uint8Array | number[],
233-
pos: number
234-
) => void | undefined,
284+
fn:
285+
| ((
286+
val: T,
287+
buf: Uint8Array | number[],
288+
pos: number
289+
) => void | undefined | null)
290+
| null,
235291
len: number,
236-
val: OpVal
292+
val: T
237293
) {
238294
this.fn = fn;
239295
this.len = len;
240296
this.val = val;
241297
}
298+
299+
proceed(buf: Uint8Array | number[], pos: number) {
300+
if (this.fn) {
301+
this.fn(this.val, buf, pos);
302+
}
303+
}
242304
}
243305

244306
class State {
245-
head: Op;
246-
tail: Op;
307+
head: IOp;
308+
tail: IOp;
247309
len: number;
248-
next: State;
310+
next: State | null;
249311

250312
constructor(writer: BinaryWriter) {
251313
this.head = writer.head;
@@ -255,11 +317,11 @@ class State {
255317
}
256318
}
257319

258-
export class BinaryWriter {
320+
export class BinaryWriter implements IBinaryWriter {
259321
len = 0;
260-
head: Op;
261-
tail: Op;
262-
states: State;
322+
head: IOp;
323+
tail: IOp;
324+
states: State | null;
263325

264326
constructor() {
265327
this.head = new Op(null, 0, 0);
@@ -282,10 +344,10 @@ export class BinaryWriter {
282344
}
283345
}
284346

285-
private _push(
286-
fn: (val: OpVal, buf: Uint8Array | number[], pos: number) => void,
347+
private _push<T>(
348+
fn: (val: T, buf: Uint8Array | number[], pos: number) => void,
287349
len: number,
288-
val: OpVal
350+
val: T
289351
) {
290352
this.tail = this.tail.next = new Op(fn, len, val);
291353
this.len += len;
@@ -297,7 +359,7 @@ export class BinaryWriter {
297359
pos = 0;
298360
const buf = BinaryWriter.alloc(this.len);
299361
while (head) {
300-
head.fn(head.val, buf, pos);
362+
head.proceed(buf, pos);
301363
pos += head.len;
302364
head = head.next;
303365
}
@@ -444,7 +506,7 @@ function pool(
444506
): (size: number) => Uint8Array {
445507
const SIZE = size || 8192;
446508
const MAX = SIZE >>> 1;
447-
let slab = null;
509+
let slab: Uint8Array | null = null;
448510
let offset = SIZE;
449511
return function pool_alloc(size): Uint8Array {
450512
if (size < 1 || size > MAX) return alloc(size);

examples/telescope/src/codegen/cosmos/staking/v1beta1/staking.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import { Coin, CoinAmino, CoinSDKType } from "../../base/v1beta1/coin";
77
import { BinaryReader, BinaryWriter } from "../../../binary";
88
import { isSet, DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
99
import { Decimal } from "@cosmjs/math";
10-
import { toBase64, fromBase64 } from "@cosmjs/encoding";
11-
import { encodeBech32Pubkey, decodeBech32Pubkey } from "@cosmjs/amino";
10+
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
1211
/** BondStatus is the status of a validator. */
1312
export enum BondStatus {
1413
/** BOND_STATUS_UNSPECIFIED - UNSPECIFIED defines an invalid validator status. */
@@ -1482,16 +1481,13 @@ export const Validator = {
14821481
fromAmino(object: ValidatorAmino): Validator {
14831482
return {
14841483
operatorAddress: object.operator_address,
1485-
consensusPubkey: encodeBech32Pubkey({
1486-
type: "tendermint/PubKeySecp256k1",
1487-
value: toBase64(object.consensus_pubkey.value)
1488-
}, "cosmos"),
1484+
consensusPubkey: object?.consensus_pubkey ? encodePubkey(object.consensus_pubkey) : undefined,
14891485
jailed: object.jailed,
14901486
status: isSet(object.status) ? bondStatusFromJSON(object.status) : -1,
14911487
tokens: object.tokens,
14921488
delegatorShares: object.delegator_shares,
14931489
description: object?.description ? Description.fromAmino(object.description) : undefined,
1494-
unbondingHeight: BigInt(object.unbonding_height),
1490+
unbondingHeight: isSet(object.unbonding_height) ? BigInt(object.unbonding_height) : 0n,
14951491
unbondingTime: object.unbonding_time,
14961492
commission: object?.commission ? Commission.fromAmino(object.commission) : undefined,
14971493
minSelfDelegation: object.min_self_delegation
@@ -1500,10 +1496,7 @@ export const Validator = {
15001496
toAmino(message: Validator): ValidatorAmino {
15011497
const obj: any = {};
15021498
obj.operator_address = message.operatorAddress;
1503-
obj.consensus_pubkey = message.consensusPubkey ? {
1504-
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
1505-
value: fromBase64(decodeBech32Pubkey(message.consensusPubkey).value)
1506-
} : undefined;
1499+
obj.consensus_pubkey = message.consensusPubkey ? decodePubkey(message.consensusPubkey) : undefined;
15071500
obj.jailed = message.jailed;
15081501
obj.status = message.status;
15091502
obj.tokens = message.tokens;

examples/telescope/src/codegen/cosmos/staking/v1beta1/tx.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { Coin, CoinAmino, CoinSDKType } from "../../base/v1beta1/coin";
55
import { Timestamp } from "../../../google/protobuf/timestamp";
66
import { BinaryReader, BinaryWriter } from "../../../binary";
77
import { isSet, DeepPartial, toTimestamp, fromTimestamp } from "../../../helpers";
8-
import { toBase64, fromBase64 } from "@cosmjs/encoding";
9-
import { encodeBech32Pubkey, decodeBech32Pubkey } from "@cosmjs/amino";
8+
import { encodePubkey, decodePubkey } from "@cosmjs/proto-signing";
109
import { Decimal } from "@cosmjs/math";
1110
/** MsgCreateValidator defines a SDK message for creating a new validator. */
1211
export interface MsgCreateValidator {
@@ -412,10 +411,7 @@ export const MsgCreateValidator = {
412411
minSelfDelegation: object.min_self_delegation,
413412
delegatorAddress: object.delegator_address,
414413
validatorAddress: object.validator_address,
415-
pubkey: encodeBech32Pubkey({
416-
type: "tendermint/PubKeySecp256k1",
417-
value: toBase64(object.pubkey.value)
418-
}, "cosmos"),
414+
pubkey: object?.pubkey ? encodePubkey(object.pubkey) : undefined,
419415
value: object?.value ? Coin.fromAmino(object.value) : undefined
420416
};
421417
},
@@ -426,10 +422,7 @@ export const MsgCreateValidator = {
426422
obj.min_self_delegation = message.minSelfDelegation;
427423
obj.delegator_address = message.delegatorAddress;
428424
obj.validator_address = message.validatorAddress;
429-
obj.pubkey = message.pubkey ? {
430-
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
431-
value: fromBase64(decodeBech32Pubkey(message.pubkey).value)
432-
} : undefined;
425+
obj.pubkey = message.pubkey ? decodePubkey(message.pubkey) : undefined;
433426
obj.value = message.value ? Coin.toAmino(message.value) : undefined;
434427
return obj;
435428
},

examples/telescope/src/codegen/extern.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This file and any referenced files were automatically generated by @cosmology/telescope@0.104.0
2+
* This file and any referenced files were automatically generated by @cosmology/telescope@0.106.0
33
* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
44
* and run the transpile command or yarn proto command to regenerate this bundle.
55
*/

examples/telescope/src/codegen/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This file and any referenced files were automatically generated by @cosmology/telescope@0.104.0
2+
* This file and any referenced files were automatically generated by @cosmology/telescope@0.106.0
33
* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
44
* and run the transpile command or yarn proto command to regenerate this bundle.
55
*/

examples/telescope/src/codegen/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This file and any referenced files were automatically generated by @cosmology/telescope@0.104.0
2+
* This file and any referenced files were automatically generated by @cosmology/telescope@0.106.0
33
* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
44
* and run the transpile command or yarn proto command to regenerate this bundle.
55
*/

examples/telescope/src/codegen/mobx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* This file and any referenced files were automatically generated by @cosmology/telescope@0.104.0
2+
* This file and any referenced files were automatically generated by @cosmology/telescope@0.106.0
33
* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain
44
* and run the transpile command or yarn proto command to regenerate this bundle.
55
*/

0 commit comments

Comments
 (0)