@super-protocol/sdk-js 0.11.4-beta.0 → 0.11.7-beta.0
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/build/connectors/BaseConnector.d.ts +37 -0
- package/build/connectors/BaseConnector.js +84 -0
- package/build/{BlockchainConnector.d.ts → connectors/BlockchainConnector.d.ts} +22 -38
- package/build/{BlockchainConnector.js → connectors/BlockchainConnector.js} +82 -93
- package/build/connectors/BlockchainEventsListener.d.ts +13 -0
- package/build/connectors/BlockchainEventsListener.js +118 -0
- package/build/constants.d.ts +1 -1
- package/build/constants.js +1 -1
- package/build/index.d.ts +3 -2
- package/build/index.js +5 -3
- package/build/models/Ballot.js +2 -3
- package/build/models/EtlModel.d.ts +33 -0
- package/build/models/EtlModel.js +188 -0
- package/build/models/Offer.js +2 -4
- package/build/models/Order.js +2 -4
- package/build/models/Provider.js +2 -4
- package/build/models/TCB.d.ts +2 -6
- package/build/models/TCB.js +9 -23
- package/build/models/TeeOffer.d.ts +1 -0
- package/build/models/TeeOffer.js +12 -4
- package/build/proto/Compression.d.ts +2 -1
- package/build/proto/Compression.js +7 -1
- package/build/staticModels/ActiveOffers.js +5 -5
- package/build/staticModels/ActiveOrders.js +3 -3
- package/build/staticModels/Consensus.js +10 -10
- package/build/staticModels/Marks.js +4 -4
- package/build/staticModels/ModelPackager.d.ts +18 -0
- package/build/staticModels/ModelPackager.js +111 -0
- package/build/staticModels/OffersFactory.js +8 -7
- package/build/staticModels/OrdersFactory.js +24 -23
- package/build/staticModels/ProviderRegistry.js +13 -12
- package/build/staticModels/Staking.js +4 -4
- package/build/staticModels/Superpro.d.ts +2 -1
- package/build/staticModels/Superpro.js +4 -4
- package/build/staticModels/SuperproToken.d.ts +12 -4
- package/build/staticModels/SuperproToken.js +30 -14
- package/build/staticModels/TeeOffersFactory.js +8 -7
- package/build/store.d.ts +1 -2
- package/build/store.js +1 -2
- package/build/types/Compressor.d.ts +5 -0
- package/build/types/Compressor.js +2 -0
- package/build/types/Consensus.d.ts +26 -0
- package/build/types/Consensus.js +10 -1
- package/build/types/EtlModel.d.ts +2 -0
- package/build/types/EtlModel.js +2 -0
- package/build/types/ResourceLoader.d.ts +28 -0
- package/build/types/ResourceLoader.js +2 -0
- package/build/utils/TxManager.js +0 -1
- package/build/utils/compressors/GzipCompressor.d.ts +8 -0
- package/build/utils/compressors/GzipCompressor.js +65 -0
- package/build/utils/compressors/UncompressedCompressor.d.ts +8 -0
- package/build/utils/compressors/UncompressedCompressor.js +19 -0
- package/build/utils/compressors/index.d.ts +2 -0
- package/build/utils/compressors/index.js +18 -0
- package/build/utils/resourceLoaders/BaseResourceLoader.d.ts +10 -0
- package/build/utils/resourceLoaders/BaseResourceLoader.js +95 -0
- package/build/utils/resourceLoaders/StorageProviderLoader.d.ts +18 -0
- package/build/utils/resourceLoaders/StorageProviderLoader.js +132 -0
- package/build/utils/resourceLoaders/UrlResourceLoader.d.ts +9 -0
- package/build/utils/resourceLoaders/UrlResourceLoader.js +127 -0
- package/build/utils/resourceLoaders/getResourceLoader.d.ts +5 -0
- package/build/utils/resourceLoaders/getResourceLoader.js +14 -0
- package/build/utils/resourceLoaders/index.d.ts +1 -0
- package/build/utils/resourceLoaders/index.js +17 -0
- package/build/utils.d.ts +0 -10
- package/build/utils.js +5 -23
- package/package.json +2 -2
- package/readme.md +9 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { HttpProviderBase, WebsocketProviderBase } from "web3-core-helpers";
|
|
2
|
+
import { Contract } from "web3-eth-contract";
|
|
3
|
+
export declare type Config = {
|
|
4
|
+
contractAddress: string;
|
|
5
|
+
blockchainUrl?: string;
|
|
6
|
+
gasPrice?: string;
|
|
7
|
+
gasLimit?: number;
|
|
8
|
+
gasLimitMultiplier?: number;
|
|
9
|
+
reconnect?: {
|
|
10
|
+
auto?: boolean;
|
|
11
|
+
delay?: number;
|
|
12
|
+
maxAttempts?: number;
|
|
13
|
+
onTimeout?: boolean;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export declare class BaseConnector {
|
|
17
|
+
protected initialized: boolean;
|
|
18
|
+
protected logger: import("pino").default.Logger<{
|
|
19
|
+
level: string;
|
|
20
|
+
} & import("pino").default.ChildLoggerOptions>;
|
|
21
|
+
protected contract?: Contract;
|
|
22
|
+
protected provider?: WebsocketProviderBase | HttpProviderBase;
|
|
23
|
+
isInitialized(): boolean;
|
|
24
|
+
checkIfInitialized(): void;
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @returns initialized contract
|
|
28
|
+
*/
|
|
29
|
+
getContract(): Contract;
|
|
30
|
+
/**
|
|
31
|
+
* Function for connecting to blockchain
|
|
32
|
+
* Used to setting up settings for blockchain connector
|
|
33
|
+
* Needs to run this function before using blockchain connector
|
|
34
|
+
*/
|
|
35
|
+
initialize(config: Config): Promise<void>;
|
|
36
|
+
shutdown(): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.BaseConnector = void 0;
|
|
43
|
+
var logger_1 = __importDefault(require("../logger"));
|
|
44
|
+
var BaseConnector = /** @class */ (function () {
|
|
45
|
+
function BaseConnector() {
|
|
46
|
+
this.initialized = false;
|
|
47
|
+
this.logger = logger_1.default.child({ className: this.constructor["name"] });
|
|
48
|
+
}
|
|
49
|
+
BaseConnector.prototype.isInitialized = function () {
|
|
50
|
+
return this.initialized;
|
|
51
|
+
};
|
|
52
|
+
BaseConnector.prototype.checkIfInitialized = function () {
|
|
53
|
+
if (!this.initialized)
|
|
54
|
+
throw new Error("".concat(this.constructor["name"], " is not initialized, needs to run '").concat(this.constructor["name"], ".initialize(CONFIG)' first"));
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @returns initialized contract
|
|
59
|
+
*/
|
|
60
|
+
BaseConnector.prototype.getContract = function () {
|
|
61
|
+
this.checkIfInitialized();
|
|
62
|
+
return this.contract;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Function for connecting to blockchain
|
|
66
|
+
* Used to setting up settings for blockchain connector
|
|
67
|
+
* Needs to run this function before using blockchain connector
|
|
68
|
+
*/
|
|
69
|
+
BaseConnector.prototype.initialize = function (config) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
71
|
+
return [2 /*return*/];
|
|
72
|
+
}); });
|
|
73
|
+
};
|
|
74
|
+
BaseConnector.prototype.shutdown = function () {
|
|
75
|
+
var _a;
|
|
76
|
+
if (this.initialized) {
|
|
77
|
+
(_a = this.provider) === null || _a === void 0 ? void 0 : _a.disconnect(0, "");
|
|
78
|
+
this.initialized = false;
|
|
79
|
+
this.logger.trace("".concat(this.constructor["name"], " was shutdown"));
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
return BaseConnector;
|
|
83
|
+
}());
|
|
84
|
+
exports.BaseConnector = BaseConnector;
|
|
@@ -1,61 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { BaseConnector, Config } from "./BaseConnector";
|
|
2
|
+
import { TransactionOptions, EventData, BlockInfo } from "../types/Web3";
|
|
3
|
+
import BlockchainTransaction from "../types/blockchainConnector/StorageAccess";
|
|
3
4
|
import { TransactionReceipt } from "web3-core";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
private static
|
|
7
|
-
private
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
static defaultActionAccount?: string;
|
|
11
|
-
private static initContracts;
|
|
12
|
-
static getContractInstance(transactionOptions?: TransactionOptions): Contract;
|
|
5
|
+
declare class BlockchainConnector extends BaseConnector {
|
|
6
|
+
private defaultActionAccount?;
|
|
7
|
+
private static instance;
|
|
8
|
+
private constructor();
|
|
9
|
+
static getInstance(): BlockchainConnector;
|
|
10
|
+
getContract(transactionOptions?: TransactionOptions): import("web3-eth-contract").Contract;
|
|
13
11
|
/**
|
|
14
12
|
* Function for connecting to blockchain
|
|
15
13
|
* Used to setting up settings for blockchain connector
|
|
16
14
|
* Needs to run this function before using blockchain connector
|
|
17
15
|
*/
|
|
18
|
-
|
|
16
|
+
initialize(config: Config): Promise<void>;
|
|
19
17
|
/**
|
|
20
18
|
* Function for connecting provider action account
|
|
21
19
|
* Needs to run this function before using any set methods in blockchain connector
|
|
22
20
|
*/
|
|
23
|
-
|
|
21
|
+
initializeActionAccount(actionAccountKey: string, manageNonce?: boolean): Promise<string>;
|
|
24
22
|
/**
|
|
25
23
|
* Returns balance of blockchain platform tokens in wei
|
|
26
24
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
getBalance(address: string): Promise<string>;
|
|
26
|
+
getTimestamp(): Promise<number | string>;
|
|
29
27
|
/**
|
|
30
28
|
* Returns transactions events info
|
|
31
29
|
* @param txHash - transaction hash
|
|
32
30
|
* @returns {Promise<EventData[]>} - Transaction events info
|
|
33
31
|
*/
|
|
34
|
-
|
|
32
|
+
getTransactionEvents(txHash: string): Promise<EventData[]>;
|
|
35
33
|
/**
|
|
36
34
|
* Function for adding event listeners on TEE offer created event in TEE offers factory contract
|
|
37
35
|
* @param callback - function for processing created TEE offer
|
|
38
36
|
* @return unsubscribe - unsubscribe function from event
|
|
39
37
|
*/
|
|
40
|
-
|
|
38
|
+
getLastBlockInfo(): Promise<BlockInfo>;
|
|
41
39
|
/**
|
|
42
40
|
* Returns transactions reciept
|
|
43
41
|
* @param txHash - transaction hash
|
|
44
42
|
* @returns {Promise<TransactionReceipt>} - Transaction reciept
|
|
45
43
|
*/
|
|
46
|
-
|
|
44
|
+
getTransactionReceipt(txHash: string): Promise<TransactionReceipt>;
|
|
47
45
|
/**
|
|
48
46
|
* Returns balance of blockchain platform tokens in wei
|
|
49
47
|
*/
|
|
50
|
-
|
|
48
|
+
transfer(to: string, amount: string, transactionOptions?: TransactionOptions): Promise<TransactionReceipt>;
|
|
51
49
|
/**
|
|
52
50
|
* Returns transactions count
|
|
53
51
|
* @param address - wallet address
|
|
54
52
|
* @returns {Promise<number>} - Transactions count
|
|
55
53
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
private
|
|
54
|
+
getTransactionCount(address: string, status?: string): Promise<number>;
|
|
55
|
+
getAddressByKey(pk: string): string;
|
|
56
|
+
private executeBatchAsync;
|
|
59
57
|
/**
|
|
60
58
|
* Fetch transactions for specific addresses starting with specific block until last block
|
|
61
59
|
* @param addresses - array of addresses to fetch transactions (from these addresses and to these addresses)
|
|
@@ -67,21 +65,7 @@ declare class BlockchainConnector {
|
|
|
67
65
|
* lastBlock, - number of last fetched block (can be used to start fetching from this block next time)
|
|
68
66
|
* }>}
|
|
69
67
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
getTransactions(addresses: string[], startBlock?: number, lastBlock?: number, batchSize?: number): Promise<BlockchainTransaction>;
|
|
69
|
+
shutdown(): void;
|
|
72
70
|
}
|
|
73
|
-
export declare type Config = {
|
|
74
|
-
contractAddress: string;
|
|
75
|
-
blockchainUrl?: string;
|
|
76
|
-
blockchainHttpsUrl?: string;
|
|
77
|
-
gasPrice?: string;
|
|
78
|
-
gasLimit?: number;
|
|
79
|
-
gasLimitMultiplier?: number;
|
|
80
|
-
wssReconnect?: {
|
|
81
|
-
auto?: boolean;
|
|
82
|
-
delay?: number;
|
|
83
|
-
maxAttempts?: number;
|
|
84
|
-
onTimeout?: boolean;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
71
|
export default BlockchainConnector;
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
2
17
|
var __assign = (this && this.__assign) || function () {
|
|
3
18
|
__assign = Object.assign || function(t) {
|
|
4
19
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -50,73 +65,53 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
50
65
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
66
|
};
|
|
52
67
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
var
|
|
68
|
+
var BaseConnector_1 = require("./BaseConnector");
|
|
54
69
|
var web3_1 = __importDefault(require("web3"));
|
|
55
70
|
var web3_core_helpers_1 = require("web3-core-helpers");
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
var
|
|
60
|
-
var SuperproToken_1 = __importDefault(require("./staticModels/SuperproToken"));
|
|
61
|
-
var TxManager_1 = __importDefault(require("./utils/TxManager"));
|
|
62
|
-
var app_json_1 = __importDefault(require("./contracts/app.json"));
|
|
71
|
+
var constants_1 = require("../constants");
|
|
72
|
+
var utils_1 = require("../utils");
|
|
73
|
+
var TxManager_1 = __importDefault(require("../utils/TxManager"));
|
|
74
|
+
var app_json_1 = __importDefault(require("../contracts/app.json"));
|
|
63
75
|
var ethers_1 = require("ethers");
|
|
64
76
|
var Jsonrpc = require('web3-core-requestmanager/src/jsonrpc');
|
|
65
|
-
|
|
77
|
+
// TODO: remove this dependencies
|
|
78
|
+
var store_1 = __importDefault(require("../store"));
|
|
79
|
+
var Superpro_1 = __importDefault(require("../staticModels/Superpro"));
|
|
80
|
+
var SuperproToken_1 = __importDefault(require("../staticModels/SuperproToken"));
|
|
81
|
+
var BlockchainConnector = /** @class */ (function (_super) {
|
|
82
|
+
__extends(BlockchainConnector, _super);
|
|
66
83
|
function BlockchainConnector() {
|
|
84
|
+
return _super.call(this) || this;
|
|
67
85
|
}
|
|
68
|
-
BlockchainConnector.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
});
|
|
74
|
-
});
|
|
86
|
+
BlockchainConnector.getInstance = function () {
|
|
87
|
+
if (!BlockchainConnector.instance) {
|
|
88
|
+
BlockchainConnector.instance = new BlockchainConnector();
|
|
89
|
+
}
|
|
90
|
+
return BlockchainConnector.instance;
|
|
75
91
|
};
|
|
76
|
-
|
|
77
|
-
|
|
92
|
+
// TODO: remove this
|
|
93
|
+
BlockchainConnector.prototype.getContract = function (transactionOptions) {
|
|
94
|
+
this.checkIfInitialized();
|
|
78
95
|
if (transactionOptions === null || transactionOptions === void 0 ? void 0 : transactionOptions.web3) {
|
|
79
96
|
return new transactionOptions.web3.eth.Contract(app_json_1.default.abi, Superpro_1.default.address);
|
|
80
97
|
}
|
|
81
|
-
return
|
|
98
|
+
return _super.prototype.getContract.call(this);
|
|
82
99
|
};
|
|
83
100
|
/**
|
|
84
101
|
* Function for connecting to blockchain
|
|
85
102
|
* Used to setting up settings for blockchain connector
|
|
86
103
|
* Needs to run this function before using blockchain connector
|
|
87
104
|
*/
|
|
88
|
-
BlockchainConnector.
|
|
105
|
+
BlockchainConnector.prototype.initialize = function (config) {
|
|
89
106
|
return __awaiter(this, void 0, void 0, function () {
|
|
90
|
-
var url,
|
|
107
|
+
var url, _a;
|
|
91
108
|
return __generator(this, function (_b) {
|
|
92
109
|
switch (_b.label) {
|
|
93
110
|
case 0:
|
|
111
|
+
this.logger.trace(config, "Initializing");
|
|
94
112
|
url = (config === null || config === void 0 ? void 0 : config.blockchainUrl) || constants_1.defaultBlockchainUrl;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
store_1.default.web3Https = new web3_1.default(this.providerHttps);
|
|
98
|
-
}
|
|
99
|
-
if (this.provider) {
|
|
100
|
-
if (this.provider instanceof web3_1.default.providers.WebsocketProvider) {
|
|
101
|
-
this.provider.reset();
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (/^(ws)|(wss)/.test(url)) {
|
|
105
|
-
reconnectOptions = Object.assign({
|
|
106
|
-
auto: true,
|
|
107
|
-
delay: 5000,
|
|
108
|
-
maxAttempts: 5,
|
|
109
|
-
onTimeout: false,
|
|
110
|
-
}, config.wssReconnect);
|
|
111
|
-
this.provider = new web3_1.default.providers.WebsocketProvider(url, {
|
|
112
|
-
reconnect: reconnectOptions,
|
|
113
|
-
});
|
|
114
|
-
store_1.default.web3 = new web3_1.default(this.provider);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
this.provider = new web3_1.default.providers.HttpProvider(url);
|
|
118
|
-
store_1.default.web3 = new web3_1.default(this.provider);
|
|
119
|
-
}
|
|
113
|
+
this.provider = new web3_1.default.providers.HttpProvider(url);
|
|
114
|
+
store_1.default.web3Https = new web3_1.default(this.provider);
|
|
120
115
|
if (config === null || config === void 0 ? void 0 : config.gasPrice)
|
|
121
116
|
store_1.default.gasPrice = config.gasPrice;
|
|
122
117
|
if (config === null || config === void 0 ? void 0 : config.gasLimit)
|
|
@@ -124,15 +119,14 @@ var BlockchainConnector = /** @class */ (function () {
|
|
|
124
119
|
if (config === null || config === void 0 ? void 0 : config.gasLimitMultiplier)
|
|
125
120
|
store_1.default.gasLimitMultiplier = config.gasLimitMultiplier;
|
|
126
121
|
Superpro_1.default.address = config.contractAddress;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
_b.sent();
|
|
130
|
-
TxManager_1.default.init(store_1.default.web3);
|
|
131
|
-
store_1.default.isInitialized = true;
|
|
122
|
+
this.contract = new store_1.default.web3Https.eth.Contract(app_json_1.default.abi, Superpro_1.default.address);
|
|
123
|
+
TxManager_1.default.init(store_1.default.web3Https);
|
|
132
124
|
_a = SuperproToken_1.default;
|
|
133
|
-
return [4 /*yield*/, Superpro_1.default.getTokenAddress()];
|
|
134
|
-
case
|
|
135
|
-
_a.
|
|
125
|
+
return [4 /*yield*/, Superpro_1.default.getTokenAddress(this.contract)];
|
|
126
|
+
case 1:
|
|
127
|
+
_a.addressHttps = _b.sent();
|
|
128
|
+
this.initialized = true;
|
|
129
|
+
this.logger.trace("Initialized");
|
|
136
130
|
return [2 /*return*/];
|
|
137
131
|
}
|
|
138
132
|
});
|
|
@@ -142,15 +136,15 @@ var BlockchainConnector = /** @class */ (function () {
|
|
|
142
136
|
* Function for connecting provider action account
|
|
143
137
|
* Needs to run this function before using any set methods in blockchain connector
|
|
144
138
|
*/
|
|
145
|
-
BlockchainConnector.
|
|
139
|
+
BlockchainConnector.prototype.initializeActionAccount = function (actionAccountKey, manageNonce) {
|
|
146
140
|
if (manageNonce === void 0) { manageNonce = true; }
|
|
147
141
|
return __awaiter(this, void 0, void 0, function () {
|
|
148
142
|
var actionAccount;
|
|
149
143
|
return __generator(this, function (_a) {
|
|
150
144
|
switch (_a.label) {
|
|
151
145
|
case 0:
|
|
152
|
-
|
|
153
|
-
actionAccount = store_1.default.
|
|
146
|
+
this.checkIfInitialized();
|
|
147
|
+
actionAccount = store_1.default.web3Https.eth.accounts.wallet.add(actionAccountKey).address;
|
|
154
148
|
if (!store_1.default.actionAccount)
|
|
155
149
|
store_1.default.actionAccount = actionAccount;
|
|
156
150
|
if (!store_1.default.keys[actionAccount])
|
|
@@ -170,23 +164,23 @@ var BlockchainConnector = /** @class */ (function () {
|
|
|
170
164
|
/**
|
|
171
165
|
* Returns balance of blockchain platform tokens in wei
|
|
172
166
|
*/
|
|
173
|
-
BlockchainConnector.getBalance = function (address) {
|
|
167
|
+
BlockchainConnector.prototype.getBalance = function (address) {
|
|
174
168
|
return __awaiter(this, void 0, void 0, function () {
|
|
175
169
|
return __generator(this, function (_a) {
|
|
176
|
-
|
|
177
|
-
return [2 /*return*/, store_1.default.
|
|
170
|
+
this.checkIfInitialized();
|
|
171
|
+
return [2 /*return*/, store_1.default.web3Https.eth.getBalance(address)];
|
|
178
172
|
});
|
|
179
173
|
});
|
|
180
174
|
};
|
|
181
|
-
BlockchainConnector.getTimestamp = function () {
|
|
175
|
+
BlockchainConnector.prototype.getTimestamp = function () {
|
|
182
176
|
var _a;
|
|
183
177
|
return __awaiter(this, void 0, void 0, function () {
|
|
184
178
|
var block;
|
|
185
179
|
return __generator(this, function (_b) {
|
|
186
180
|
switch (_b.label) {
|
|
187
181
|
case 0:
|
|
188
|
-
|
|
189
|
-
return [4 /*yield*/, ((_a = store_1.default.
|
|
182
|
+
this.checkIfInitialized();
|
|
183
|
+
return [4 /*yield*/, ((_a = store_1.default.web3Https) === null || _a === void 0 ? void 0 : _a.eth.getBlock("latest"))];
|
|
190
184
|
case 1:
|
|
191
185
|
block = _b.sent();
|
|
192
186
|
return [2 /*return*/, block.timestamp];
|
|
@@ -199,18 +193,18 @@ var BlockchainConnector = /** @class */ (function () {
|
|
|
199
193
|
* @param txHash - transaction hash
|
|
200
194
|
* @returns {Promise<EventData[]>} - Transaction events info
|
|
201
195
|
*/
|
|
202
|
-
BlockchainConnector.getTransactionEvents = function (txHash) {
|
|
196
|
+
BlockchainConnector.prototype.getTransactionEvents = function (txHash) {
|
|
203
197
|
return __awaiter(this, void 0, void 0, function () {
|
|
204
198
|
var parseReceiptEvents, receipt, tokenEvents, events, eventData, _i, events_1, event, data, dataValues, i;
|
|
205
199
|
return __generator(this, function (_a) {
|
|
206
200
|
switch (_a.label) {
|
|
207
201
|
case 0:
|
|
208
|
-
|
|
202
|
+
this.checkIfInitialized();
|
|
209
203
|
parseReceiptEvents = require("web3-parse-receipt-events");
|
|
210
|
-
return [4 /*yield*/, store_1.default.
|
|
204
|
+
return [4 /*yield*/, store_1.default.web3Https.eth.getTransactionReceipt(txHash)];
|
|
211
205
|
case 1:
|
|
212
206
|
receipt = _a.sent();
|
|
213
|
-
tokenEvents = parseReceiptEvents(app_json_1.default.abi, SuperproToken_1.default.
|
|
207
|
+
tokenEvents = parseReceiptEvents(app_json_1.default.abi, SuperproToken_1.default.addressHttps, receipt);
|
|
214
208
|
parseReceiptEvents(app_json_1.default.abi, Superpro_1.default.address, receipt); // don't remove
|
|
215
209
|
events = Object.values(tokenEvents.events || {});
|
|
216
210
|
eventData = [];
|
|
@@ -242,17 +236,17 @@ var BlockchainConnector = /** @class */ (function () {
|
|
|
242
236
|
* @param callback - function for processing created TEE offer
|
|
243
237
|
* @return unsubscribe - unsubscribe function from event
|
|
244
238
|
*/
|
|
245
|
-
BlockchainConnector.getLastBlockInfo = function () {
|
|
239
|
+
BlockchainConnector.prototype.getLastBlockInfo = function () {
|
|
246
240
|
return __awaiter(this, void 0, void 0, function () {
|
|
247
241
|
var index, hash;
|
|
248
242
|
return __generator(this, function (_a) {
|
|
249
243
|
switch (_a.label) {
|
|
250
244
|
case 0:
|
|
251
|
-
|
|
252
|
-
return [4 /*yield*/, store_1.default.
|
|
245
|
+
this.checkIfInitialized();
|
|
246
|
+
return [4 /*yield*/, store_1.default.web3Https.eth.getBlockNumber()];
|
|
253
247
|
case 1:
|
|
254
248
|
index = _a.sent();
|
|
255
|
-
return [4 /*yield*/, store_1.default.
|
|
249
|
+
return [4 /*yield*/, store_1.default.web3Https.eth.getBlock(index)];
|
|
256
250
|
case 2:
|
|
257
251
|
hash = (_a.sent()).hash;
|
|
258
252
|
return [2 /*return*/, {
|
|
@@ -268,22 +262,22 @@ var BlockchainConnector = /** @class */ (function () {
|
|
|
268
262
|
* @param txHash - transaction hash
|
|
269
263
|
* @returns {Promise<TransactionReceipt>} - Transaction reciept
|
|
270
264
|
*/
|
|
271
|
-
BlockchainConnector.getTransactionReceipt = function (txHash) {
|
|
265
|
+
BlockchainConnector.prototype.getTransactionReceipt = function (txHash) {
|
|
272
266
|
return __awaiter(this, void 0, void 0, function () {
|
|
273
267
|
return __generator(this, function (_a) {
|
|
274
|
-
|
|
275
|
-
return [2 /*return*/, store_1.default.
|
|
268
|
+
this.checkIfInitialized();
|
|
269
|
+
return [2 /*return*/, store_1.default.web3Https.eth.getTransactionReceipt(txHash)];
|
|
276
270
|
});
|
|
277
271
|
});
|
|
278
272
|
};
|
|
279
273
|
/**
|
|
280
274
|
* Returns balance of blockchain platform tokens in wei
|
|
281
275
|
*/
|
|
282
|
-
BlockchainConnector.transfer = function (to, amount, transactionOptions) {
|
|
276
|
+
BlockchainConnector.prototype.transfer = function (to, amount, transactionOptions) {
|
|
283
277
|
return __awaiter(this, void 0, void 0, function () {
|
|
284
278
|
var transaction;
|
|
285
279
|
return __generator(this, function (_a) {
|
|
286
|
-
|
|
280
|
+
this.checkIfInitialized();
|
|
287
281
|
(0, utils_1.checkIfActionAccountInitialized)(transactionOptions);
|
|
288
282
|
transaction = {
|
|
289
283
|
to: to,
|
|
@@ -298,24 +292,24 @@ var BlockchainConnector = /** @class */ (function () {
|
|
|
298
292
|
* @param address - wallet address
|
|
299
293
|
* @returns {Promise<number>} - Transactions count
|
|
300
294
|
*/
|
|
301
|
-
BlockchainConnector.getTransactionCount = function (address, status) {
|
|
295
|
+
BlockchainConnector.prototype.getTransactionCount = function (address, status) {
|
|
302
296
|
return __awaiter(this, void 0, void 0, function () {
|
|
303
297
|
return __generator(this, function (_a) {
|
|
304
|
-
|
|
298
|
+
this.checkIfInitialized();
|
|
305
299
|
if (status) {
|
|
306
|
-
return [2 /*return*/, store_1.default.
|
|
300
|
+
return [2 /*return*/, store_1.default.web3Https.eth.getTransactionCount(address, status)];
|
|
307
301
|
}
|
|
308
302
|
else {
|
|
309
|
-
return [2 /*return*/, store_1.default.
|
|
303
|
+
return [2 /*return*/, store_1.default.web3Https.eth.getTransactionCount(address)];
|
|
310
304
|
}
|
|
311
305
|
return [2 /*return*/];
|
|
312
306
|
});
|
|
313
307
|
});
|
|
314
308
|
};
|
|
315
|
-
BlockchainConnector.getAddressByKey = function (pk) {
|
|
309
|
+
BlockchainConnector.prototype.getAddressByKey = function (pk) {
|
|
316
310
|
return new ethers_1.Wallet(pk).address;
|
|
317
311
|
};
|
|
318
|
-
BlockchainConnector.executeBatchAsync = function (batch) {
|
|
312
|
+
BlockchainConnector.prototype.executeBatchAsync = function (batch) {
|
|
319
313
|
return __awaiter(this, void 0, void 0, function () {
|
|
320
314
|
return __generator(this, function (_a) {
|
|
321
315
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
@@ -352,14 +346,14 @@ var BlockchainConnector = /** @class */ (function () {
|
|
|
352
346
|
* lastBlock, - number of last fetched block (can be used to start fetching from this block next time)
|
|
353
347
|
* }>}
|
|
354
348
|
*/
|
|
355
|
-
BlockchainConnector.getTransactions = function (addresses, startBlock, lastBlock, batchSize) {
|
|
349
|
+
BlockchainConnector.prototype.getTransactions = function (addresses, startBlock, lastBlock, batchSize) {
|
|
356
350
|
if (batchSize === void 0) { batchSize = constants_1.BLOCK_SIZE_TO_FETCH_TRANSACTION; }
|
|
357
351
|
return __awaiter(this, void 0, void 0, function () {
|
|
358
352
|
var blockchainLastBlock, transactionsByAddress, batch, getBlock, batchLastBlock, blockNumber, blocks;
|
|
359
353
|
return __generator(this, function (_a) {
|
|
360
354
|
switch (_a.label) {
|
|
361
355
|
case 0:
|
|
362
|
-
|
|
356
|
+
this.checkIfInitialized();
|
|
363
357
|
return [4 /*yield*/, store_1.default.web3Https.eth.getBlockNumber()];
|
|
364
358
|
case 1:
|
|
365
359
|
blockchainLastBlock = _a.sent();
|
|
@@ -410,15 +404,10 @@ var BlockchainConnector = /** @class */ (function () {
|
|
|
410
404
|
});
|
|
411
405
|
});
|
|
412
406
|
};
|
|
413
|
-
BlockchainConnector.
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if (this.providerHttps)
|
|
417
|
-
this.providerHttps.disconnect();
|
|
418
|
-
store_1.default.isInitialized = false;
|
|
419
|
-
store_1.default.web3 = undefined;
|
|
407
|
+
BlockchainConnector.prototype.shutdown = function () {
|
|
408
|
+
_super.prototype.shutdown.call(this);
|
|
409
|
+
store_1.default.web3Https = undefined;
|
|
420
410
|
};
|
|
421
|
-
BlockchainConnector.logger = logger_1.default.child({ className: "BlockchainConnector" });
|
|
422
411
|
return BlockchainConnector;
|
|
423
|
-
}());
|
|
412
|
+
}(BaseConnector_1.BaseConnector));
|
|
424
413
|
exports.default = BlockchainConnector;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BaseConnector, Config } from "./BaseConnector";
|
|
2
|
+
declare class BlockchainEventsListener extends BaseConnector {
|
|
3
|
+
private static instance;
|
|
4
|
+
private constructor();
|
|
5
|
+
static getInstance(): BlockchainEventsListener;
|
|
6
|
+
/**
|
|
7
|
+
* Function for connecting to blockchain using web socket
|
|
8
|
+
* Needs to run this function before using events
|
|
9
|
+
*/
|
|
10
|
+
initialize(config: Config): Promise<void>;
|
|
11
|
+
shutdown(): void;
|
|
12
|
+
}
|
|
13
|
+
export default BlockchainEventsListener;
|