@typeberry/convert 0.1.3-af70ed0 → 0.1.3-ea24911
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/index.js +60 -37
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -16263,10 +16263,16 @@ function registers_signExtend32To64(value) {
|
|
|
16263
16263
|
|
|
16264
16264
|
/** Attempt to convert a number into `HostCallIndex`. */
|
|
16265
16265
|
const host_call_handler_tryAsHostCallIndex = (v) => opaque_asOpaqueType(numbers_tryAsU32(v));
|
|
16266
|
+
/**
|
|
16267
|
+
* Host-call exit reason.
|
|
16268
|
+
*
|
|
16269
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/24a30124a501?v=0.7.2
|
|
16270
|
+
*/
|
|
16266
16271
|
var host_call_handler_PvmExecution;
|
|
16267
16272
|
(function (PvmExecution) {
|
|
16268
16273
|
PvmExecution[PvmExecution["Halt"] = 0] = "Halt";
|
|
16269
16274
|
PvmExecution[PvmExecution["Panic"] = 1] = "Panic";
|
|
16275
|
+
PvmExecution[PvmExecution["OOG"] = 2] = "OOG";
|
|
16270
16276
|
})(host_call_handler_PvmExecution || (host_call_handler_PvmExecution = {}));
|
|
16271
16277
|
/** A utility function to easily trace a bunch of registers. */
|
|
16272
16278
|
function host_call_handler_traceRegisters(...regs) {
|
|
@@ -19883,8 +19889,9 @@ class host_calls_HostCalls {
|
|
|
19883
19889
|
const index = tryAsHostCallIndex(hostCallIndex);
|
|
19884
19890
|
const hostCall = this.hostCalls.get(index);
|
|
19885
19891
|
const gasBefore = gas.get();
|
|
19886
|
-
|
|
19887
|
-
const
|
|
19892
|
+
// NOTE: `basicGasCost(regs)` function is for compatibility reasons: pre GP 0.7.2
|
|
19893
|
+
const basicGasCost = typeof hostCall.basicGasCost === "number" ? hostCall.basicGasCost : hostCall.basicGasCost(regs);
|
|
19894
|
+
const underflow = gas.sub(basicGasCost);
|
|
19888
19895
|
const pcLog = `[PC: ${pvmInstance.getPC()}]`;
|
|
19889
19896
|
if (underflow) {
|
|
19890
19897
|
this.hostCalls.traceHostCall(`${pcLog} OOG`, index, hostCall, regs, gas.get());
|
|
@@ -19901,6 +19908,10 @@ class host_calls_HostCalls {
|
|
|
19901
19908
|
status = Status.PANIC;
|
|
19902
19909
|
return this.getReturnValue(status, pvmInstance);
|
|
19903
19910
|
}
|
|
19911
|
+
if (result === PvmExecution.OOG) {
|
|
19912
|
+
status = Status.OOG;
|
|
19913
|
+
return this.getReturnValue(status, pvmInstance);
|
|
19914
|
+
}
|
|
19904
19915
|
if (result === undefined) {
|
|
19905
19916
|
pvmInstance.runProgram();
|
|
19906
19917
|
status = pvmInstance.getStatus();
|
|
@@ -19959,7 +19970,7 @@ class host_calls_manager_HostCallsManager {
|
|
|
19959
19970
|
}
|
|
19960
19971
|
class NoopMissing {
|
|
19961
19972
|
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
19962
|
-
|
|
19973
|
+
basicGasCost = tryAsSmallGas(0);
|
|
19963
19974
|
currentServiceId = tryAsU32(0);
|
|
19964
19975
|
tracedRegisters = [];
|
|
19965
19976
|
async execute() {
|
|
@@ -20073,7 +20084,7 @@ function utils_clampU64ToU32(value) {
|
|
|
20073
20084
|
|
|
20074
20085
|
class missing_Missing {
|
|
20075
20086
|
index = tryAsHostCallIndex(2 ** 32 - 1);
|
|
20076
|
-
|
|
20087
|
+
basicGasCost = tryAsSmallGas(10);
|
|
20077
20088
|
currentServiceId = CURRENT_SERVICE_ID;
|
|
20078
20089
|
tracedRegisters = traceRegisters(7);
|
|
20079
20090
|
execute(_gas, regs, _memory) {
|
|
@@ -23056,7 +23067,7 @@ class Assign {
|
|
|
23056
23067
|
partialState;
|
|
23057
23068
|
chainSpec;
|
|
23058
23069
|
index = host_call_handler_tryAsHostCallIndex(15);
|
|
23059
|
-
|
|
23070
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23060
23071
|
tracedRegisters = host_call_handler_traceRegisters(IN_OUT_REG, 8);
|
|
23061
23072
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
23062
23073
|
this.currentServiceId = currentServiceId;
|
|
@@ -23134,7 +23145,7 @@ class Bless {
|
|
|
23134
23145
|
partialState;
|
|
23135
23146
|
chainSpec;
|
|
23136
23147
|
index = host_call_handler_tryAsHostCallIndex(14);
|
|
23137
|
-
|
|
23148
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23138
23149
|
tracedRegisters = host_call_handler_traceRegisters(bless_IN_OUT_REG, 8, 9, 10, 11);
|
|
23139
23150
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
23140
23151
|
this.currentServiceId = currentServiceId;
|
|
@@ -23219,7 +23230,7 @@ class Bless {
|
|
|
23219
23230
|
class gas_GasHostCall {
|
|
23220
23231
|
currentServiceId;
|
|
23221
23232
|
index = host_call_handler_tryAsHostCallIndex(0);
|
|
23222
|
-
|
|
23233
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23223
23234
|
tracedRegisters = host_call_handler_traceRegisters(7);
|
|
23224
23235
|
constructor(currentServiceId) {
|
|
23225
23236
|
this.currentServiceId = currentServiceId;
|
|
@@ -23246,7 +23257,7 @@ class Checkpoint {
|
|
|
23246
23257
|
currentServiceId;
|
|
23247
23258
|
partialState;
|
|
23248
23259
|
index = host_call_handler_tryAsHostCallIndex(17);
|
|
23249
|
-
|
|
23260
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23250
23261
|
tracedRegisters;
|
|
23251
23262
|
gasHostCall;
|
|
23252
23263
|
constructor(currentServiceId, partialState) {
|
|
@@ -23283,7 +23294,7 @@ class Designate {
|
|
|
23283
23294
|
partialState;
|
|
23284
23295
|
chainSpec;
|
|
23285
23296
|
index = host_call_handler_tryAsHostCallIndex(16);
|
|
23286
|
-
|
|
23297
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23287
23298
|
tracedRegisters = host_call_handler_traceRegisters(designate_IN_OUT_REG);
|
|
23288
23299
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
23289
23300
|
this.currentServiceId = currentServiceId;
|
|
@@ -23334,7 +23345,7 @@ class Eject {
|
|
|
23334
23345
|
currentServiceId;
|
|
23335
23346
|
partialState;
|
|
23336
23347
|
index = host_call_handler_tryAsHostCallIndex(21);
|
|
23337
|
-
|
|
23348
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23338
23349
|
tracedRegisters = host_call_handler_traceRegisters(eject_IN_OUT_REG, 8);
|
|
23339
23350
|
constructor(currentServiceId, partialState) {
|
|
23340
23351
|
this.currentServiceId = currentServiceId;
|
|
@@ -23396,7 +23407,7 @@ class Forget {
|
|
|
23396
23407
|
currentServiceId;
|
|
23397
23408
|
partialState;
|
|
23398
23409
|
index = host_call_handler_tryAsHostCallIndex(24);
|
|
23399
|
-
|
|
23410
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23400
23411
|
tracedRegisters = host_call_handler_traceRegisters(forget_IN_OUT_REG, 8);
|
|
23401
23412
|
constructor(currentServiceId, partialState) {
|
|
23402
23413
|
this.currentServiceId = currentServiceId;
|
|
@@ -23446,7 +23457,7 @@ class New {
|
|
|
23446
23457
|
currentServiceId;
|
|
23447
23458
|
partialState;
|
|
23448
23459
|
index = host_call_handler_tryAsHostCallIndex(18);
|
|
23449
|
-
|
|
23460
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23450
23461
|
tracedRegisters = host_call_handler_traceRegisters(new_IN_OUT_REG, 8, 9, 10, 11);
|
|
23451
23462
|
constructor(currentServiceId, partialState) {
|
|
23452
23463
|
this.currentServiceId = currentServiceId;
|
|
@@ -23509,7 +23520,7 @@ class Provide {
|
|
|
23509
23520
|
currentServiceId;
|
|
23510
23521
|
partialState;
|
|
23511
23522
|
index = host_call_handler_tryAsHostCallIndex(26);
|
|
23512
|
-
|
|
23523
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23513
23524
|
tracedRegisters = host_call_handler_traceRegisters(provide_IN_OUT_REG, 8, 9);
|
|
23514
23525
|
constructor(currentServiceId, partialState) {
|
|
23515
23526
|
this.currentServiceId = currentServiceId;
|
|
@@ -23570,7 +23581,7 @@ class Query {
|
|
|
23570
23581
|
currentServiceId;
|
|
23571
23582
|
partialState;
|
|
23572
23583
|
index = host_call_handler_tryAsHostCallIndex(22);
|
|
23573
|
-
|
|
23584
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23574
23585
|
tracedRegisters = host_call_handler_traceRegisters(IN_OUT_REG_1, IN_OUT_REG_2);
|
|
23575
23586
|
constructor(currentServiceId, partialState) {
|
|
23576
23587
|
this.currentServiceId = currentServiceId;
|
|
@@ -23636,7 +23647,7 @@ class Solicit {
|
|
|
23636
23647
|
currentServiceId;
|
|
23637
23648
|
partialState;
|
|
23638
23649
|
index = host_call_handler_tryAsHostCallIndex(23);
|
|
23639
|
-
|
|
23650
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23640
23651
|
tracedRegisters = host_call_handler_traceRegisters(solicit_IN_OUT_REG, 8);
|
|
23641
23652
|
constructor(currentServiceId, partialState) {
|
|
23642
23653
|
this.currentServiceId = currentServiceId;
|
|
@@ -23684,12 +23695,12 @@ class Solicit {
|
|
|
23684
23695
|
|
|
23685
23696
|
const transfer_IN_OUT_REG = 7; // `d`
|
|
23686
23697
|
const AMOUNT_REG = 8; // `a`
|
|
23687
|
-
const
|
|
23698
|
+
const TRANSFER_GAS_FEE_REG = 9; // `l`
|
|
23688
23699
|
const MEMO_START_REG = 10; // `o`
|
|
23689
23700
|
/**
|
|
23690
23701
|
* Transfer balance from one service account to another.
|
|
23691
23702
|
*
|
|
23692
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
23703
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/373f00373f00?v=0.7.2
|
|
23693
23704
|
*/
|
|
23694
23705
|
class Transfer {
|
|
23695
23706
|
currentServiceId;
|
|
@@ -23701,38 +23712,50 @@ class Transfer {
|
|
|
23701
23712
|
},
|
|
23702
23713
|
}));
|
|
23703
23714
|
/**
|
|
23704
|
-
* `g = 10 +
|
|
23705
|
-
*
|
|
23715
|
+
* `g = 10 + t`
|
|
23716
|
+
*
|
|
23717
|
+
* `t` has positive value, only when status of a transfer is `OK`
|
|
23718
|
+
* `0` otherwise
|
|
23719
|
+
*
|
|
23720
|
+
* Pre0.7.2: `g = 10 + ω9`
|
|
23721
|
+
*
|
|
23722
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/373f00373f00?v=0.7.2
|
|
23706
23723
|
*/
|
|
23707
|
-
|
|
23708
|
-
|
|
23709
|
-
|
|
23710
|
-
|
|
23711
|
-
tracedRegisters = host_call_handler_traceRegisters(transfer_IN_OUT_REG, AMOUNT_REG, ON_TRANSFER_GAS_REG, MEMO_START_REG);
|
|
23724
|
+
basicGasCost = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_2)
|
|
23725
|
+
? gas_tryAsSmallGas(10)
|
|
23726
|
+
: (regs) => gas_tryAsGas(10n + regs.get(TRANSFER_GAS_FEE_REG));
|
|
23727
|
+
tracedRegisters = host_call_handler_traceRegisters(transfer_IN_OUT_REG, AMOUNT_REG, TRANSFER_GAS_FEE_REG, MEMO_START_REG);
|
|
23712
23728
|
constructor(currentServiceId, partialState) {
|
|
23713
23729
|
this.currentServiceId = currentServiceId;
|
|
23714
23730
|
this.partialState = partialState;
|
|
23715
23731
|
}
|
|
23716
|
-
async execute(
|
|
23732
|
+
async execute(gas, regs, memory) {
|
|
23717
23733
|
// `d`: destination
|
|
23718
23734
|
const destination = getServiceId(regs.get(transfer_IN_OUT_REG));
|
|
23719
23735
|
// `a`: amount
|
|
23720
23736
|
const amount = regs.get(AMOUNT_REG);
|
|
23721
23737
|
// `l`: gas
|
|
23722
|
-
const
|
|
23738
|
+
const transferGasFee = common_tryAsServiceGas(regs.get(TRANSFER_GAS_FEE_REG));
|
|
23723
23739
|
// `o`: transfer memo
|
|
23724
23740
|
const memoStart = regs.get(MEMO_START_REG);
|
|
23725
23741
|
const memo = bytes_Bytes.zero(TRANSFER_MEMO_BYTES);
|
|
23726
23742
|
const memoryReadResult = memory.loadInto(memo.raw, memoStart);
|
|
23727
23743
|
// page fault while reading the memory.
|
|
23728
23744
|
if (memoryReadResult.isError) {
|
|
23729
|
-
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${
|
|
23745
|
+
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- PANIC`;
|
|
23730
23746
|
return host_call_handler_PvmExecution.Panic;
|
|
23731
23747
|
}
|
|
23732
|
-
const transferResult = this.partialState.transfer(destination, amount,
|
|
23733
|
-
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${
|
|
23748
|
+
const transferResult = this.partialState.transfer(destination, amount, transferGasFee, memo);
|
|
23749
|
+
logger_logger.trace `TRANSFER(${destination}, ${amount}, ${transferGasFee}, ${memo}) <- ${result_resultToString(transferResult)}`;
|
|
23734
23750
|
// All good!
|
|
23735
23751
|
if (transferResult.isOk) {
|
|
23752
|
+
if (compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_2)) {
|
|
23753
|
+
// substracting value `t`
|
|
23754
|
+
const underflow = gas.sub(gas_tryAsGas(transferGasFee));
|
|
23755
|
+
if (underflow) {
|
|
23756
|
+
return host_call_handler_PvmExecution.OOG;
|
|
23757
|
+
}
|
|
23758
|
+
}
|
|
23736
23759
|
regs.set(transfer_IN_OUT_REG, results_HostCallResult.OK);
|
|
23737
23760
|
return;
|
|
23738
23761
|
}
|
|
@@ -23772,7 +23795,7 @@ class Upgrade {
|
|
|
23772
23795
|
currentServiceId;
|
|
23773
23796
|
partialState;
|
|
23774
23797
|
index = host_call_handler_tryAsHostCallIndex(19);
|
|
23775
|
-
|
|
23798
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23776
23799
|
tracedRegisters = host_call_handler_traceRegisters(upgrade_IN_OUT_REG, GAS_REG, ALLOWANCE_REG);
|
|
23777
23800
|
constructor(currentServiceId, partialState) {
|
|
23778
23801
|
this.currentServiceId = currentServiceId;
|
|
@@ -23815,7 +23838,7 @@ class Yield {
|
|
|
23815
23838
|
currentServiceId;
|
|
23816
23839
|
partialState;
|
|
23817
23840
|
index = host_call_handler_tryAsHostCallIndex(25);
|
|
23818
|
-
|
|
23841
|
+
basicGasCost = gas_tryAsSmallGas(10);
|
|
23819
23842
|
tracedRegisters = host_call_handler_traceRegisters(yield_IN_OUT_REG);
|
|
23820
23843
|
constructor(currentServiceId, partialState) {
|
|
23821
23844
|
this.currentServiceId = currentServiceId;
|
|
@@ -23851,7 +23874,7 @@ class fetch_Fetch {
|
|
|
23851
23874
|
currentServiceId;
|
|
23852
23875
|
fetch;
|
|
23853
23876
|
index = tryAsHostCallIndex(1);
|
|
23854
|
-
|
|
23877
|
+
basicGasCost = tryAsSmallGas(10);
|
|
23855
23878
|
tracedRegisters = traceRegisters(fetch_IN_OUT_REG, 8, 9, 10, 11, 12);
|
|
23856
23879
|
constructor(currentServiceId, fetch) {
|
|
23857
23880
|
this.currentServiceId = currentServiceId;
|
|
@@ -24008,7 +24031,7 @@ class info_Info {
|
|
|
24008
24031
|
currentServiceId;
|
|
24009
24032
|
account;
|
|
24010
24033
|
index = tryAsHostCallIndex(5);
|
|
24011
|
-
|
|
24034
|
+
basicGasCost = tryAsSmallGas(10);
|
|
24012
24035
|
tracedRegisters = traceRegisters(info_IN_OUT_REG, 8, OFFSET_REG, LEN_REG);
|
|
24013
24036
|
constructor(currentServiceId, account) {
|
|
24014
24037
|
this.currentServiceId = currentServiceId;
|
|
@@ -24083,7 +24106,7 @@ const decoder = new TextDecoder("utf8");
|
|
|
24083
24106
|
class log_LogHostCall {
|
|
24084
24107
|
currentServiceId;
|
|
24085
24108
|
index = tryAsHostCallIndex(100);
|
|
24086
|
-
|
|
24109
|
+
basicGasCost = tryAsSmallGas(0);
|
|
24087
24110
|
// intentionally not tracing anything here, since the message will be printed anyway.
|
|
24088
24111
|
tracedRegisters = traceRegisters();
|
|
24089
24112
|
constructor(currentServiceId) {
|
|
@@ -24125,7 +24148,7 @@ class lookup_Lookup {
|
|
|
24125
24148
|
currentServiceId;
|
|
24126
24149
|
account;
|
|
24127
24150
|
index = tryAsHostCallIndex(2);
|
|
24128
|
-
|
|
24151
|
+
basicGasCost = tryAsSmallGas(10);
|
|
24129
24152
|
tracedRegisters = traceRegisters(lookup_IN_OUT_REG, 8, 9, 10, 11);
|
|
24130
24153
|
constructor(currentServiceId, account) {
|
|
24131
24154
|
this.currentServiceId = currentServiceId;
|
|
@@ -24188,7 +24211,7 @@ class read_Read {
|
|
|
24188
24211
|
currentServiceId;
|
|
24189
24212
|
account;
|
|
24190
24213
|
index = tryAsHostCallIndex(3);
|
|
24191
|
-
|
|
24214
|
+
basicGasCost = tryAsSmallGas(10);
|
|
24192
24215
|
tracedRegisters = traceRegisters(read_IN_OUT_REG, 8, 9, 10, 11, 12);
|
|
24193
24216
|
constructor(currentServiceId, account) {
|
|
24194
24217
|
this.currentServiceId = currentServiceId;
|
|
@@ -24258,7 +24281,7 @@ class write_Write {
|
|
|
24258
24281
|
currentServiceId;
|
|
24259
24282
|
account;
|
|
24260
24283
|
index = tryAsHostCallIndex(4);
|
|
24261
|
-
|
|
24284
|
+
basicGasCost = tryAsSmallGas(10);
|
|
24262
24285
|
tracedRegisters = traceRegisters(write_IN_OUT_REG, 8, 9, 10);
|
|
24263
24286
|
constructor(currentServiceId, account) {
|
|
24264
24287
|
this.currentServiceId = currentServiceId;
|