Skip to content

Commit

Permalink
Remove long and use toFixed
Browse files Browse the repository at this point in the history
  • Loading branch information
joon9823 committed Nov 5, 2024
1 parent 381aba7 commit cb9e274
Show file tree
Hide file tree
Showing 96 changed files with 387 additions and 481 deletions.
1 change: 0 additions & 1 deletion package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"bip39": "^3.0.4",
"jscrypto": "^1.0.3",
"keccak256": "^1.0.6",
"long": "^5.2.0",
"ripemd160": "^2.0.2",
"secp256k1": "^5.0.0",
"semver": "^7.6.3",
Expand Down
2 changes: 1 addition & 1 deletion src/core/Coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class Coin extends JSONSerializable<Coin.Amino, Coin.Data, Coin.Proto> {
* Turns the Coin into an Integer coin.
*/
public toIntCoin(): Coin {
return new Coin(this.denom, num(this.amount).toFixed(0))
return new Coin(this.denom, num(this.amount).toFixed())
}

/**
Expand Down
12 changes: 7 additions & 5 deletions src/core/Duration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Duration as Duration_pb } from '@initia/initia.proto/google/protobuf/duration'
import Long from 'long'

/**
* A Duration represents a signed, fixed-length span of time represented
Expand All @@ -20,14 +19,14 @@ import Long from 'long'
* microsecond should be expressed in JSON format as "3.000001s".
*/
export class Duration {
public seconds: Long
public seconds: number
public nanos: number

constructor(seconds: number, nanos = 0) {
const [sec, nano] = (nanos / Math.pow(10, 9) + seconds)
.toFixed(9)
.split('.')
this.seconds = Long.fromString(sec)
this.seconds = parseInt(sec)
this.nanos = parseInt(nano)
}

Expand All @@ -37,7 +36,7 @@ export class Duration {
}

public toString(): string {
return `${this.nanos / Math.pow(10, 9) + this.seconds.toNumber()}s`
return `${this.nanos / Math.pow(10, 9) + this.seconds}s`
}

public static fromAmino(amino: Duration.Amino): Duration {
Expand All @@ -61,7 +60,10 @@ export class Duration {
}

public toProto(): Duration.Proto {
return { seconds: this.seconds, nanos: this.nanos }
return Duration_pb.fromPartial({
seconds: this.seconds,
nanos: this.nanos,
})
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/auction/AuctionParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class AuctionParams extends JSONSerializable<
return {
type: 'block-sdk/x/auction/Params',
value: {
max_bundle_size: max_bundle_size.toString(),
max_bundle_size: max_bundle_size.toFixed(),
escrow_account_address,
reserve_fee: reserve_fee.toAmino(),
min_bid_increment: min_bid_increment.toAmino(),
Expand Down Expand Up @@ -103,7 +103,7 @@ export class AuctionParams extends JSONSerializable<

return {
'@type': '/sdk.auction.v1.Params',
max_bundle_size: max_bundle_size.toString(),
max_bundle_size: max_bundle_size.toFixed(),
escrow_account_address,
reserve_fee: reserve_fee.toData(),
min_bid_increment: min_bid_increment.toData(),
Expand Down
31 changes: 15 additions & 16 deletions src/core/auth/AuthParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { JSONSerializable } from '../../util/json'
import { Params as Params_pb } from '@initia/initia.proto/cosmos/auth/v1beta1/auth'
import Long from 'long'

export class AuthParams extends JSONSerializable<
AuthParams.Amino,
Expand Down Expand Up @@ -56,11 +55,11 @@ export class AuthParams extends JSONSerializable<
return {
type: 'cosmos-sdk/x/auth/Params',
value: {
max_memo_characters: max_memo_characters.toString(),
tx_sig_limit: tx_sig_limit.toString(),
tx_size_cost_per_byte: tx_size_cost_per_byte.toString(),
sig_verify_cost_ed25519: sig_verify_cost_ed25519.toString(),
sig_verify_cost_secp256k1: sig_verify_cost_secp256k1.toString(),
max_memo_characters: max_memo_characters.toFixed(),
tx_sig_limit: tx_sig_limit.toFixed(),
tx_size_cost_per_byte: tx_size_cost_per_byte.toFixed(),
sig_verify_cost_ed25519: sig_verify_cost_ed25519.toFixed(),
sig_verify_cost_secp256k1: sig_verify_cost_secp256k1.toFixed(),
},
}
}
Expand Down Expand Up @@ -94,11 +93,11 @@ export class AuthParams extends JSONSerializable<

return {
'@type': '/cosmos.auth.v1beta1.Params',
max_memo_characters: max_memo_characters.toString(),
tx_sig_limit: tx_sig_limit.toString(),
tx_size_cost_per_byte: tx_size_cost_per_byte.toString(),
sig_verify_cost_ed25519: sig_verify_cost_ed25519.toString(),
sig_verify_cost_secp256k1: sig_verify_cost_secp256k1.toString(),
max_memo_characters: max_memo_characters.toFixed(),
tx_sig_limit: tx_sig_limit.toFixed(),
tx_size_cost_per_byte: tx_size_cost_per_byte.toFixed(),
sig_verify_cost_ed25519: sig_verify_cost_ed25519.toFixed(),
sig_verify_cost_secp256k1: sig_verify_cost_secp256k1.toFixed(),
}
}

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

return Params_pb.fromPartial({
maxMemoCharacters: Long.fromNumber(max_memo_characters),
txSigLimit: Long.fromNumber(tx_sig_limit),
txSizeCostPerByte: Long.fromNumber(tx_size_cost_per_byte),
sigVerifyCostEd25519: Long.fromNumber(sig_verify_cost_ed25519),
sigVerifyCostSecp256k1: Long.fromNumber(sig_verify_cost_secp256k1),
maxMemoCharacters: max_memo_characters,
txSigLimit: tx_sig_limit,
txSizeCostPerByte: tx_size_cost_per_byte,
sigVerifyCostEd25519: sig_verify_cost_ed25519,
sigVerifyCostSecp256k1: sig_verify_cost_secp256k1,
})
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/core/auth/BaseAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { JSONSerializable } from '../../util/json'
import { AccAddress } from '../bech32'
import { BaseAccount as BaseAccount_pb } from '@initia/initia.proto/cosmos/auth/v1beta1/auth'
import { Any } from '@initia/initia.proto/google/protobuf/any'
import Long from 'long'

/**
* Stores information about an account fetched from the blockchain.
Expand Down Expand Up @@ -96,8 +95,8 @@ export class BaseAccount extends JSONSerializable<
return BaseAccount_pb.fromPartial({
address,
pubKey: public_key?.packAny(),
accountNumber: Long.fromNumber(account_number),
sequence: Long.fromNumber(sequence),
accountNumber: account_number,
sequence,
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/bank/DenomUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class DenomUnit extends JSONSerializable<
const { denom, exponent, aliases } = this
return {
denom,
exponent: exponent.toString(),
exponent: exponent.toFixed(),
aliases,
}
}
Expand All @@ -43,7 +43,7 @@ export class DenomUnit extends JSONSerializable<
const { denom, exponent, aliases } = this
return {
denom,
exponent: exponent.toString(),
exponent: exponent.toFixed(),
aliases,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/celestia/Blob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export class Blob extends JSONSerializable<any, Blob.Data, Blob.Proto> {
return {
namespace_id,
data,
share_version: share_version.toString(),
namespace_version: namespace_version.toString(),
share_version: share_version.toFixed(),
namespace_version: namespace_version.toFixed(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/celestia/msgs/MsgPayForBlobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export class MsgPayForBlobs extends JSONSerializable<
'@type': '/celestia.blob.v1.MsgPayForBlobs',
signer,
namespaces,
blob_sizes: blob_sizes.map((size) => size.toString()),
blob_sizes: blob_sizes.map((size) => size.toFixed()),
share_commitments,
share_versions: share_versions.map((version) => version.toString()),
share_versions: share_versions.map((version) => version.toFixed()),
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/core/consensus/ABCIParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { JSONSerializable } from '../../util/json'
import { ABCIParams as ABCIParams_pb } from '@initia/initia.proto/tendermint/types/params'
import Long from 'long'

export class ABCIParams extends JSONSerializable<
ABCIParams.Amino,
Expand All @@ -21,7 +20,7 @@ export class ABCIParams extends JSONSerializable<
public toAmino(): ABCIParams.Amino {
return {
vote_extensions_enable_height:
this.vote_extensions_enable_height.toString(),
this.vote_extensions_enable_height.toFixed(),
}
}

Expand All @@ -32,7 +31,7 @@ export class ABCIParams extends JSONSerializable<
public toData(): ABCIParams.Data {
return {
vote_extensions_enable_height:
this.vote_extensions_enable_height.toString(),
this.vote_extensions_enable_height.toFixed(),
}
}

Expand All @@ -42,9 +41,7 @@ export class ABCIParams extends JSONSerializable<

public toProto(): ABCIParams.Proto {
return ABCIParams_pb.fromPartial({
voteExtensionsEnableHeight: Long.fromNumber(
this.vote_extensions_enable_height
),
voteExtensionsEnableHeight: this.vote_extensions_enable_height,
})
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/core/consensus/BlockParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { JSONSerializable } from '../../util/json'
import { BlockParams as BlockParams_pb } from '@initia/initia.proto/tendermint/types/params'
import Long from 'long'

export class BlockParams extends JSONSerializable<
BlockParams.Amino,
Expand All @@ -26,8 +25,8 @@ export class BlockParams extends JSONSerializable<
public toAmino(): BlockParams.Amino {
const { max_bytes, max_gas } = this
return {
max_bytes: max_bytes.toString(),
max_gas: max_gas.toString(),
max_bytes: max_bytes.toFixed(),
max_gas: max_gas.toFixed(),
}
}

Expand All @@ -39,8 +38,8 @@ export class BlockParams extends JSONSerializable<
public toData(): BlockParams.Data {
const { max_bytes, max_gas } = this
return {
max_bytes: max_bytes.toString(),
max_gas: max_gas.toString(),
max_bytes: max_bytes.toFixed(),
max_gas: max_gas.toFixed(),
}
}

Expand All @@ -51,8 +50,8 @@ export class BlockParams extends JSONSerializable<
public toProto(): BlockParams.Proto {
const { max_bytes, max_gas } = this
return BlockParams_pb.fromPartial({
maxBytes: Long.fromNumber(max_bytes),
maxGas: Long.fromNumber(max_gas),
maxBytes: max_bytes,
maxGas: max_gas,
})
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/core/consensus/EvidenceParams.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { JSONSerializable } from '../../util/json'
import { Duration } from '../Duration'
import { EvidenceParams as EvidenceParams_pb } from '@initia/initia.proto/tendermint/types/params'
import Long from 'long'

export class EvidenceParams extends JSONSerializable<
EvidenceParams.Amino,
Expand Down Expand Up @@ -33,9 +32,9 @@ export class EvidenceParams extends JSONSerializable<
public toAmino(): EvidenceParams.Amino {
const { max_age_num_blocks, max_age_duration, max_bytes } = this
return {
max_age_num_blocks: max_age_num_blocks.toString(),
max_age_num_blocks: max_age_num_blocks.toFixed(),
max_age_duration: max_age_duration.toAmino(),
max_bytes: max_bytes.toString(),
max_bytes: max_bytes.toFixed(),
}
}

Expand All @@ -51,9 +50,9 @@ export class EvidenceParams extends JSONSerializable<
public toData(): EvidenceParams.Data {
const { max_age_num_blocks, max_age_duration, max_bytes } = this
return {
max_age_num_blocks: max_age_num_blocks.toString(),
max_age_num_blocks: max_age_num_blocks.toFixed(),
max_age_duration: max_age_duration.toData(),
max_bytes: max_bytes.toString(),
max_bytes: max_bytes.toFixed(),
}
}

Expand All @@ -68,9 +67,9 @@ export class EvidenceParams extends JSONSerializable<
public toProto(): EvidenceParams.Proto {
const { max_age_num_blocks, max_age_duration, max_bytes } = this
return EvidenceParams_pb.fromPartial({
maxAgeNumBlocks: Long.fromNumber(max_age_num_blocks),
maxAgeNumBlocks: max_age_num_blocks,
maxAgeDuration: max_age_duration.toProto(),
maxBytes: Long.fromNumber(max_bytes),
maxBytes: max_bytes,
})
}
}
Expand Down
13 changes: 6 additions & 7 deletions src/core/evidence/Equivocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { JSONSerializable } from '../../util/json'
import { ValConsAddress } from '../bech32'
import { Equivocation as Equivocation_pb } from '@initia/initia.proto/cosmos/evidence/v1beta1/evidence'
import { Any } from '@initia/initia.proto/google/protobuf/any'
import Long from 'long'

export class Equivocation extends JSONSerializable<
Equivocation.Amino,
Expand Down Expand Up @@ -43,9 +42,9 @@ export class Equivocation extends JSONSerializable<
return {
type: 'cosmos-sdk/Equivocation',
value: {
height: height.toString(),
height: height.toFixed(),
time: time.toISOString(),
power: power.toString(),
power: power.toFixed(),
consensus_address,
},
}
Expand All @@ -67,9 +66,9 @@ export class Equivocation extends JSONSerializable<

return {
'@type': '/cosmos.evidence.v1beta1.Equivocation',
height: height.toString(),
height: height.toFixed(),
time: time.toISOString(),
power: power.toString(),
power: power.toFixed(),
consensus_address,
}
}
Expand All @@ -87,9 +86,9 @@ export class Equivocation extends JSONSerializable<
const { height, time, power, consensus_address } = this

return Equivocation_pb.fromPartial({
height: Long.fromNumber(height),
height,
time,
power: Long.fromNumber(power),
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 @@ -49,7 +49,7 @@ export class EvmParams extends JSONSerializable<
fee_denom,
} = this
return {
extra_eips: extra_eips.map((eip) => eip.toString()),
extra_eips: extra_eips.map((eip) => eip.toFixed()),
allowed_publishers,
allow_custom_erc20,
allowed_custom_erc20s,
Expand Down Expand Up @@ -83,7 +83,7 @@ export class EvmParams extends JSONSerializable<
fee_denom,
} = this
return {
extra_eips: extra_eips.map((eip) => eip.toString()),
extra_eips: extra_eips.map((eip) => eip.toFixed()),
allowed_publishers,
allow_custom_erc20,
allowed_custom_erc20s,
Expand Down
Loading

0 comments on commit cb9e274

Please sign in to comment.