@alephium/web3 0.5.0-rc.17 → 0.5.0-rc.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/contract/contract.js +6 -6
- package/dist/src/index.js +0 -3
- package/dist/src/signer/signer.js +1 -1
- package/dist/src/utils/number.d.ts +2 -0
- package/dist/src/utils/number.js +29 -1
- package/package.json +1 -1
- package/src/contract/contract.ts +9 -7
- package/src/index.ts +0 -4
- package/src/signer/signer.ts +1 -1
- package/src/utils/number.ts +34 -0
|
@@ -140,7 +140,7 @@ class ProjectArtifact {
|
|
|
140
140
|
compilerOptionsUsed: this.compilerOptionsUsed,
|
|
141
141
|
infos: Object.fromEntries(new Map([...this.infos].sort()))
|
|
142
142
|
};
|
|
143
|
-
const content =
|
|
143
|
+
const content = (0, utils_1.stringifyJsonWithBigint)(artifact, 2);
|
|
144
144
|
return fs_2.promises.writeFile(filepath, content);
|
|
145
145
|
}
|
|
146
146
|
needToReCompile(compilerOptions, sourceInfos) {
|
|
@@ -169,7 +169,7 @@ class ProjectArtifact {
|
|
|
169
169
|
return undefined;
|
|
170
170
|
}
|
|
171
171
|
const content = await fs_2.promises.readFile(filepath);
|
|
172
|
-
const json =
|
|
172
|
+
const json = (0, utils_1.parseJsonWithBigint)(content.toString());
|
|
173
173
|
const compilerOptionsUsed = json.compilerOptionsUsed;
|
|
174
174
|
const files = new Map(Object.entries(json.infos));
|
|
175
175
|
return new ProjectArtifact(compilerOptionsUsed, files);
|
|
@@ -480,7 +480,7 @@ class Contract extends Artifact {
|
|
|
480
480
|
// support both 'code.ral' and 'code.ral.json'
|
|
481
481
|
static async fromArtifactFile(path, bytecodeDebugPatch, codeHashDebug) {
|
|
482
482
|
const content = await fs_2.promises.readFile(path);
|
|
483
|
-
const artifact =
|
|
483
|
+
const artifact = (0, utils_1.parseJsonWithBigint)(content.toString());
|
|
484
484
|
return Contract.fromJson(artifact, bytecodeDebugPatch, codeHashDebug);
|
|
485
485
|
}
|
|
486
486
|
toString() {
|
|
@@ -493,7 +493,7 @@ class Contract extends Artifact {
|
|
|
493
493
|
eventsSig: this.eventsSig,
|
|
494
494
|
functions: this.functions
|
|
495
495
|
};
|
|
496
|
-
return
|
|
496
|
+
return (0, utils_1.stringifyJsonWithBigint)(object, 2);
|
|
497
497
|
}
|
|
498
498
|
toState(fields, asset, address) {
|
|
499
499
|
const addressDef = typeof address !== 'undefined' ? address : Contract.randomAddress();
|
|
@@ -718,7 +718,7 @@ class Script extends Artifact {
|
|
|
718
718
|
}
|
|
719
719
|
static async fromArtifactFile(path, bytecodeDebugPatch) {
|
|
720
720
|
const content = await fs_2.promises.readFile(path);
|
|
721
|
-
const artifact =
|
|
721
|
+
const artifact = (0, utils_1.parseJsonWithBigint)(content.toString());
|
|
722
722
|
return this.fromJson(artifact, bytecodeDebugPatch);
|
|
723
723
|
}
|
|
724
724
|
toString() {
|
|
@@ -729,7 +729,7 @@ class Script extends Artifact {
|
|
|
729
729
|
fieldsSig: this.fieldsSig,
|
|
730
730
|
functions: this.functions
|
|
731
731
|
};
|
|
732
|
-
return
|
|
732
|
+
return (0, utils_1.stringifyJsonWithBigint)(object, 2);
|
|
733
733
|
}
|
|
734
734
|
async txParamsForExecution(signer, params) {
|
|
735
735
|
const selectedAccount = await signer.getSelectedAccount();
|
package/dist/src/index.js
CHANGED
|
@@ -44,9 +44,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
46
|
exports.utils = exports.web3 = void 0;
|
|
47
|
-
BigInt.prototype['toJSON'] = function () {
|
|
48
|
-
return this.toString();
|
|
49
|
-
};
|
|
50
47
|
__exportStar(require("./api"), exports);
|
|
51
48
|
__exportStar(require("./contract"), exports);
|
|
52
49
|
__exportStar(require("./signer"), exports);
|
|
@@ -61,7 +61,7 @@ class SignerProvider {
|
|
|
61
61
|
const derivedAddress = (0, utils_1.addressFromPublicKey)(account.publicKey, account.keyType);
|
|
62
62
|
const derivedGroup = (0, utils_1.groupOfAddress)(derivedAddress);
|
|
63
63
|
if (derivedAddress !== account.address || derivedGroup !== account.group) {
|
|
64
|
-
throw Error(`Invalid
|
|
64
|
+
throw Error(`Invalid account data: ${JSON.stringify(account)}`);
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -14,3 +14,5 @@ export declare function prettifyExactAmount(amount: bigint, decimals: number): s
|
|
|
14
14
|
export declare function prettifyNumber(amount: bigint, decimals: number, config: IPrettifyNumberConfig): string | undefined;
|
|
15
15
|
export declare function convertAmountWithDecimals(amount: string | number, decimals: number): bigint | undefined;
|
|
16
16
|
export declare function convertAlphAmount(amount: string | number): bigint | undefined;
|
|
17
|
+
export declare function stringifyJsonWithBigint(obj: any, space?: string | number): string;
|
|
18
|
+
export declare function parseJsonWithBigint(text: string): any;
|
package/dist/src/utils/number.js
CHANGED
|
@@ -20,7 +20,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
20
20
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.convertAlphAmount = exports.convertAmountWithDecimals = exports.prettifyNumber = exports.prettifyExactAmount = exports.prettifyTokenAmount = exports.prettifyAttoAlphAmount = exports.prettifyNumberConfig = exports.isNumeric = void 0;
|
|
23
|
+
exports.parseJsonWithBigint = exports.stringifyJsonWithBigint = exports.convertAlphAmount = exports.convertAmountWithDecimals = exports.prettifyNumber = exports.prettifyExactAmount = exports.prettifyTokenAmount = exports.prettifyAttoAlphAmount = exports.prettifyNumberConfig = exports.isNumeric = void 0;
|
|
24
24
|
// Credits:
|
|
25
25
|
// 1. https://github.com/argentlabs/argent-x/blob/e63affa7f28b27333dca4081a3dcd375bb2da40b/packages/extension/src/shared/utils/number.ts
|
|
26
26
|
// 2. https://github.com/ethers-io/ethers.js/blob/724881f34d428406488a1c9f9dbebe54b6edecda/src.ts/utils/fixednumber.ts
|
|
@@ -142,3 +142,31 @@ function convertAlphAmount(amount) {
|
|
|
142
142
|
return convertAmountWithDecimals(amount, 18);
|
|
143
143
|
}
|
|
144
144
|
exports.convertAlphAmount = convertAlphAmount;
|
|
145
|
+
function replacer(key, value) {
|
|
146
|
+
if (typeof value === 'bigint') {
|
|
147
|
+
return { __bigintval__: value.toString() };
|
|
148
|
+
}
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
function reviver(key, value) {
|
|
152
|
+
if (value != null && typeof value === 'object' && '__bigintval__' in value) {
|
|
153
|
+
return BigInt(value['__bigintval__']);
|
|
154
|
+
}
|
|
155
|
+
return value;
|
|
156
|
+
}
|
|
157
|
+
function stringifyJsonWithBigint(obj, space) {
|
|
158
|
+
const bigintToString = BigInt.prototype['toJSON'];
|
|
159
|
+
BigInt.prototype['toJSON'] = undefined;
|
|
160
|
+
const result = JSON.stringify(obj, replacer, space);
|
|
161
|
+
BigInt.prototype['toJSON'] = bigintToString;
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
exports.stringifyJsonWithBigint = stringifyJsonWithBigint;
|
|
165
|
+
function parseJsonWithBigint(text) {
|
|
166
|
+
const bigintToString = BigInt.prototype['toJSON'];
|
|
167
|
+
BigInt.prototype['toJSON'] = undefined;
|
|
168
|
+
const result = JSON.parse(text, reviver);
|
|
169
|
+
BigInt.prototype['toJSON'] = bigintToString;
|
|
170
|
+
return result;
|
|
171
|
+
}
|
|
172
|
+
exports.parseJsonWithBigint = parseJsonWithBigint;
|
package/package.json
CHANGED
package/src/contract/contract.ts
CHANGED
|
@@ -54,7 +54,9 @@ import {
|
|
|
54
54
|
Eq,
|
|
55
55
|
Optional,
|
|
56
56
|
groupOfAddress,
|
|
57
|
-
addressFromContractId
|
|
57
|
+
addressFromContractId,
|
|
58
|
+
stringifyJsonWithBigint,
|
|
59
|
+
parseJsonWithBigint
|
|
58
60
|
} from '../utils'
|
|
59
61
|
import { getCurrentNodeProvider } from '../global'
|
|
60
62
|
import * as path from 'path'
|
|
@@ -207,7 +209,7 @@ class ProjectArtifact {
|
|
|
207
209
|
compilerOptionsUsed: this.compilerOptionsUsed,
|
|
208
210
|
infos: Object.fromEntries(new Map([...this.infos].sort()))
|
|
209
211
|
}
|
|
210
|
-
const content =
|
|
212
|
+
const content = stringifyJsonWithBigint(artifact, 2)
|
|
211
213
|
return fsPromises.writeFile(filepath, content)
|
|
212
214
|
}
|
|
213
215
|
|
|
@@ -241,7 +243,7 @@ class ProjectArtifact {
|
|
|
241
243
|
return undefined
|
|
242
244
|
}
|
|
243
245
|
const content = await fsPromises.readFile(filepath)
|
|
244
|
-
const json =
|
|
246
|
+
const json = parseJsonWithBigint(content.toString())
|
|
245
247
|
const compilerOptionsUsed = json.compilerOptionsUsed as node.CompilerOptions
|
|
246
248
|
const files = new Map(Object.entries<CodeInfo>(json.infos))
|
|
247
249
|
return new ProjectArtifact(compilerOptionsUsed, files)
|
|
@@ -737,7 +739,7 @@ export class Contract extends Artifact {
|
|
|
737
739
|
// support both 'code.ral' and 'code.ral.json'
|
|
738
740
|
static async fromArtifactFile(path: string, bytecodeDebugPatch: string, codeHashDebug: string): Promise<Contract> {
|
|
739
741
|
const content = await fsPromises.readFile(path)
|
|
740
|
-
const artifact =
|
|
742
|
+
const artifact = parseJsonWithBigint(content.toString())
|
|
741
743
|
return Contract.fromJson(artifact, bytecodeDebugPatch, codeHashDebug)
|
|
742
744
|
}
|
|
743
745
|
|
|
@@ -751,7 +753,7 @@ export class Contract extends Artifact {
|
|
|
751
753
|
eventsSig: this.eventsSig,
|
|
752
754
|
functions: this.functions
|
|
753
755
|
}
|
|
754
|
-
return
|
|
756
|
+
return stringifyJsonWithBigint(object, 2)
|
|
755
757
|
}
|
|
756
758
|
|
|
757
759
|
toState<T extends Fields>(fields: T, asset: Asset, address?: string): ContractState<T> {
|
|
@@ -1047,7 +1049,7 @@ export class Script extends Artifact {
|
|
|
1047
1049
|
|
|
1048
1050
|
static async fromArtifactFile(path: string, bytecodeDebugPatch: string): Promise<Script> {
|
|
1049
1051
|
const content = await fsPromises.readFile(path)
|
|
1050
|
-
const artifact =
|
|
1052
|
+
const artifact = parseJsonWithBigint(content.toString())
|
|
1051
1053
|
return this.fromJson(artifact, bytecodeDebugPatch)
|
|
1052
1054
|
}
|
|
1053
1055
|
|
|
@@ -1059,7 +1061,7 @@ export class Script extends Artifact {
|
|
|
1059
1061
|
fieldsSig: this.fieldsSig,
|
|
1060
1062
|
functions: this.functions
|
|
1061
1063
|
}
|
|
1062
|
-
return
|
|
1064
|
+
return stringifyJsonWithBigint(object, 2)
|
|
1063
1065
|
}
|
|
1064
1066
|
|
|
1065
1067
|
async txParamsForExecution<P extends Fields>(
|
package/src/index.ts
CHANGED
|
@@ -16,10 +16,6 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
16
16
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
BigInt.prototype['toJSON'] = function () {
|
|
20
|
-
return this.toString()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
19
|
export * from './api'
|
|
24
20
|
export * from './contract'
|
|
25
21
|
export * from './signer'
|
package/src/signer/signer.ts
CHANGED
|
@@ -61,7 +61,7 @@ export abstract class SignerProvider {
|
|
|
61
61
|
const derivedAddress = addressFromPublicKey(account.publicKey, account.keyType)
|
|
62
62
|
const derivedGroup = groupOfAddress(derivedAddress)
|
|
63
63
|
if (derivedAddress !== account.address || derivedGroup !== account.group) {
|
|
64
|
-
throw Error(`Invalid
|
|
64
|
+
throw Error(`Invalid account data: ${JSON.stringify(account)}`)
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
package/src/utils/number.ts
CHANGED
|
@@ -155,3 +155,37 @@ export function convertAmountWithDecimals(amount: string | number, decimals: num
|
|
|
155
155
|
export function convertAlphAmount(amount: string | number): bigint | undefined {
|
|
156
156
|
return convertAmountWithDecimals(amount, 18)
|
|
157
157
|
}
|
|
158
|
+
|
|
159
|
+
function replacer(key: string, value: any): any {
|
|
160
|
+
if (typeof value === 'bigint') {
|
|
161
|
+
return { __bigintval__: value.toString() }
|
|
162
|
+
}
|
|
163
|
+
return value
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function reviver(key: string, value: any): any {
|
|
167
|
+
if (value != null && typeof value === 'object' && '__bigintval__' in value) {
|
|
168
|
+
return BigInt(value['__bigintval__'])
|
|
169
|
+
}
|
|
170
|
+
return value
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function stringifyJsonWithBigint(obj: any, space?: string | number): string {
|
|
174
|
+
const bigintToString = BigInt.prototype['toJSON']
|
|
175
|
+
BigInt.prototype['toJSON'] = undefined
|
|
176
|
+
|
|
177
|
+
const result = JSON.stringify(obj, replacer, space)
|
|
178
|
+
|
|
179
|
+
BigInt.prototype['toJSON'] = bigintToString
|
|
180
|
+
return result
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function parseJsonWithBigint(text: string): any {
|
|
184
|
+
const bigintToString = BigInt.prototype['toJSON']
|
|
185
|
+
BigInt.prototype['toJSON'] = undefined
|
|
186
|
+
|
|
187
|
+
const result = JSON.parse(text, reviver)
|
|
188
|
+
|
|
189
|
+
BigInt.prototype['toJSON'] = bigintToString
|
|
190
|
+
return result
|
|
191
|
+
}
|