Skip to content

Commit 834e01a

Browse files
committed
Merge branch 'fix/uint-3' into fix/test-cleanup-mar-23
2 parents c98e0f9 + 83ae96c commit 834e01a

File tree

13 files changed

+343
-312
lines changed

13 files changed

+343
-312
lines changed

packages/api/src/graphql/modules/QueryGraphqlModule.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
log,
4949
ModuleContainer,
5050
ModulesRecord,
51+
NonMethods,
5152
range,
5253
} from "@proto-kit/common";
5354
import { ObjMap } from "graphql/jsutils/ObjMap";
@@ -61,11 +62,6 @@ interface ProvableExtension<T, TJson = any> {
6162
fromJSON: (x: TJson) => T;
6263
}
6364

64-
type NonMethodKeys<Type> = {
65-
[Key in keyof Type]: Type[Key] extends Function ? never : Key;
66-
}[keyof Type];
67-
type NonMethods<Type> = Pick<Type, NonMethodKeys<Type>>;
68-
6965
interface AnyJson {
7066
[key: string]: any;
7167
}

packages/common/src/utils.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,20 @@ export function prefixToField(prefix: string): Field {
8686
}
8787

8888
export function hashWithPrefix(prefix: string, input: Field[]) {
89-
const salt = Poseidon.update([Field(0), Field(0), Field(0)], [prefixToField(prefix)])
90-
return Poseidon.update(salt as [Field, Field, Field], input)[0]
89+
const salt = Poseidon.update(
90+
[Field(0), Field(0), Field(0)],
91+
[prefixToField(prefix)]
92+
);
93+
return Poseidon.update(salt as [Field, Field, Field], input)[0];
9194
}
9295

9396
// end copy
9497

9598
export function expectDefined<T>(value: T | undefined): asserts value is T {
9699
expect(value).toBeDefined();
97-
}
100+
}
101+
102+
type NonMethodKeys<Type> = {
103+
[Key in keyof Type]: Type[Key] extends Function ? never : Key;
104+
}[keyof Type];
105+
export type NonMethods<Type> = Pick<Type, NonMethodKeys<Type>>;

packages/library/src/hooks/TransactionFeeHook.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class TransactionFeeHook extends ProvableTransactionHook<TransactionFeeHo
102102
new TokenId(this.config.tokenId),
103103
from.value,
104104
PublicKey.fromBase58(this.config.feeRecipient),
105-
Balance.from(fee.value)
105+
Balance.Unsafe.fromField(fee.value)
106106
);
107107
}
108108

@@ -136,12 +136,12 @@ export class TransactionFeeHook extends ProvableTransactionHook<TransactionFeeHo
136136
errors.invalidFeeConfigMethodId()
137137
);
138138

139-
const fee = UInt64.from(feeConfig.baseFee.value).add(
140-
UInt64.from(feeConfig.weight.value).mul(
141-
UInt64.from(feeConfig.perWeightUnitFee.value)
139+
const fee = UInt64.Unsafe.fromField(feeConfig.baseFee.value).add(
140+
UInt64.Unsafe.fromField(feeConfig.weight.value).mul(
141+
UInt64.Unsafe.fromField(feeConfig.perWeightUnitFee.value)
142142
)
143143
);
144144

145-
this.transferFee(executionData.transaction.sender, UInt64.from(fee.value));
145+
this.transferFee(executionData.transaction.sender, UInt64.Unsafe.fromField(fee.value));
146146
}
147147
}

packages/library/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export * from "./math/UInt32";
33
export * from "./math/UInt64";
44
export * from "./math/UInt112";
55
export * from "./math/UInt224";
6-
export * from "./math/PrecisionHelper";
76
export * from "./protocol/VanillaProtocolModules";
87
export * from "./runtime/Balances";
98
export * from "./runtime/VanillaRuntimeModules";

packages/library/src/math/PrecisionHelper.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

packages/library/src/math/Types.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { UInt } from "./UInt";
2+
3+
type AvailableBitLengths = 32 | 64 | 112 | 224;
4+
5+
type NextLowest<Input extends AvailableBitLengths> = Input extends 224
6+
? 112
7+
: Input extends 112
8+
? 64
9+
: Input extends 64
10+
? 32
11+
: never;
12+
13+
type RecursiveSmaller<Input extends AvailableBitLengths> =
14+
| Input
15+
| (NextLowest<Input> extends never
16+
? never
17+
: RecursiveSmaller<NextLowest<Input>>);
18+
19+
/**
20+
* Type to determine all possible bitlengths of UInts that would fit into
21+
* a given bitlength without doing additional rangechecks.
22+
* I.e. FittingUInt<112> = UIntX<32 | 64 | 112>
23+
*/
24+
export type FittingUInt<Input extends number> =
25+
Input extends AvailableBitLengths
26+
? UInt<RecursiveSmaller<Input>>
27+
: UInt<Input>;

0 commit comments

Comments
 (0)