@btc-vision/btc-runtime 1.0.13 → 1.0.14
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/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
## Introduction
|
|
13
13
|
|
|
14
|
-
The OPNet Smart Contract Runtime contains all the necessary components to effectively create smart contracts
|
|
14
|
+
The OPNet Smart Contract Runtime contains all the necessary components to effectively create smart contracts on Bitcoin
|
|
15
15
|
L1. The runtime is written in AssemblyScript.
|
|
16
16
|
|
|
17
17
|
### Installation
|
package/package.json
CHANGED
|
@@ -299,7 +299,7 @@ export class BytesWriter {
|
|
|
299
299
|
|
|
300
300
|
private fromAddress(value: Address): Uint8Array {
|
|
301
301
|
if (value.length > i32(ADDRESS_BYTE_LENGTH)) {
|
|
302
|
-
throw new Revert(
|
|
302
|
+
throw new Revert(`Address is too long ${value.length} > ${ADDRESS_BYTE_LENGTH} bytes`);
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
const bytes: Uint8Array = new Uint8Array(ADDRESS_BYTE_LENGTH);
|
package/runtime/index.ts
CHANGED
package/runtime/types/Address.ts
CHANGED
|
@@ -19,6 +19,30 @@ export class SafeMath {
|
|
|
19
19
|
return u256.sub(a, b);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
// Computes (a * b) % modulus with full precision
|
|
23
|
+
public static mulmod(a: u256, b: u256, modulus: u256): u256 {
|
|
24
|
+
if (u256.eq(modulus, u256.Zero)) throw new Error('SafeMath: modulo by zero');
|
|
25
|
+
|
|
26
|
+
const mul = SafeMath.mul(a, b);
|
|
27
|
+
return SafeMath.mod(mul, modulus);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@inline
|
|
31
|
+
@unsafe
|
|
32
|
+
@operator('%')
|
|
33
|
+
public static mod(a: u256, b: u256): u256 {
|
|
34
|
+
if (u256.eq(b, u256.Zero)) {
|
|
35
|
+
throw new Error('SafeMath: modulo by zero');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let result = a.clone();
|
|
39
|
+
while (u256.ge(result, b)) {
|
|
40
|
+
result = u256.sub(result, b);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
|
|
22
46
|
public static mul(a: u256, b: u256): u256 {
|
|
23
47
|
if (a === SafeMath.ZERO || b === SafeMath.ZERO) {
|
|
24
48
|
return SafeMath.ZERO;
|
|
@@ -37,7 +61,7 @@ export class SafeMath {
|
|
|
37
61
|
@inline
|
|
38
62
|
@unsafe
|
|
39
63
|
@operator('/')
|
|
40
|
-
static div(a: u256, b: u256): u256 {
|
|
64
|
+
public static div(a: u256, b: u256): u256 {
|
|
41
65
|
if (b.isZero()) {
|
|
42
66
|
throw new Error('Division by zero');
|
|
43
67
|
}
|
|
@@ -110,7 +134,7 @@ export class SafeMath {
|
|
|
110
134
|
|
|
111
135
|
@inline
|
|
112
136
|
@unsafe
|
|
113
|
-
static shl(value: u256, shift: i32): u256 {
|
|
137
|
+
public static shl(value: u256, shift: i32): u256 {
|
|
114
138
|
if (shift == 0) {
|
|
115
139
|
return value.clone();
|
|
116
140
|
}
|