Skip to content

Commit

Permalink
Merge pull request #96 from initia-labs/feat/bigint
Browse files Browse the repository at this point in the history
Change long to bigint
  • Loading branch information
Vritra4 authored Nov 15, 2024
2 parents caa4351 + b3b405c commit 80d666a
Show file tree
Hide file tree
Showing 90 changed files with 276 additions and 279 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
},
"dependencies": {
"@bitcoinerlab/secp256k1": "^1.1.1",
"@initia/initia.proto": "^0.2.3",
"@initia/opinit.proto": "^0.0.10",
"@initia/initia.proto": "^0.2.4",
"@initia/opinit.proto": "^0.0.11",
"@ledgerhq/hw-transport": "^6.31.4",
"@ledgerhq/hw-transport-webhid": "^6.29.4",
"@ledgerhq/hw-transport-webusb": "^6.29.4",
Expand Down
4 changes: 2 additions & 2 deletions src/core/Duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ export class Duration {
}

public static fromProto(proto: Duration.Proto): Duration {
return new Duration(proto.seconds.toNumber(), proto.nanos)
return new Duration(Number(proto.seconds), proto.nanos)
}

public toProto(): Duration.Proto {
return Duration_pb.fromPartial({
seconds: this.seconds,
seconds: BigInt(this.seconds),
nanos: this.nanos,
})
}
Expand Down
20 changes: 10 additions & 10 deletions src/core/auth/AuthParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ export class AuthParams extends JSONSerializable<

public static fromProto(data: AuthParams.Proto): AuthParams {
return new AuthParams(
data.maxMemoCharacters.toNumber(),
data.txSigLimit.toNumber(),
data.txSizeCostPerByte.toNumber(),
data.sigVerifyCostEd25519.toNumber(),
data.sigVerifyCostSecp256k1.toNumber()
Number(data.maxMemoCharacters),
Number(data.txSigLimit),
Number(data.txSizeCostPerByte),
Number(data.sigVerifyCostEd25519),
Number(data.sigVerifyCostSecp256k1)
)
}

Expand All @@ -124,11 +124,11 @@ export class AuthParams extends JSONSerializable<
} = this

return Params_pb.fromPartial({
maxMemoCharacters: max_memo_characters,
txSigLimit: tx_sig_limit,
txSizeCostPerByte: tx_size_cost_per_byte,
sigVerifyCostEd25519: sig_verify_cost_ed25519,
sigVerifyCostSecp256k1: sig_verify_cost_secp256k1,
maxMemoCharacters: BigInt(max_memo_characters),
txSigLimit: BigInt(tx_sig_limit),
txSizeCostPerByte: BigInt(tx_size_cost_per_byte),
sigVerifyCostEd25519: BigInt(sig_verify_cost_ed25519),
sigVerifyCostSecp256k1: BigInt(sig_verify_cost_secp256k1),
})
}
}
Expand Down
50 changes: 25 additions & 25 deletions src/core/auth/BaseAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ export class BaseAccount extends JSONSerializable<
return this.public_key
}

public toAmino(): BaseAccount.Amino {
const { address, public_key, account_number, sequence } = this
return {
type: 'cosmos-sdk/BaseAccount',
value: {
address,
public_key: public_key?.toAmino(),
account_number: account_number.toFixed(),
sequence: sequence.toFixed(),
},
}
}

public static fromAmino(data: BaseAccount.Amino): BaseAccount {
const {
value: { address, public_key, account_number, sequence },
Expand All @@ -66,6 +53,19 @@ export class BaseAccount extends JSONSerializable<
)
}

public toAmino(): BaseAccount.Amino {
const { address, public_key, account_number, sequence } = this
return {
type: 'cosmos-sdk/BaseAccount',
value: {
address,
public_key: public_key?.toAmino(),
account_number: account_number.toFixed(),
sequence: sequence.toFixed(),
},
}
}

public static fromData(data: BaseAccount.Data): BaseAccount {
const { address, pub_key, account_number, sequence } = data

Expand All @@ -88,26 +88,26 @@ export class BaseAccount extends JSONSerializable<
}
}

public toProto(): BaseAccount.Proto {
const { address, public_key, account_number, sequence } = this
return BaseAccount_pb.fromPartial({
address,
pubKey: public_key?.packAny(),
accountNumber: account_number,
sequence,
})
}

