@btc-vision/btc-runtime 1.0.6 → 1.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@btc-vision/btc-runtime",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "Bitcoin Smart Contract Runtime",
5
5
  "main": "btc/index.ts",
6
6
  "types": "btc/index.ts",
@@ -33,6 +33,12 @@ export class BlockchainEnvironment {
33
33
 
34
34
  constructor() {}
35
35
 
36
+ private _timestamp: u64 = 0;
37
+
38
+ public get timestamp(): u64 {
39
+ return this._timestamp;
40
+ }
41
+
36
42
  private _contract: Potential<() => OP_NET> = null;
37
43
 
38
44
  public get contract(): OP_NET {
@@ -104,6 +110,8 @@ export class BlockchainEnvironment {
104
110
 
105
111
  this._owner = reader.readAddress();
106
112
  this._contractAddress = reader.readAddress();
113
+
114
+ this._timestamp = reader.readU64();
107
115
  }
108
116
 
109
117
  public call(destinationContract: Address, calldata: BytesWriter): BytesReader {
@@ -18,4 +18,4 @@ export declare function deployFromAddress(data: Uint8Array): Uint8Array;
18
18
 
19
19
  // @ts-ignore
20
20
  @external('env', 'call')
21
- export declare function call(calldata: Uint8Array): Uint8Array;
21
+ export declare function call(data: Uint8Array): Uint8Array;
@@ -72,6 +72,35 @@ export class SafeMath {
72
72
  return result;
73
73
  }
74
74
 
75
+ public static min(a: u256, b: u256): u256 {
76
+ return u256.lt(a, b) ? a : b;
77
+ }
78
+
79
+ public static max(a: u256, b: u256): u256 {
80
+ return u256.gt(a, b) ? a : b;
81
+ }
82
+
83
+ @inline
84
+ @unsafe
85
+ public static sqrt(y: u256): u256 {
86
+ if (u256.gt(y, u256.fromU32(3))) {
87
+ let z = y;
88
+
89
+ let x = SafeMath.add(SafeMath.div(y, u256.fromU32(2)), u256.fromU32(1));
90
+ while (u256.lt(x, z)) {
91
+ z = x;
92
+
93
+ let u = SafeMath.div(y, x);
94
+ x = SafeMath.div(u256.add(u, x), u256.fromU32(2));
95
+ }
96
+ return z;
97
+ } else if (!u256.eq(y, u256.Zero)) {
98
+ return u256.fromU32(1);
99
+ } else {
100
+ return u256.Zero;
101
+ }
102
+ }
103
+
75
104
  @inline
76
105
  @unsafe
77
106
  static shl(value: u256, shift: i32): u256 {