@alephium/web3 0.2.0-rc.34 → 0.2.0-rc.35

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.
@@ -1,5 +1,5 @@
1
1
  import * as node from './api-alephium';
2
- export declare type Number256 = number | bigint | string;
2
+ export declare type Number256 = bigint;
3
3
  export declare type Val = Number256 | boolean | string | Val[];
4
4
  export declare type NamedVals = Record<string, Val>;
5
5
  export interface Token {
@@ -13,7 +13,7 @@ export declare function fromApiTokens(tokens?: node.Token[]): Token[] | undefine
13
13
  export declare function toApiBoolean(v: Val): boolean;
14
14
  export declare function toApiNumber256(v: Val): string;
15
15
  export declare function toApiNumber256Optional(v?: Val): string | undefined;
16
- export declare function fromApiNumber256(n: string): Number256;
16
+ export declare function fromApiNumber256(n: string): bigint;
17
17
  export declare function toApiByteVec(v: Val): string;
18
18
  export declare function toApiAddress(v: Val): string;
19
19
  export declare function toApiArray(tpe: string, v: Val): node.Val;
@@ -63,12 +63,7 @@ function toApiNumber256Optional(v) {
63
63
  }
64
64
  exports.toApiNumber256Optional = toApiNumber256Optional;
65
65
  function fromApiNumber256(n) {
66
- if (Number.isSafeInteger(Number.parseInt(n))) {
67
- return Number(n);
68
- }
69
- else {
70
- return BigInt(n);
71
- }
66
+ return BigInt(n);
72
67
  }
73
68
  exports.fromApiNumber256 = fromApiNumber256;
74
69
  // TODO: check hex string
@@ -213,7 +213,7 @@ export interface DeployContractTransaction {
213
213
  export interface BuildDeployContractTx {
214
214
  signerAddress: string;
215
215
  initialFields?: Fields;
216
- initialAttoAlphAmount?: string;
216
+ initialAttoAlphAmount?: Number256;
217
217
  initialTokenAmounts?: Token[];
218
218
  issueTokenAmount?: Number256;
219
219
  gasAmount?: number;
@@ -587,11 +587,11 @@ class Contract extends Artifact {
587
587
  const signerParams = {
588
588
  signerAddress: (await signer.getSelectedAccount()).address,
589
589
  bytecode: bytecode,
590
- initialAttoAlphAmount: extractOptionalNumber256(params.initialAttoAlphAmount),
591
- issueTokenAmount: extractOptionalNumber256(params.issueTokenAmount),
592
- initialTokenAmounts: (0, api_1.toApiTokens)(params.initialTokenAmounts),
590
+ initialAttoAlphAmount: params.initialAttoAlphAmount,
591
+ issueTokenAmount: params.issueTokenAmount,
592
+ initialTokenAmounts: params.initialTokenAmounts,
593
593
  gasAmount: params.gasAmount,
594
- gasPrice: extractOptionalNumber256(params.gasPrice)
594
+ gasPrice: params.gasPrice
595
595
  };
596
596
  return signerParams;
597
597
  }
@@ -652,10 +652,10 @@ class Script extends Artifact {
652
652
  const signerParams = {
653
653
  signerAddress: (await signer.getSelectedAccount()).address,
654
654
  bytecode: this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {}),
655
- attoAlphAmount: extractOptionalNumber256(params.attoAlphAmount),
656
- tokens: (0, api_1.toApiTokens)(params.tokens),
655
+ attoAlphAmount: params.attoAlphAmount,
656
+ tokens: params.tokens,
657
657
  gasAmount: params.gasAmount,
658
- gasPrice: extractOptionalNumber256(params.gasPrice)
658
+ gasPrice: params.gasPrice
659
659
  };
660
660
  return signerParams;
661
661
  }
@@ -668,9 +668,6 @@ class Script extends Artifact {
668
668
  }
669
669
  }
670
670
  exports.Script = Script;
671
- function extractOptionalNumber256(v) {
672
- return typeof v !== 'undefined' ? (0, api_1.toApiNumber256)(v) : undefined;
673
- }
674
671
  function fromApiFields(vals, fieldsSig) {
675
672
  return (0, api_1.fromApiVals)(vals, fieldsSig.names, fieldsSig.types);
676
673
  }
@@ -48,10 +48,10 @@ export interface SignDeployContractTxResult {
48
48
  export interface SignExecuteScriptTxParams {
49
49
  signerAddress: string;
50
50
  bytecode: string;
51
- attoAlphAmount?: string;
51
+ attoAlphAmount?: Number256;
52
52
  tokens?: Token[];
53
53
  gasAmount?: number;
54
- gasPrice?: string;
54
+ gasPrice?: Number256;
55
55
  }
56
56
  export interface SignExecuteScriptTxResult {
57
57
  fromGroup: number;
@@ -137,7 +137,9 @@ class SignerProviderSimple {
137
137
  async buildScriptTx(params) {
138
138
  const data = {
139
139
  ...(await this.usePublicKey(params)),
140
- tokens: (0, api_1.toApiTokens)(params.tokens)
140
+ attoAlphAmount: (0, api_1.toApiNumber256Optional)(params.attoAlphAmount),
141
+ tokens: (0, api_1.toApiTokens)(params.tokens),
142
+ gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
141
143
  };
142
144
  return this.getNodeProvider().contracts.postContractsUnsignedTxExecuteScript(data);
143
145
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.2.0-rc.34",
3
+ "version": "0.2.0-rc.35",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
package/src/api/types.ts CHANGED
@@ -19,7 +19,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
19
19
  import { assertType, bs58, Eq } from '../utils'
20
20
  import * as node from './api-alephium'
21
21
 
22
- export type Number256 = number | bigint | string
22
+ export type Number256 = bigint
23
23
  export type Val = Number256 | boolean | string | Val[]
24
24
  export type NamedVals = Record<string, Val>
25
25
 
@@ -68,12 +68,8 @@ export function toApiNumber256Optional(v?: Val): string | undefined {
68
68
  return v === undefined ? undefined : toApiNumber256(v)
69
69
  }
70
70
 
71
- export function fromApiNumber256(n: string): Number256 {
72
- if (Number.isSafeInteger(Number.parseInt(n))) {
73
- return Number(n)
74
- } else {
75
- return BigInt(n)
76
- }
71
+ export function fromApiNumber256(n: string): bigint {
72
+ return BigInt(n)
77
73
  }
78
74
 
79
75
  // TODO: check hex string
@@ -32,7 +32,6 @@ import {
32
32
  toApiVal,
33
33
  Token,
34
34
  Val,
35
- toApiTokens,
36
35
  fromApiTokens,
37
36
  fromApiVals
38
37
  } from '../api'
@@ -816,11 +815,11 @@ export class Contract extends Artifact {
816
815
  const signerParams: SignDeployContractTxParams = {
817
816
  signerAddress: (await signer.getSelectedAccount()).address,
818
817
  bytecode: bytecode,
819
- initialAttoAlphAmount: extractOptionalNumber256(params.initialAttoAlphAmount),
820
- issueTokenAmount: extractOptionalNumber256(params.issueTokenAmount),
821
- initialTokenAmounts: toApiTokens(params.initialTokenAmounts),
818
+ initialAttoAlphAmount: params.initialAttoAlphAmount,
819
+ issueTokenAmount: params.issueTokenAmount,
820
+ initialTokenAmounts: params.initialTokenAmounts,
822
821
  gasAmount: params.gasAmount,
823
- gasPrice: extractOptionalNumber256(params.gasPrice)
822
+ gasPrice: params.gasPrice
824
823
  }
825
824
  return signerParams
826
825
  }
@@ -902,10 +901,10 @@ export class Script extends Artifact {
902
901
  const signerParams: SignExecuteScriptTxParams = {
903
902
  signerAddress: (await signer.getSelectedAccount()).address,
904
903
  bytecode: this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {}),
905
- attoAlphAmount: extractOptionalNumber256(params.attoAlphAmount),
906
- tokens: toApiTokens(params.tokens),
904
+ attoAlphAmount: params.attoAlphAmount,
905
+ tokens: params.tokens,
907
906
  gasAmount: params.gasAmount,
908
- gasPrice: extractOptionalNumber256(params.gasPrice)
907
+ gasPrice: params.gasPrice
909
908
  }
910
909
  return signerParams
911
910
  }
@@ -923,10 +922,6 @@ export class Script extends Artifact {
923
922
  }
924
923
  }
925
924
 
926
- function extractOptionalNumber256(v?: Val): string | undefined {
927
- return typeof v !== 'undefined' ? toApiNumber256(v) : undefined
928
- }
929
-
930
925
  function fromApiFields(vals: node.Val[], fieldsSig: node.FieldsSig): Fields {
931
926
  return fromApiVals(vals, fieldsSig.names, fieldsSig.types)
932
927
  }
@@ -1102,7 +1097,7 @@ type BuildTxParams<T> = Omit<T, 'bytecode'> & { initialFields?: Val[] }
1102
1097
  export interface BuildDeployContractTx {
1103
1098
  signerAddress: string
1104
1099
  initialFields?: Fields
1105
- initialAttoAlphAmount?: string
1100
+ initialAttoAlphAmount?: Number256
1106
1101
  initialTokenAmounts?: Token[]
1107
1102
  issueTokenAmount?: Number256
1108
1103
  gasAmount?: number
@@ -91,10 +91,10 @@ assertType<Eq<SignDeployContractTxResult, SignResult<node.BuildDeployContractTxR
91
91
  export interface SignExecuteScriptTxParams {
92
92
  signerAddress: string
93
93
  bytecode: string
94
- attoAlphAmount?: string
94
+ attoAlphAmount?: Number256
95
95
  tokens?: Token[]
96
96
  gasAmount?: number
97
- gasPrice?: string
97
+ gasPrice?: Number256
98
98
  }
99
99
  assertType<Eq<keyof SignExecuteScriptTxParams, keyof TxBuildParams<node.BuildExecuteScriptTx>>>()
100
100
  export interface SignExecuteScriptTxResult {
@@ -250,7 +250,9 @@ export abstract class SignerProviderSimple implements SignerProvider {
250
250
  async buildScriptTx(params: SignExecuteScriptTxParams): Promise<node.BuildExecuteScriptTxResult> {
251
251
  const data: node.BuildExecuteScriptTx = {
252
252
  ...(await this.usePublicKey(params)),
253
- tokens: toApiTokens(params.tokens)
253
+ attoAlphAmount: toApiNumber256Optional(params.attoAlphAmount),
254
+ tokens: toApiTokens(params.tokens),
255
+ gasPrice: toApiNumber256Optional(params.gasPrice)
254
256
  }
255
257
  return this.getNodeProvider().contracts.postContractsUnsignedTxExecuteScript(data)
256
258
  }