public static fromProto(baseAccountProto: BaseAccount.Proto): BaseAccount {
const pubkey = baseAccountProto.pubKey
return new BaseAccount(
baseAccountProto.address,
pubkey ? PublicKey.fromProto(pubkey) : undefined,
baseAccountProto.accountNumber.toNumber(),
baseAccountProto.sequence.toNumber()
Number(baseAccountProto.accountNumber),
Number(baseAccountProto.sequence)
)
}

public toProto(): BaseAccount.Proto {
const { address, public_key, account_number, sequence } = this
return BaseAccount_pb.fromPartial({
address,
pubKey: public_key?.packAny(),
accountNumber: BigInt(account_number),
sequence: BigInt(sequence),
})
}

public packAny(): Any {
return Any.fromPartial({
typeUrl: '/cosmos.auth.v1beta1.BaseAccount',
Expand Down
4 changes: 2 additions & 2 deletions src/core/consensus/ABCIParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export class ABCIParams extends JSONSerializable<
}

public static fromProto(data: ABCIParams.Proto): ABCIParams {
return new ABCIParams(data.voteExtensionsEnableHeight.toNumber())
return new ABCIParams(Number(data.voteExtensionsEnableHeight))
}

public toProto(): ABCIParams.Proto {
return ABCIParams_pb.fromPartial({
voteExtensionsEnableHeight: this.vote_extensions_enable_height,
voteExtensionsEnableHeight: BigInt(this.vote_extensions_enable_height),
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/core/consensus/BlockParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ export class BlockParams extends JSONSerializable<
}

public static fromProto(data: BlockParams.Proto): BlockParams {
return new BlockParams(data.maxBytes.toNumber(), data.maxGas.toNumber())
return new BlockParams(Number(data.maxBytes), Number(data.maxGas))
}

public toProto(): BlockParams.Proto {
const { max_bytes, max_gas } = this
return BlockParams_pb.fromPartial({
maxBytes: max_bytes,
maxGas: max_gas,
maxBytes: BigInt(max_bytes),
maxGas: BigInt(max_gas),
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/consensus/EvidenceParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,18 @@ export class EvidenceParams extends JSONSerializable<

public static fromProto(data: EvidenceParams.Proto): EvidenceParams {
return new EvidenceParams(
data.maxAgeNumBlocks.toNumber(),
Number(data.maxAgeNumBlocks),
Duration.fromProto(data.maxAgeDuration as Duration.Proto),
data.maxBytes.toNumber()
Number(data.maxBytes)
)
}

public toProto(): EvidenceParams.Proto {
const { max_age_num_blocks, max_age_duration, max_bytes } = this
return EvidenceParams_pb.fromPartial({
maxAgeNumBlocks: max_age_num_blocks,
maxAgeNumBlocks: BigInt(max_age_num_blocks),
maxAgeDuration: max_age_duration.toProto(),
maxBytes: max_bytes,
maxBytes: BigInt(max_bytes),
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/evidence/Equivocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ export class Equivocation extends JSONSerializable<

public static fromProto(data: Equivocation.Proto): Equivocation {
return new Equivocation(
data.height.toNumber(),
Number(data.height),
data.time as Date,
data.power.toNumber(),
Number(data.power),
data.consensusAddress
)
}
Expand All @@ -89,9 +89,9 @@ export class Equivocation extends JSONSerializable<
const { height, time, power, consensus_address } = this

return Equivocation_pb.fromPartial({
height,
height: BigInt(height),
time,
power,
power: BigInt(power),
consensusAddress: consensus_address,
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/evm/EvmParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class EvmParams extends JSONSerializable<

public static fromProto(proto: EvmParams.Proto): EvmParams {
return new EvmParams(
proto.extraEips.map((eip) => eip.toNumber()),
proto.extraEips.map((eip) => Number(eip)),
proto.allowedPublishers,
proto.allowCustomErc20,
proto.allowedCustomErc20s,
Expand All @@ -113,7 +113,7 @@ export class EvmParams extends JSONSerializable<
fee_denom,
} = this
return Params_pb.fromPartial({
extraEips: extra_eips,
extraEips: extra_eips.map((eip) => BigInt(eip)),
allowedPublishers: allowed_publishers,
allowCustomErc20: allow_custom_erc20,
allowedCustomErc20s: allowed_custom_erc20s,
Expand Down
9 changes: 2 additions & 7 deletions src/core/evm/msgs/MsgCreate2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,15 @@ export class MsgCreate2 extends JSONSerializable<
}

public static fromProto(data: MsgCreate2.Proto): MsgCreate2 {
return new MsgCreate2(
data.sender,
data.code,
data.salt.toNumber(),
data.value
)
return new MsgCreate2(data.sender, data.code, Number(data.salt), data.value)
}

public toProto(): MsgCreate2.Proto {
const { sender, code, salt, value } = this
return MsgCreate2_pb.fromPartial({
sender,
code,
salt,
salt: BigInt(salt),
value,
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/gov/Deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class Deposit extends JSONSerializable<

public static fromProto(data: Deposit.Proto): Deposit {
return new Deposit(
data.proposalId.toNumber(),
Number(data.proposalId),
data.depositor,
Coins.fromProto(data.amount)
)
Expand All @@ -69,7 +69,7 @@ export class Deposit extends JSONSerializable<
public toProto(): Deposit.Proto {
const { proposal_id, depositor, amount } = this
return Deposit_pb.fromPartial({
proposalId: proposal_id,
proposalId: BigInt(proposal_id),
depositor,
amount: amount.toProto(),
})
Expand Down
4 changes: 2 additions & 2 deletions src/core/gov/TallyResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class TallyResult extends JSONSerializable<

public static fromProto(data: TallyResult.Proto): TallyResult {
return new TallyResult(
data.tallyHeight.toNumber(),
Number(data.tallyHeight),
data.totalStakingPower,
data.totalVestingPower,
{
Expand All @@ -104,7 +104,7 @@ export class TallyResult extends JSONSerializable<
v1_tally_result,
} = this
return TallyResult_pb.fromPartial({
tallyHeight: tally_height,
tallyHeight: BigInt(tally_height),
totalStakingPower: total_staking_power,
totalVestingPower: total_vesting_power,
v1TallyResult: V1TallyResult_pb.fromPartial({
Expand Down
4 changes: 2 additions & 2 deletions src/core/gov/Vote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Vote extends JSONSerializable<Vote.Amino, Vote.Data, Vote.Proto> {

public static fromProto(proto: Vote.Proto): Vote {
return new Vote(
proto.proposalId.toNumber(),
Number(proto.proposalId),
proto.voter,
proto.options.map((o) => WeightedVoteOption.fromProto(o)),
proto.metadata
Expand All @@ -78,7 +78,7 @@ export class Vote extends JSONSerializable<Vote.Amino, Vote.Data, Vote.Proto> {
const { proposal_id, voter, options, metadata } = this
return Vote_pb.fromPartial({
options: options.map((o) => o.toProto()),
proposalId: proposal_id,
proposalId: BigInt(proposal_id),
voter,
metadata,
})
Expand Down
4 changes: 2 additions & 2 deletions src/core/gov/msgs/MsgCancelProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ export class MsgCancelProposal extends JSONSerializable<
}

public static fromProto(proto: MsgCancelProposal.Proto): MsgCancelProposal {
return new MsgCancelProposal(proto.proposalId.toNumber(), proto.proposer)
return new MsgCancelProposal(Number(proto.proposalId), proto.proposer)
}

public toProto(): MsgCancelProposal.Proto {
const { proposal_id, proposer } = this
return MsgCancelProposal_pb.fromPartial({
proposalId: proposal_id,
proposalId: BigInt(proposal_id),
proposer,
})
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/gov/msgs/MsgDeposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class MsgDeposit extends JSONSerializable<

public static fromProto(proto: MsgDeposit.Proto): MsgDeposit {
return new MsgDeposit(
proto.proposalId.toNumber(),
Number(proto.proposalId),
proto.depositor,
Coins.fromProto(proto.amount)
)
Expand All @@ -82,7 +82,7 @@ export class MsgDeposit extends JSONSerializable<
return MsgDeposit_pb.fromPartial({
amount: amount.toProto(),
depositor,
proposalId: proposal_id,
proposalId: BigInt(proposal_id),
})
}

Expand Down
Loading

0 comments on commit 80d666a

Please sign in to comment.