hive-stream 2.0.5 → 3.0.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/.claude/settings.local.json +12 -0
- package/.env.example +2 -2
- package/.travis.yml +11 -11
- package/CHANGELOG.md +166 -0
- package/CLAUDE.md +75 -0
- package/LICENSE +21 -21
- package/README.md +338 -238
- package/dist/actions.d.ts +41 -10
- package/dist/actions.js +126 -23
- package/dist/actions.js.map +1 -1
- package/dist/adapters/base.adapter.d.ts +25 -25
- package/dist/adapters/base.adapter.js +63 -49
- package/dist/adapters/base.adapter.js.map +1 -1
- package/dist/adapters/mongodb.adapter.d.ts +50 -37
- package/dist/adapters/mongodb.adapter.js +363 -158
- package/dist/adapters/mongodb.adapter.js.map +1 -1
- package/dist/adapters/postgresql.adapter.d.ts +49 -0
- package/dist/adapters/postgresql.adapter.js +507 -0
- package/dist/adapters/postgresql.adapter.js.map +1 -0
- package/dist/adapters/sqlite.adapter.d.ts +40 -41
- package/dist/adapters/sqlite.adapter.js +470 -397
- package/dist/adapters/sqlite.adapter.js.map +1 -1
- package/dist/api.d.ts +6 -6
- package/dist/api.js +95 -55
- package/dist/api.js.map +1 -1
- package/dist/config.d.ts +16 -16
- package/dist/config.js +18 -18
- package/dist/config.js.map +1 -1
- package/dist/contracts/coinflip.contract.d.ts +27 -14
- package/dist/contracts/coinflip.contract.js +253 -94
- package/dist/contracts/coinflip.contract.js.map +1 -1
- package/dist/contracts/dice.contract.d.ts +37 -29
- package/dist/contracts/dice.contract.js +282 -155
- package/dist/contracts/dice.contract.js.map +1 -1
- package/dist/contracts/lotto.contract.d.ts +20 -20
- package/dist/contracts/lotto.contract.js +246 -246
- package/dist/contracts/nft.contract.d.ts +24 -0
- package/dist/contracts/nft.contract.js +533 -0
- package/dist/contracts/nft.contract.js.map +1 -0
- package/dist/contracts/token.contract.d.ts +18 -0
- package/dist/contracts/token.contract.js +263 -0
- package/dist/contracts/token.contract.js.map +1 -0
- package/dist/exchanges/bittrex.d.ts +6 -6
- package/dist/exchanges/bittrex.js +34 -34
- package/dist/exchanges/coingecko.d.ts +5 -0
- package/dist/exchanges/coingecko.js +40 -0
- package/dist/exchanges/coingecko.js.map +1 -0
- package/dist/exchanges/exchange.d.ts +9 -9
- package/dist/exchanges/exchange.js +26 -26
- package/dist/hive-rates.d.ts +9 -9
- package/dist/hive-rates.js +121 -75
- package/dist/hive-rates.js.map +1 -1
- package/dist/index.d.ts +12 -11
- package/dist/index.js +33 -32
- package/dist/index.js.map +1 -1
- package/dist/streamer.d.ts +140 -93
- package/dist/streamer.js +793 -545
- package/dist/streamer.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +25 -25
- package/dist/test.js.map +1 -1
- package/dist/types/hive-stream.d.ts +35 -6
- package/dist/types/hive-stream.js +2 -2
- package/dist/utils.d.ts +27 -27
- package/dist/utils.js +271 -261
- package/dist/utils.js.map +1 -1
- package/ecosystem.config.js +17 -17
- package/jest.config.js +8 -8
- package/package.json +53 -48
- package/test-contract-block.md +18 -18
- package/tests/actions.spec.ts +252 -0
- package/tests/adapters/actions-persistence.spec.ts +144 -0
- package/tests/adapters/postgresql.adapter.spec.ts +127 -0
- package/tests/adapters/sqlite.adapter.spec.ts +180 -42
- package/tests/contracts/coinflip.contract.spec.ts +221 -131
- package/tests/contracts/dice.contract.spec.ts +202 -159
- package/tests/contracts/entrants.json +728 -728
- package/tests/contracts/lotto.contract.spec.ts +323 -323
- package/tests/contracts/nft.contract.spec.ts +948 -0
- package/tests/contracts/token.contract.spec.ts +334 -0
- package/tests/helpers/mock-adapter.ts +214 -0
- package/tests/setup.ts +29 -18
- package/tests/streamer-actions.spec.ts +263 -0
- package/tests/streamer.spec.ts +248 -151
- package/tests/utils.spec.ts +91 -94
- package/tsconfig.build.json +3 -22
- package/tslint.json +20 -20
- package/wallaby.js +26 -26
- package/.env +0 -3
package/dist/hive-rates.js
CHANGED
|
@@ -1,76 +1,122 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HiveRates = void 0;
|
|
4
|
-
const
|
|
5
|
-
class HiveRates {
|
|
6
|
-
fiatRates =
|
|
7
|
-
hiveRates =
|
|
8
|
-
lastFetch;
|
|
9
|
-
oneHour = 1000 * 60 * 60;
|
|
10
|
-
async fetchRates() {
|
|
11
|
-
let hiveAverage = 0;
|
|
12
|
-
let hbdAverage = 0;
|
|
13
|
-
let hiveCount = 0;
|
|
14
|
-
let hbdCount = 0;
|
|
15
|
-
let exchangesUpdated = false;
|
|
16
|
-
const exchanges = [new
|
|
17
|
-
for (const exchange of exchanges) {
|
|
18
|
-
const updated = await exchange.updateRates();
|
|
19
|
-
if (updated) {
|
|
20
|
-
exchangesUpdated = true;
|
|
21
|
-
const usdHiveRate = exchange.rateUsdHive;
|
|
22
|
-
const usdHbdRate = exchange.rateUsdHbd;
|
|
23
|
-
if (usdHiveRate && usdHiveRate > 0) {
|
|
24
|
-
hiveAverage += usdHiveRate;
|
|
25
|
-
hiveCount++;
|
|
26
|
-
}
|
|
27
|
-
if (usdHbdRate
|
|
28
|
-
hbdAverage += usdHbdRate;
|
|
29
|
-
hbdCount++;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
const fiatRates = await this.getFiatRates();
|
|
34
|
-
if (hiveCount === 0 && hbdCount === 0) {
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
if (hiveCount > 0) {
|
|
38
|
-
hiveAverage = hiveAverage / hiveCount;
|
|
39
|
-
}
|
|
40
|
-
if (hbdCount > 0) {
|
|
41
|
-
hbdAverage = hbdAverage / hbdCount;
|
|
42
|
-
}
|
|
43
|
-
for (const [symbol, value] of Object.entries(this.fiatRates)) {
|
|
44
|
-
|
|
45
|
-
this.hiveRates[
|
|
46
|
-
this.hiveRates[`${symbol}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HiveRates = void 0;
|
|
4
|
+
const coingecko_1 = require("./exchanges/coingecko");
|
|
5
|
+
class HiveRates {
|
|
6
|
+
fiatRates = {};
|
|
7
|
+
hiveRates = {};
|
|
8
|
+
lastFetch;
|
|
9
|
+
oneHour = 1000 * 60 * 60;
|
|
10
|
+
async fetchRates() {
|
|
11
|
+
let hiveAverage = 0;
|
|
12
|
+
let hbdAverage = 0;
|
|
13
|
+
let hiveCount = 0;
|
|
14
|
+
let hbdCount = 0;
|
|
15
|
+
let exchangesUpdated = false;
|
|
16
|
+
const exchanges = [new coingecko_1.CoinGeckoExchange()];
|
|
17
|
+
for (const exchange of exchanges) {
|
|
18
|
+
const updated = await exchange.updateRates();
|
|
19
|
+
if (updated) {
|
|
20
|
+
exchangesUpdated = true;
|
|
21
|
+
const usdHiveRate = exchange.rateUsdHive;
|
|
22
|
+
const usdHbdRate = exchange.rateUsdHbd;
|
|
23
|
+
if (usdHiveRate && usdHiveRate > 0) {
|
|
24
|
+
hiveAverage += usdHiveRate;
|
|
25
|
+
hiveCount++;
|
|
26
|
+
}
|
|
27
|
+
if (usdHbdRate && usdHbdRate > 0) {
|
|
28
|
+
hbdAverage += usdHbdRate;
|
|
29
|
+
hbdCount++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const fiatRates = await this.getFiatRates();
|
|
34
|
+
if (hiveCount === 0 && hbdCount === 0) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (hiveCount > 0) {
|
|
38
|
+
hiveAverage = hiveAverage / hiveCount;
|
|
39
|
+
}
|
|
40
|
+
if (hbdCount > 0) {
|
|
41
|
+
hbdAverage = hbdAverage / hbdCount;
|
|
42
|
+
}
|
|
43
|
+
for (const [symbol, value] of Object.entries(this.fiatRates)) {
|
|
44
|
+
const rate = Number(value);
|
|
45
|
+
this.hiveRates[`USD_${symbol}`] = rate;
|
|
46
|
+
this.hiveRates[`${symbol}_HIVE`] = hiveAverage * rate;
|
|
47
|
+
this.hiveRates[`${symbol}_HBD`] = hbdAverage * rate;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
fiatToHiveRate(fiatSymbol, hiveSymbol) {
|
|
52
|
+
if (!this.hiveRates) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (!this.hiveRates[`${fiatSymbol}_${hiveSymbol}`]) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return this.hiveRates[`${fiatSymbol}_${hiveSymbol}`];
|
|
59
|
+
}
|
|
60
|
+
async getFiatRates(base = 'USD') {
|
|
61
|
+
const HOUR_AGO = Date.now() - this.oneHour;
|
|
62
|
+
if (this.lastFetch && this.lastFetch > HOUR_AGO) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const baseKey = base.toLowerCase();
|
|
67
|
+
let response = null;
|
|
68
|
+
let exchangeRates = null;
|
|
69
|
+
// Try primary endpoint first
|
|
70
|
+
try {
|
|
71
|
+
const primaryUrl = `https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/${baseKey}.json`;
|
|
72
|
+
const request = await fetch(primaryUrl);
|
|
73
|
+
if (request.ok) {
|
|
74
|
+
response = await request.json();
|
|
75
|
+
exchangeRates = response?.[baseKey];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (primaryError) {
|
|
79
|
+
console.warn('Primary API endpoint failed:', primaryError.message);
|
|
80
|
+
}
|
|
81
|
+
// If primary fails, try the Cloudflare fallback
|
|
82
|
+
if (!exchangeRates) {
|
|
83
|
+
try {
|
|
84
|
+
const fallbackUrl = `https://latest.currency-api.pages.dev/v1/currencies/${baseKey}.json`;
|
|
85
|
+
const request = await fetch(fallbackUrl);
|
|
86
|
+
if (request.ok) {
|
|
87
|
+
response = await request.json();
|
|
88
|
+
exchangeRates = response?.[baseKey];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (fallbackError) {
|
|
92
|
+
console.warn('Fallback API endpoint failed:', fallbackError.message);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!exchangeRates || typeof exchangeRates !== 'object') {
|
|
96
|
+
console.error('No valid exchange rates found in API response');
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
// Convert the currency codes to uppercase to match the previous format
|
|
100
|
+
const upperCaseRates = {};
|
|
101
|
+
for (const [currency, rate] of Object.entries(exchangeRates)) {
|
|
102
|
+
if (typeof rate === 'number' && !isNaN(rate)) {
|
|
103
|
+
upperCaseRates[currency.toUpperCase()] = rate;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (Object.keys(upperCaseRates).length === 0) {
|
|
107
|
+
console.error('No valid currency rates found');
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
this.fiatRates = upperCaseRates;
|
|
111
|
+
this.lastFetch = Date.now();
|
|
112
|
+
console.log(`Successfully fetched ${Object.keys(upperCaseRates).length} currency rates with base ${base}`);
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
console.error('Error fetching fiat rates:', error);
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.HiveRates = HiveRates;
|
|
76
122
|
//# sourceMappingURL=hive-rates.js.map
|
package/dist/hive-rates.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hive-rates.js","sourceRoot":"","sources":["../src/hive-rates.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"hive-rates.js","sourceRoot":"","sources":["../src/hive-rates.ts"],"names":[],"mappings":";;;AAAA,qDAA0D;AAE1D,MAAa,SAAS;IACV,SAAS,GAAG,EAAE,CAAC;IACf,SAAS,GAAG,EAAE,CAAC;IACf,SAAS,CAAC;IACV,OAAO,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;IAE1B,KAAK,CAAC,UAAU;QACnB,IAAI,WAAW,GAAG,CAAC,CAAC;QACpB,IAAI,UAAU,GAAG,CAAC,CAAC;QAEnB,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,IAAI,QAAQ,GAAG,CAAC,CAAC;QAEjB,IAAI,gBAAgB,GAAG,KAAK,CAAC;QAE7B,MAAM,SAAS,GAAG,CAAE,IAAI,6BAAiB,EAAE,CAAE,CAAC;QAE9C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;YAC9B,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;YAE7C,IAAI,OAAO,EAAE;gBACT,gBAAgB,GAAG,IAAI,CAAC;gBAExB,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC;gBACzC,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;gBAEvC,IAAI,WAAW,IAAI,WAAW,GAAG,CAAC,EAAE;oBAChC,WAAW,IAAI,WAAW,CAAC;oBAC3B,SAAS,EAAE,CAAC;iBACf;gBAED,IAAI,UAAU,IAAI,UAAU,GAAG,CAAC,EAAE;oBAC9B,UAAU,IAAI,UAAU,CAAC;oBACzB,QAAQ,EAAE,CAAC;iBACd;aACJ;SACJ;QAED,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QAE5C,IAAI,SAAS,KAAK,CA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,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,EAAE;gBAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;oBAC1C,cAAc,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,GAAG,IAAI,CAAC;iBACjD;aACJ;YAED,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC1C,OAAO,CAAC,KAAK,CAAC,+BAA+B,CAAC,CAAC;gBAC/C,OAAO,KAAK,CAAC;aAChB;YAED,IAAI,CAAC,SAAS,GAAG,cAAc,CAAC;YAChC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAE5B,OAAO,CAAC,GAAG,CAAC,wBAAwB,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,6BAA6B,IAAI,EAAE,CAAC,CAAC;YAC3G,OAAO,IAAI,CAAC;SACf;QAAC,OAAO,KAAK,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;YACnD,OAAO,KAAK,CAAC;SAChB;IACL,CAAC;CACJ;AA9ID,8BA8IC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
export * from './config';
|
|
2
|
-
export * from './streamer';
|
|
3
|
-
export * from './utils';
|
|
4
|
-
export * from './actions';
|
|
5
|
-
export * from './adapters/base.adapter';
|
|
6
|
-
export * from './adapters/sqlite.adapter';
|
|
7
|
-
export * from './adapters/mongodb.adapter';
|
|
8
|
-
export
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export
|
|
1
|
+
export * from './config';
|
|
2
|
+
export * from './streamer';
|
|
3
|
+
export * from './utils';
|
|
4
|
+
export * from './actions';
|
|
5
|
+
export * from './adapters/base.adapter';
|
|
6
|
+
export * from './adapters/sqlite.adapter';
|
|
7
|
+
export * from './adapters/mongodb.adapter';
|
|
8
|
+
export * from './adapters/postgresql.adapter';
|
|
9
|
+
export { DiceContract } from './contracts/dice.contract';
|
|
10
|
+
export { LottoContract } from './contracts/lotto.contract';
|
|
11
|
+
export { CoinflipContract } from './contracts/coinflip.contract';
|
|
12
|
+
export * from './types/hive-stream';
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.CoinflipContract = exports.LottoContract = exports.DiceContract = void 0;
|
|
18
|
-
__exportStar(require("./config"), exports);
|
|
19
|
-
__exportStar(require("./streamer"), exports);
|
|
20
|
-
__exportStar(require("./utils"), exports);
|
|
21
|
-
__exportStar(require("./actions"), exports);
|
|
22
|
-
__exportStar(require("./adapters/base.adapter"), exports);
|
|
23
|
-
__exportStar(require("./adapters/sqlite.adapter"), exports);
|
|
24
|
-
__exportStar(require("./adapters/mongodb.adapter"), exports);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.CoinflipContract = exports.LottoContract = exports.DiceContract = void 0;
|
|
18
|
+
__exportStar(require("./config"), exports);
|
|
19
|
+
__exportStar(require("./streamer"), exports);
|
|
20
|
+
__exportStar(require("./utils"), exports);
|
|
21
|
+
__exportStar(require("./actions"), exports);
|
|
22
|
+
__exportStar(require("./adapters/base.adapter"), exports);
|
|
23
|
+
__exportStar(require("./adapters/sqlite.adapter"), exports);
|
|
24
|
+
__exportStar(require("./adapters/mongodb.adapter"), exports);
|
|
25
|
+
__exportStar(require("./adapters/postgresql.adapter"), exports);
|
|
26
|
+
var dice_contract_1 = require("./contracts/dice.contract");
|
|
27
|
+
Object.defineProperty(exports, "DiceContract", { enumerable: true, get: function () { return dice_contract_1.DiceContract; } });
|
|
28
|
+
var lotto_contract_1 = require("./contracts/lotto.contract");
|
|
29
|
+
Object.defineProperty(exports, "LottoContract", { enumerable: true, get: function () { return lotto_contract_1.LottoContract; } });
|
|
30
|
+
var coinflip_contract_1 = require("./contracts/coinflip.contract");
|
|
31
|
+
Object.defineProperty(exports, "CoinflipContract", { enumerable: true, get: function () { return coinflip_contract_1.CoinflipContract; } });
|
|
32
|
+
// Types
|
|
33
|
+
__exportStar(require("./types/hive-stream"), exports);
|
|
33
34
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6CAA2B;AAC3B,0CAAwB;AACxB,4CAA0B;AAE1B,0DAAwC;AACxC,4DAA0C;AAC1C,6DAA2C;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,6CAA2B;AAC3B,0CAAwB;AACxB,4CAA0B;AAE1B,0DAAwC;AACxC,4DAA0C;AAC1C,6DAA2C;AAC3C,gEAA8C;AAE9C,2DAAyD;AAAhD,6GAAA,YAAY,OAAA;AACrB,6DAA2D;AAAlD,+GAAA,aAAa,OAAA;AACtB,mEAAiE;AAAxD,qHAAA,gBAAgB,OAAA;AAEzB,QAAQ;AACR,sDAAoC"}
|
package/dist/streamer.d.ts
CHANGED
|
@@ -1,93 +1,140 @@
|
|
|
1
|
-
import { AdapterBase } from './adapters/base.adapter';
|
|
2
|
-
import { TimeAction } from './actions';
|
|
3
|
-
import { ConfigInterface } from './config';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
private
|
|
7
|
-
private
|
|
8
|
-
private
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
private
|
|
22
|
-
private
|
|
23
|
-
private
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
private
|
|
27
|
-
private
|
|
28
|
-
private
|
|
29
|
-
private
|
|
30
|
-
private
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
*
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
1
|
+
import { AdapterBase } from './adapters/base.adapter';
|
|
2
|
+
import { TimeAction } from './actions';
|
|
3
|
+
import { ConfigInterface } from './config';
|
|
4
|
+
import { ContractInstance } from './types/hive-stream';
|
|
5
|
+
export declare class Streamer {
|
|
6
|
+
private customJsonSubscriptions;
|
|
7
|
+
private customJsonIdSubscriptions;
|
|
8
|
+
private customJsonHiveEngineSubscriptions;
|
|
9
|
+
private commentSubscriptions;
|
|
10
|
+
private postSubscriptions;
|
|
11
|
+
private transferSubscriptions;
|
|
12
|
+
private attempts;
|
|
13
|
+
private config;
|
|
14
|
+
private client;
|
|
15
|
+
private hive;
|
|
16
|
+
private username;
|
|
17
|
+
private postingKey;
|
|
18
|
+
private activeKey;
|
|
19
|
+
private blockNumberTimeout;
|
|
20
|
+
private latestBlockTimer;
|
|
21
|
+
private lastBlockNumber;
|
|
22
|
+
private blockId;
|
|
23
|
+
private previousBlockId;
|
|
24
|
+
private transactionId;
|
|
25
|
+
private blockTime;
|
|
26
|
+
private latestBlockchainTime;
|
|
27
|
+
private disableAllProcessing;
|
|
28
|
+
private contracts;
|
|
29
|
+
private adapter;
|
|
30
|
+
private actions;
|
|
31
|
+
private lastStateSave;
|
|
32
|
+
private stateSaveInterval;
|
|
33
|
+
private blockProcessingQueue;
|
|
34
|
+
private isProcessingQueue;
|
|
35
|
+
private readonly maxSubscriptions;
|
|
36
|
+
private subscriptionCleanupInterval;
|
|
37
|
+
private actionFrequencyMap;
|
|
38
|
+
private contractCache;
|
|
39
|
+
private blockCache;
|
|
40
|
+
private transactionCache;
|
|
41
|
+
private accountCache;
|
|
42
|
+
private readonly cacheTimeout;
|
|
43
|
+
private readonly maxCacheSize;
|
|
44
|
+
private utils;
|
|
45
|
+
constructor(userConfig?: Partial<ConfigInterface>);
|
|
46
|
+
private _initializeAdapter;
|
|
47
|
+
registerAdapter(adapter: AdapterBase): Promise<void>;
|
|
48
|
+
getAdapter(): AdapterBase;
|
|
49
|
+
/**
|
|
50
|
+
* Register a new action with improved validation and persistence
|
|
51
|
+
*/
|
|
52
|
+
registerAction(action: TimeAction): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Validate that the contract and method exist for the action
|
|
55
|
+
*/
|
|
56
|
+
private validateActionContract;
|
|
57
|
+
/**
|
|
58
|
+
* Remove an action by ID
|
|
59
|
+
*/
|
|
60
|
+
removeAction(actionId: string): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Get all registered actions
|
|
63
|
+
*/
|
|
64
|
+
getActions(): TimeAction[];
|
|
65
|
+
/**
|
|
66
|
+
* Get action by ID
|
|
67
|
+
*/
|
|
68
|
+
getAction(actionId: string): TimeAction | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Enable/disable an action
|
|
71
|
+
*/
|
|
72
|
+
setActionEnabled(actionId: string, enabled: boolean): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Save actions to disk asynchronously
|
|
75
|
+
*/
|
|
76
|
+
private saveActionsToDisk;
|
|
77
|
+
/**
|
|
78
|
+
* Resets a specific action time value
|
|
79
|
+
*/
|
|
80
|
+
resetAction(id: string): Promise<boolean>;
|
|
81
|
+
registerContract(name: string, contract: ContractInstance): this;
|
|
82
|
+
unregisterContract(name: string): void;
|
|
83
|
+
/**
|
|
84
|
+
* setConfig
|
|
85
|
+
*
|
|
86
|
+
* Allows specific configuration settings to be overridden
|
|
87
|
+
*
|
|
88
|
+
* @param config
|
|
89
|
+
*/
|
|
90
|
+
setConfig(config: Partial<ConfigInterface>): this;
|
|
91
|
+
/**
|
|
92
|
+
* Start
|
|
93
|
+
*
|
|
94
|
+
* Starts the streamer bot to get blocks from the Hive API
|
|
95
|
+
*
|
|
96
|
+
*/
|
|
97
|
+
start(): Promise<Streamer>;
|
|
98
|
+
/**
|
|
99
|
+
* Stop
|
|
100
|
+
*
|
|
101
|
+
* Stops the streamer from running
|
|
102
|
+
*/
|
|
103
|
+
stop(): Promise<void>;
|
|
104
|
+
private getLatestBlock;
|
|
105
|
+
private getBlock;
|
|
106
|
+
private loadBlock;
|
|
107
|
+
processOperation(op: [string, any], blockNumber: number, blockId: string, prevBlockId: string, trxId: string, blockTime: Date): Promise<void>;
|
|
108
|
+
private processActions;
|
|
109
|
+
/**
|
|
110
|
+
* Execute a single action with proper isolation
|
|
111
|
+
*/
|
|
112
|
+
private executeAction;
|
|
113
|
+
/**
|
|
114
|
+
* Clean up completed or disabled actions to prevent memory leaks
|
|
115
|
+
*/
|
|
116
|
+
private cleanupActions;
|
|
117
|
+
saveStateToDisk(): Promise<void>;
|
|
118
|
+
private saveStateThrottled;
|
|
119
|
+
saveToHiveApi(from: string, data: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
120
|
+
getAccountTransfers(account: string, from?: number, limit?: number): Promise<any>;
|
|
121
|
+
transferHiveTokens(from: string, to: string, amount: string, symbol: string, memo?: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
122
|
+
transferHiveTokensMultiple(from: string, accounts: string[], amount: string, symbol: string, memo?: string): Promise<boolean>;
|
|
123
|
+
transferHiveEngineTokens(from: string, to: string, symbol: string, quantity: string, memo?: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
124
|
+
transferHiveEngineTokensMultiple(from: string, accounts: any[], symbol: string, memo?: string, amount?: string): Promise<void>;
|
|
125
|
+
issueHiveEngineTokens(from: string, to: string, symbol: string, quantity: string, memo?: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
126
|
+
issueHiveEngineTokensMultiple(from: string, accounts: any[], symbol: string, memo?: string, amount?: string): Promise<void>;
|
|
127
|
+
upvote(votePercentage: string, username: string, permlink: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
128
|
+
downvote(votePercentage: string, username: string, permlink: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
129
|
+
getTransaction(blockNumber: number, transactionId: string): Promise<import("@hiveio/dhive").SignedTransaction>;
|
|
130
|
+
verifyTransfer(transaction: any, from: string, to: string, amount: string): Promise<boolean>;
|
|
131
|
+
onComment(callback: any): void;
|
|
132
|
+
onPost(callback: any): void;
|
|
133
|
+
onTransfer(account: string, callback: () => void): void;
|
|
134
|
+
onCustomJson(callback: any): void;
|
|
135
|
+
onCustomJsonId(callback: any, id: string): void;
|
|
136
|
+
onHiveEngine(callback: any): void;
|
|
137
|
+
private cleanupSubscriptions;
|
|
138
|
+
removeTransferSubscription(account: string): void;
|
|
139
|
+
removeCustomJsonIdSubscription(id: string): void;
|
|
140
|
+
}
|