@multiplechain/bitcoin 0.1.16 → 0.1.18

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,7 +1,7 @@
1
1
  {
2
2
  "namespace": "multiplechain",
3
3
  "name": "@multiplechain/bitcoin",
4
- "version": "0.1.16",
4
+ "version": "0.1.18",
5
5
  "description": "Bitcoin JS provider",
6
6
  "scripts": {
7
7
  "serve": "parcel test.html --no-cache --dist-dir test",
@@ -114,42 +114,33 @@ class Transaction {
114
114
  /**
115
115
  * @returns {Boolean}
116
116
  */
117
- validateTransaction() {
118
- return new Promise((resolve, reject) => {
119
- this.intervalValidate = setInterval(async () => {
120
- try {
117
+ async validate(timer = 1) {
118
+ timer = this.timer || timer;
119
+ try {
120
+
121
+ await new Promise(r => setTimeout(r, (timer*1000)));
121
122
 
122
- await this.getData();
123
+ await this.getData();
123
124
 
124
- let result = null;
125
+ let result = null;
125
126
 
126
- if (this.data == null) {
127
- result = false;
128
- } else {
129
- if (this.data.status.block_height) {
130
- result = true;
131
- }
132
- }
127
+ if (this.data && this.data.status.block_height) {
128
+ result = true;
129
+ }
133
130
 
134
- if (typeof result == 'boolean') {
135
- clearInterval(this.intervalValidate);
136
- if (result == true) {
137
- resolve(true);
138
- } else {
139
- reject(false);
140
- }
141
- }
142
-
143
- } catch (error) {
144
- if (error.message == 'There was a problem retrieving transaction data!') {
145
- this.validateTransaction();
146
- } else {
147
- clearInterval(this.intervalValidate);
148
- reject(error);
149
- }
150
- }
151
- }, (this.timer*1000));
152
- });
131
+ if (typeof result == 'boolean') {
132
+ return result;
133
+ }
134
+
135
+ return this.validate(timer);
136
+ } catch (error) {
137
+
138
+ if (error.message == 'There was a problem retrieving transaction data!') {
139
+ return this.validate(timer);
140
+ } else {
141
+ throw error;
142
+ }
143
+ }
153
144
  }
154
145
 
155
146
  /**
@@ -158,7 +149,7 @@ class Transaction {
158
149
  */
159
150
  async verifyTransferWithData(config) {
160
151
 
161
- if (await this.validateTransaction()) {
152
+ if (await this.validate()) {
162
153
 
163
154
  let index = this.data.vout.findIndex(object => {
164
155
  return object.scriptpubkey_address == config.receiver;