@alephium/web3 0.33.0 → 0.34.1

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.
@@ -56,6 +56,7 @@ const events_1 = require("./events");
56
56
  const constants_1 = require("../constants");
57
57
  const blake = __importStar(require("blakejs"));
58
58
  const error_1 = require("../utils/error");
59
+ const debug_1 = require("../debug");
59
60
  const crypto = new utils_1.WebCrypto();
60
61
  exports.StdIdFieldName = '__stdInterfaceId';
61
62
  var SourceKind;
@@ -214,7 +215,7 @@ class ProjectArtifact {
214
215
  return new ProjectArtifact(fullNodeVersion, compilerOptionsUsed, files);
215
216
  }
216
217
  catch (error) {
217
- console.log(`Failed to load project artifact, error: ${error}`);
218
+ console.error(`Failed to load project artifact, error: ${error}`);
218
219
  return undefined;
219
220
  }
220
221
  }
@@ -646,7 +647,7 @@ class Contract extends Artifact {
646
647
  return utils_1.bs58.encode(bytes);
647
648
  }
648
649
  printDebugMessages(funcName, messages) {
649
- if (messages.length != 0) {
650
+ if ((0, debug_1.isContractDebugMessageEnabled)() && messages.length != 0) {
650
651
  console.log(`Testing ${this.name}.${funcName}:`);
651
652
  messages.forEach((m) => console.log(`> Contract @ ${m.contractAddress} - ${m.message}`));
652
653
  }
@@ -5,6 +5,18 @@ export declare function encodeI256(i256: bigint): Uint8Array;
5
5
  export declare function encodeU256(u256: bigint): Uint8Array;
6
6
  export declare function encodeByteVec(bytes: string): Uint8Array;
7
7
  export declare function encodeAddress(address: string): Uint8Array;
8
+ export declare enum VmValType {
9
+ Bool = 0,
10
+ I256 = 1,
11
+ U256 = 2,
12
+ ByteVec = 3,
13
+ Address = 4
14
+ }
15
+ export declare function encodeVmBool(bool: boolean): Uint8Array;
16
+ export declare function encodeVmI256(i256: bigint): Uint8Array;
17
+ export declare function encodeVmU256(u256: bigint): Uint8Array;
18
+ export declare function encodeVmByteVec(bytes: string): Uint8Array;
19
+ export declare function encodeVmAddress(address: string): Uint8Array;
8
20
  export declare function encodeScriptFieldAsString(tpe: string, value: Val): string;
9
21
  export declare function encodeScriptField(tpe: string, value: Val): Uint8Array;
10
22
  export declare function falttenFields(fields: Fields, fieldsSig: FieldsSig): {
@@ -18,7 +18,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  var _a;
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.buildDebugBytecode = exports.encodeContractField = exports.buildContractByteCode = exports.buildScriptByteCode = exports.falttenFields = exports.encodeScriptField = exports.encodeScriptFieldAsString = exports.encodeAddress = exports.encodeByteVec = exports.encodeU256 = exports.encodeI256 = exports.encodeBool = void 0;
21
+ exports.buildDebugBytecode = exports.encodeContractField = exports.buildContractByteCode = exports.buildScriptByteCode = exports.falttenFields = exports.encodeScriptField = exports.encodeScriptFieldAsString = exports.encodeVmAddress = exports.encodeVmByteVec = exports.encodeVmU256 = exports.encodeVmI256 = exports.encodeVmBool = exports.VmValType = exports.encodeAddress = exports.encodeByteVec = exports.encodeU256 = exports.encodeI256 = exports.encodeBool = void 0;
22
22
  const buffer_1 = require("buffer/");
23
23
  const api_1 = require("../api");
24
24
  const utils_1 = require("../utils");
@@ -164,6 +164,34 @@ function encodeAddress(address) {
164
164
  return utils_1.bs58.decode(address);
165
165
  }
166
166
  exports.encodeAddress = encodeAddress;
167
+ var VmValType;
168
+ (function (VmValType) {
169
+ VmValType[VmValType["Bool"] = 0] = "Bool";
170
+ VmValType[VmValType["I256"] = 1] = "I256";
171
+ VmValType[VmValType["U256"] = 2] = "U256";
172
+ VmValType[VmValType["ByteVec"] = 3] = "ByteVec";
173
+ VmValType[VmValType["Address"] = 4] = "Address";
174
+ })(VmValType = exports.VmValType || (exports.VmValType = {}));
175
+ function encodeVmBool(bool) {
176
+ return buffer_1.Buffer.concat([encodeU256(BigInt(VmValType.Bool)), encodeBool(bool)]);
177
+ }
178
+ exports.encodeVmBool = encodeVmBool;
179
+ function encodeVmI256(i256) {
180
+ return buffer_1.Buffer.concat([encodeU256(BigInt(VmValType.I256)), encodeI256(i256)]);
181
+ }
182
+ exports.encodeVmI256 = encodeVmI256;
183
+ function encodeVmU256(u256) {
184
+ return buffer_1.Buffer.concat([encodeU256(BigInt(VmValType.U256)), encodeU256(u256)]);
185
+ }
186
+ exports.encodeVmU256 = encodeVmU256;
187
+ function encodeVmByteVec(bytes) {
188
+ return buffer_1.Buffer.concat([encodeU256(BigInt(VmValType.ByteVec)), encodeByteVec(bytes)]);
189
+ }
190
+ exports.encodeVmByteVec = encodeVmByteVec;
191
+ function encodeVmAddress(address) {
192
+ return buffer_1.Buffer.concat([encodeU256(BigInt(VmValType.Address)), encodeAddress(address)]);
193
+ }
194
+ exports.encodeVmAddress = encodeVmAddress;
167
195
  function invalidScriptField(tpe, value) {
168
196
  return Error(`Invalid script field ${value} for type ${tpe}`);
169
197
  }
@@ -1,3 +1,6 @@
1
1
  export declare function isDebugModeEnabled(): boolean;
2
2
  export declare function enableDebugMode(): void;
3
3
  export declare function disableDebugMode(): void;
4
+ export declare function isContractDebugMessageEnabled(): boolean;
5
+ export declare function enableContractDebugMessage(): void;
6
+ export declare function disableContractDebugMessage(): void;
package/dist/src/debug.js CHANGED
@@ -17,7 +17,7 @@ You should have received a copy of the GNU Lesser General Public License
17
17
  along with the library. If not, see <http://www.gnu.org/licenses/>.
18
18
  */
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.disableDebugMode = exports.enableDebugMode = exports.isDebugModeEnabled = void 0;
20
+ exports.disableContractDebugMessage = exports.enableContractDebugMessage = exports.isContractDebugMessageEnabled = exports.disableDebugMode = exports.enableDebugMode = exports.isDebugModeEnabled = void 0;
21
21
  let debugModeEnabled = false;
22
22
  function isDebugModeEnabled() {
23
23
  return debugModeEnabled;
@@ -31,3 +31,16 @@ function disableDebugMode() {
31
31
  debugModeEnabled = false;
32
32
  }
33
33
  exports.disableDebugMode = disableDebugMode;
34
+ let contractDebugMessageEnabled = !(process.env.CONTRACT_DEBUG_MESSAGE === 'false'); // default to true
35
+ function isContractDebugMessageEnabled() {
36
+ return contractDebugMessageEnabled;
37
+ }
38
+ exports.isContractDebugMessageEnabled = isContractDebugMessageEnabled;
39
+ function enableContractDebugMessage() {
40
+ contractDebugMessageEnabled = true;
41
+ }
42
+ exports.enableContractDebugMessage = enableContractDebugMessage;
43
+ function disableContractDebugMessage() {
44
+ contractDebugMessageEnabled = false;
45
+ }
46
+ exports.disableContractDebugMessage = disableContractDebugMessage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alephium/web3",
3
- "version": "0.33.0",
3
+ "version": "0.34.1",
4
4
  "description": "A JS/TS library to interact with the Alephium platform",
5
5
  "license": "GPL",
6
6
  "main": "dist/src/index.js",
@@ -65,6 +65,7 @@ import { EventSubscribeOptions, EventSubscription, subscribeToEvents } from './e
65
65
  import { ONE_ALPH } from '../constants'
66
66
  import * as blake from 'blakejs'
67
67
  import { parseError } from '../utils/error'
68
+ import { isContractDebugMessageEnabled } from '../debug'
68
69
 
69
70
  const crypto = new WebCrypto()
70
71
 
@@ -303,7 +304,7 @@ export class ProjectArtifact {
303
304
  const files = new Map(Object.entries<CodeInfo>(json.infos))
304
305
  return new ProjectArtifact(fullNodeVersion, compilerOptionsUsed, files)
305
306
  } catch (error) {
306
- console.log(`Failed to load project artifact, error: ${error}`)
307
+ console.error(`Failed to load project artifact, error: ${error}`)
307
308
  return undefined
308
309
  }
309
310
  }
@@ -964,7 +965,7 @@ export class Contract extends Artifact {
964
965
  }
965
966
 
966
967
  printDebugMessages(funcName: string, messages: DebugMessage[]) {
967
- if (messages.length != 0) {
968
+ if (isContractDebugMessageEnabled() && messages.length != 0) {
968
969
  console.log(`Testing ${this.name}.${funcName}:`)
969
970
  messages.forEach((m) => console.log(`> Contract @ ${m.contractAddress} - ${m.message}`))
970
971
  }
@@ -157,6 +157,34 @@ export function encodeAddress(address: string): Uint8Array {
157
157
  return bs58.decode(address)
158
158
  }
159
159
 
160
+ export enum VmValType {
161
+ Bool = 0,
162
+ I256 = 1,
163
+ U256 = 2,
164
+ ByteVec = 3,
165
+ Address = 4
166
+ }
167
+
168
+ export function encodeVmBool(bool: boolean): Uint8Array {
169
+ return Buffer.concat([encodeU256(BigInt(VmValType.Bool)), encodeBool(bool)])
170
+ }
171
+
172
+ export function encodeVmI256(i256: bigint): Uint8Array {
173
+ return Buffer.concat([encodeU256(BigInt(VmValType.I256)), encodeI256(i256)])
174
+ }
175
+
176
+ export function encodeVmU256(u256: bigint): Uint8Array {
177
+ return Buffer.concat([encodeU256(BigInt(VmValType.U256)), encodeU256(u256)])
178
+ }
179
+
180
+ export function encodeVmByteVec(bytes: string): Uint8Array {
181
+ return Buffer.concat([encodeU256(BigInt(VmValType.ByteVec)), encodeByteVec(bytes)])
182
+ }
183
+
184
+ export function encodeVmAddress(address: string): Uint8Array {
185
+ return Buffer.concat([encodeU256(BigInt(VmValType.Address)), encodeAddress(address)])
186
+ }
187
+
160
188
  function invalidScriptField(tpe: string, value: Val): Error {
161
189
  return Error(`Invalid script field ${value} for type ${tpe}`)
162
190
  }
package/src/debug.ts CHANGED
@@ -29,3 +29,17 @@ export function enableDebugMode() {
29
29
  export function disableDebugMode() {
30
30
  debugModeEnabled = false
31
31
  }
32
+
33
+ let contractDebugMessageEnabled = !(process.env.CONTRACT_DEBUG_MESSAGE === 'false') // default to true
34
+
35
+ export function isContractDebugMessageEnabled() {
36
+ return contractDebugMessageEnabled
37
+ }
38
+
39
+ export function enableContractDebugMessage() {
40
+ contractDebugMessageEnabled = true
41
+ }
42
+
43
+ export function disableContractDebugMessage() {
44
+ contractDebugMessageEnabled = false
45
+ }