-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: bundle newly generated files when useAgoricDecimals is true.
- Loading branch information
Showing
29 changed files
with
14,253 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** | ||
* This file and any referenced files were automatically generated by @cosmology/telescope@latest | ||
* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain | ||
* and run the transpile command or npm scripts command that is used to regenerate this bundle. | ||
*/ | ||
|
||
|
||
// START agoric-sdk patch | ||
// The largest value we need is 18 (Ether). | ||
const maxFractionalDigits = 30; | ||
/** | ||
* A type for arbitrary precision, non-negative decimals. | ||
* | ||
* Instances of this class are immutable. | ||
*/ | ||
export class Decimal { | ||
public static fromUserInput( | ||
input: string, | ||
fractionalDigits: number | ||
): Decimal { | ||
Decimal.verifyFractionalDigits(fractionalDigits); | ||
const badCharacter = input.match(/[^0-9.]/); | ||
if (badCharacter) { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
throw new Error( | ||
`Invalid character at position ${badCharacter.index! + 1}` | ||
); | ||
} | ||
let whole: string; | ||
let fractional: string; | ||
if (input === "") { | ||
whole = "0"; | ||
fractional = ""; | ||
} else if (input.search(/\./) === -1) { | ||
// integer format, no separator | ||
whole = input; | ||
fractional = ""; | ||
} else { | ||
const parts = input.split("."); | ||
switch (parts.length) { | ||
case 0: | ||
case 1: | ||
throw new Error( | ||
"Fewer than two elements in split result. This must not happen here." | ||
); | ||
case 2: | ||
if (!parts[1]) throw new Error("Fractional part missing"); | ||
whole = parts[0]; | ||
fractional = parts[1].replace(/0+$/, ""); | ||
break; | ||
default: | ||
throw new Error("More than one separator found"); | ||
} | ||
} | ||
if (fractional.length > fractionalDigits) { | ||
throw new Error("Got more fractional digits than supported"); | ||
} | ||
const quantity = `${whole}${fractional.padEnd(fractionalDigits, "0")}`; | ||
return new Decimal(quantity, fractionalDigits); | ||
} | ||
public static fromAtomics( | ||
atomics: string, | ||
fractionalDigits: number | ||
): Decimal { | ||
Decimal.verifyFractionalDigits(fractionalDigits); | ||
return new Decimal(atomics, fractionalDigits); | ||
} | ||
private static verifyFractionalDigits(fractionalDigits: number): void { | ||
if (!Number.isInteger(fractionalDigits)) | ||
throw new Error("Fractional digits is not an integer"); | ||
if (fractionalDigits < 0) | ||
throw new Error("Fractional digits must not be negative"); | ||
if (fractionalDigits > maxFractionalDigits) { | ||
throw new Error( | ||
`Fractional digits must not exceed ${maxFractionalDigits}` | ||
); | ||
} | ||
} | ||
public get atomics(): string { | ||
return this.data.atomics.toString(); | ||
} | ||
public get fractionalDigits(): number { | ||
return this.data.fractionalDigits; | ||
} | ||
private readonly data: { | ||
readonly atomics: bigint; | ||
readonly fractionalDigits: number; | ||
}; | ||
private constructor(atomics: string, fractionalDigits: number) { | ||
if (!atomics.match(/^[0-9]+$/)) { | ||
throw new Error( | ||
"Invalid string format. Only non-negative integers in decimal representation supported." | ||
); | ||
} | ||
this.data = { | ||
atomics: BigInt(atomics), | ||
fractionalDigits: fractionalDigits, | ||
}; | ||
} | ||
public toString(): string { | ||
const factor = BigInt(10) ** BigInt(this.data.fractionalDigits); | ||
const whole = this.data.atomics / factor; | ||
const fractional = this.data.atomics % factor; | ||
if (fractional === 0n) { | ||
return whole.toString(); | ||
} else { | ||
const fullFractionalPart = fractional | ||
.toString() | ||
.padStart(this.data.fractionalDigits, "0"); | ||
const trimmedFractionalPart = fullFractionalPart.replace(/0+$/, ""); | ||
return `${whole.toString()}.${trimmedFractionalPart}`; | ||
} | ||
} | ||
} | ||
// END agoric-sdk patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* This file and any referenced files were automatically generated by @cosmology/telescope@latest | ||
* DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain | ||
* and run the transpile command or npm scripts command that is used to regenerate this bundle. | ||
*/ | ||
|
||
import { QueryClient, createProtobufRpcClient, ProtobufRpcClient } from '@cosmjs/stargate' | ||
import { Tendermint34Client, HttpEndpoint } from "@cosmjs/tendermint-rpc"; | ||
|
||
const _rpcClients: Record<string, ProtobufRpcClient> = {}; | ||
|
||
export const getRpcEndpointKey = (rpcEndpoint: string | HttpEndpoint) => { | ||
if (typeof rpcEndpoint === 'string') { | ||
return rpcEndpoint; | ||
} else if (!!rpcEndpoint) { | ||
//@ts-ignore | ||
return rpcEndpoint.url; | ||
} | ||
} | ||
|
||
export const getRpcClient = async (rpcEndpoint: string | HttpEndpoint) => { | ||
const key = getRpcEndpointKey(rpcEndpoint); | ||
if (!key) return; | ||
if (_rpcClients.hasOwnProperty(key)) { | ||
return _rpcClients[key]; | ||
} | ||
const tmClient = await Tendermint34Client.connect(rpcEndpoint); | ||
//@ts-ignore | ||
const client = new QueryClient(tmClient); | ||
const rpc = createProtobufRpcClient(client); | ||
_rpcClients[key] = rpc; | ||
return rpc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import * as _170 from "./gogo"; | ||
export const gogoproto = { | ||
..._170 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {} |
228 changes: 228 additions & 0 deletions
228
__fixtures__/misc/output-decimals/agoric/google/api/expr/v1alpha1/eval.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
import { BinaryReader, BinaryWriter } from "../../../../binary"; | ||
import { JsonSafe } from "../../../../json-safe"; | ||
import { DeepPartial, isSet } from "../../../../helpers"; | ||
export const protobufPackage = "google.api.expr.v1alpha1"; | ||
export interface ExprValue { | ||
/** The ids of the expressions with unknown values. */ | ||
exprs: IdRef[]; | ||
} | ||
export interface ExprValueProtoMsg { | ||
typeUrl: "/google.api.expr.v1alpha1.ExprValue"; | ||
value: Uint8Array; | ||
} | ||
export interface ExprValueAmino { | ||
/** The ids of the expressions with unknown values. */ | ||
exprs?: IdRefAmino[]; | ||
} | ||
export interface ExprValueAminoMsg { | ||
type: "/google.api.expr.v1alpha1.ExprValue"; | ||
value: ExprValueAmino; | ||
} | ||
export interface ExprValueSDKType { | ||
exprs: IdRefSDKType[]; | ||
} | ||
export interface IdRef { | ||
/** The expression id. */ | ||
id: number; | ||
} | ||
export interface IdRefProtoMsg { | ||
typeUrl: "/google.api.expr.v1alpha1.IdRef"; | ||
value: Uint8Array; | ||
} | ||
export interface IdRefAmino { | ||
/** The expression id. */ | ||
id?: number; | ||
} | ||
export interface IdRefAminoMsg { | ||
type: "/google.api.expr.v1alpha1.IdRef"; | ||
value: IdRefAmino; | ||
} | ||
export interface IdRefSDKType { | ||
id: number; | ||
} | ||
function createBaseExprValue(): ExprValue { | ||
return { | ||
exprs: [] | ||
}; | ||
} | ||
export const ExprValue = { | ||
typeUrl: "/google.api.expr.v1alpha1.ExprValue", | ||
encode(message: ExprValue, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { | ||
for (const v of message.exprs) { | ||
IdRef.encode(v!, writer.uint32(10).fork()).ldelim(); | ||
} | ||
return writer; | ||
}, | ||
decode(input: BinaryReader | Uint8Array, length?: number): ExprValue { | ||
const reader = input instanceof BinaryReader ? input : new BinaryReader(input); | ||
let end = length === undefined ? reader.len : reader.pos + length; | ||
const message = createBaseExprValue(); | ||
while (reader.pos < end) { | ||
const tag = reader.uint32(); | ||
switch (tag >>> 3) { | ||
case 1: | ||
message.exprs.push(IdRef.decode(reader, reader.uint32())); | ||
break; | ||
default: | ||
reader.skipType(tag & 7); | ||
break; | ||
} | ||
} | ||
return message; | ||
}, | ||
fromJSON(object: any): ExprValue { | ||
const obj = createBaseExprValue(); | ||
if (Array.isArray(object?.exprs)) obj.exprs = object.exprs.map((e: any) => IdRef.fromJSON(e)); | ||
return obj; | ||
}, | ||
toJSON(message: ExprValue): JsonSafe<ExprValue> { | ||
const obj: any = {}; | ||
if (message.exprs) { | ||
obj.exprs = message.exprs.map(e => e ? IdRef.toJSON(e) : undefined); | ||
} else { | ||
obj.exprs = []; | ||
} | ||
return obj; | ||
}, | ||
fromPartial(object: DeepPartial<ExprValue>): ExprValue { | ||
const message = createBaseExprValue(); | ||
message.exprs = object.exprs?.map(e => IdRef.fromPartial(e)) || []; | ||
return message; | ||
}, | ||
fromSDK(object: ExprValueSDKType): ExprValue { | ||
return { | ||
exprs: Array.isArray(object?.exprs) ? object.exprs.map((e: any) => IdRef.fromSDK(e)) : [] | ||
}; | ||
}, | ||
fromSDKJSON(object: any): ExprValueSDKType { | ||
return { | ||
exprs: Array.isArray(object?.exprs) ? object.exprs.map((e: any) => IdRef.fromSDKJSON(e)) : [] | ||
}; | ||
}, | ||
toSDK(message: ExprValue): ExprValueSDKType { | ||
const obj: any = {}; | ||
if (message.exprs) { | ||
obj.exprs = message.exprs.map(e => e ? IdRef.toSDK(e) : undefined); | ||
} else { | ||
obj.exprs = []; | ||
} | ||
return obj; | ||
}, | ||
fromAmino(object: ExprValueAmino): ExprValue { | ||
const message = createBaseExprValue(); | ||
message.exprs = object.exprs?.map(e => IdRef.fromAmino(e)) || []; | ||
return message; | ||
}, | ||
toAmino(message: ExprValue): ExprValueAmino { | ||
const obj: any = {}; | ||
if (message.exprs) { | ||
obj.exprs = message.exprs.map(e => e ? IdRef.toAmino(e) : undefined); | ||
} else { | ||
obj.exprs = message.exprs; | ||
} | ||
return obj; | ||
}, | ||
fromAminoMsg(object: ExprValueAminoMsg): ExprValue { | ||
return ExprValue.fromAmino(object.value); | ||
}, | ||
fromProtoMsg(message: ExprValueProtoMsg): ExprValue { | ||
return ExprValue.decode(message.value); | ||
}, | ||
toProto(message: ExprValue): Uint8Array { | ||
return ExprValue.encode(message).finish(); | ||
}, | ||
toProtoMsg(message: ExprValue): ExprValueProtoMsg { | ||
return { | ||
typeUrl: "/google.api.expr.v1alpha1.ExprValue", | ||
value: ExprValue.encode(message).finish() | ||
}; | ||
} | ||
}; | ||
function createBaseIdRef(): IdRef { | ||
return { | ||
id: 0 | ||
}; | ||
} | ||
export const IdRef = { | ||
typeUrl: "/google.api.expr.v1alpha1.IdRef", | ||
encode(message: IdRef, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter { | ||
if (message.id !== 0) { | ||
writer.uint32(8).int32(message.id); | ||
} | ||
return writer; | ||
}, | ||
decode(input: BinaryReader | Uint8Array, length?: number): IdRef { | ||
const reader = input instanceof BinaryReader ? input : new BinaryReader(input); | ||
let end = length === undefined ? reader.len : reader.pos + length; | ||
const message = createBaseIdRef(); | ||
while (reader.pos < end) { | ||
const tag = reader.uint32(); | ||
switch (tag >>> 3) { | ||
case 1: | ||
message.id = reader.int32(); | ||
break; | ||
default: | ||
reader.skipType(tag & 7); | ||
break; | ||
} | ||
} | ||
return message; | ||
}, | ||
fromJSON(object: any): IdRef { | ||
const obj = createBaseIdRef(); | ||
if (isSet(object.id)) obj.id = Number(object.id); | ||
return obj; | ||
}, | ||
toJSON(message: IdRef): JsonSafe<IdRef> { | ||
const obj: any = {}; | ||
message.id !== undefined && (obj.id = Math.round(message.id)); | ||
return obj; | ||
}, | ||
fromPartial(object: DeepPartial<IdRef>): IdRef { | ||
const message = createBaseIdRef(); | ||
message.id = object.id ?? 0; | ||
return message; | ||
}, | ||
fromSDK(object: IdRefSDKType): IdRef { | ||
return { | ||
id: object?.id | ||
}; | ||
}, | ||
fromSDKJSON(object: any): IdRefSDKType { | ||
return { | ||
id: isSet(object.id) ? Number(object.id) : 0 | ||
}; | ||
}, | ||
toSDK(message: IdRef): IdRefSDKType { | ||
const obj: any = {}; | ||
obj.id = message.id; | ||
return obj; | ||
}, | ||
fromAmino(object: IdRefAmino): IdRef { | ||
const message = createBaseIdRef(); | ||
if (object.id !== undefined && object.id !== null) { | ||
message.id = object.id; | ||
} | ||
return message; | ||
}, | ||
toAmino(message: IdRef): IdRefAmino { | ||
const obj: any = {}; | ||
obj.id = message.id === 0 ? undefined : message.id; | ||
return obj; | ||
}, | ||
fromAminoMsg(object: IdRefAminoMsg): IdRef { | ||
return IdRef.fromAmino(object.value); | ||
}, | ||
fromProtoMsg(message: IdRefProtoMsg): IdRef { | ||
return IdRef.decode(message.value); | ||
}, | ||
toProto(message: IdRef): Uint8Array { | ||
return IdRef.encode(message).finish(); | ||
}, | ||
toProtoMsg(message: IdRef): IdRefProtoMsg { | ||
return { | ||
typeUrl: "/google.api.expr.v1alpha1.IdRef", | ||
value: IdRef.encode(message).finish() | ||
}; | ||
} | ||
}; |
Oops, something went wrong.