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/tests/utils.spec.ts
CHANGED
|
@@ -1,95 +1,92 @@
|
|
|
1
|
-
import { Utils } from './../src/utils';
|
|
2
|
-
|
|
3
|
-
describe('Utils', () => {
|
|
4
|
-
|
|
5
|
-
describe('Round Precision', () => {
|
|
6
|
-
test('Properly rounds precision of number to 3 places', () => {
|
|
7
|
-
const value = 99.299223;
|
|
8
|
-
|
|
9
|
-
expect(Utils.roundPrecision(value, 3)).toStrictEqual(99.299);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
test('Properly rounds precision of number up and to 3 places', () => {
|
|
13
|
-
const value = 99.2966;
|
|
14
|
-
|
|
15
|
-
expect(Utils.roundPrecision(value, 3)).toStrictEqual(99.297);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
test('Invalid numeric values passed', () => {
|
|
19
|
-
expect(Utils.roundPrecision('dasd', 3)).toBeNaN();
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('Should generate two deterministic numbers', () => {
|
|
24
|
-
// Should generate a deterministic random number
|
|
25
|
-
expect(Utils.randomNumber('dasdasdas', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(26);
|
|
26
|
-
|
|
27
|
-
expect(Utils.randomNumber('fdfsdfsdfsdfsf', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(43);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('Should shuffle array in a non-deterministic way', () => {
|
|
31
|
-
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
|
|
32
|
-
const arrayCloned = [...array];
|
|
33
|
-
|
|
34
|
-
Utils.shuffle(array);
|
|
35
|
-
|
|
36
|
-
expect(array).not.toMatchObject(arrayCloned);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('Generate String', () => {
|
|
40
|
-
test('Generates a memo 6 characters in length', () => {
|
|
41
|
-
expect(Utils.randomString(6)).toHaveLength(6);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('Generates a memo using default 12 character length', () => {
|
|
45
|
-
expect(Utils.randomString()).toHaveLength(12);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('Random Range', () => {
|
|
50
|
-
test('Should generate a random number between 0 and 10', () => {
|
|
51
|
-
expect(Utils.randomRange(0, 10)).toBeLessThanOrEqual(10);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('Should generate the number 10', () => {
|
|
55
|
-
expect(Utils.randomRange(10, 10)).toStrictEqual(10);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('Only pass min and not max', () => {
|
|
59
|
-
expect(Utils.randomRange(0)).toBeLessThanOrEqual(2000);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('Pass non numeric values to random range', () => {
|
|
63
|
-
expect(Utils.randomRange('dd' as any, 'asjj' as any)).toBeNaN();
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('Convert Hive Amount', () => {
|
|
68
|
-
test('Converts amount', async () => {
|
|
69
|
-
const amount = 25;
|
|
70
|
-
const fiatSymbol = 'USD';
|
|
71
|
-
const hiveSymbol = 'HIVE';
|
|
72
|
-
|
|
73
|
-
(fetch as any)
|
|
74
|
-
.once(JSON.stringify({'
|
|
75
|
-
.once(JSON.stringify({'
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
expect(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
1
|
+
import { Utils } from './../src/utils';
|
|
2
|
+
|
|
3
|
+
describe('Utils', () => {
|
|
4
|
+
|
|
5
|
+
describe('Round Precision', () => {
|
|
6
|
+
test('Properly rounds precision of number to 3 places', () => {
|
|
7
|
+
const value = 99.299223;
|
|
8
|
+
|
|
9
|
+
expect(Utils.roundPrecision(value, 3)).toStrictEqual(99.299);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('Properly rounds precision of number up and to 3 places', () => {
|
|
13
|
+
const value = 99.2966;
|
|
14
|
+
|
|
15
|
+
expect(Utils.roundPrecision(value, 3)).toStrictEqual(99.297);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('Invalid numeric values passed', () => {
|
|
19
|
+
expect(Utils.roundPrecision('dasd', 3)).toBeNaN();
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('Should generate two deterministic numbers', () => {
|
|
24
|
+
// Should generate a deterministic random number
|
|
25
|
+
expect(Utils.randomNumber('dasdasdas', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(26);
|
|
26
|
+
|
|
27
|
+
expect(Utils.randomNumber('fdfsdfsdfsdfsf', '2312fsdfsdfsdf', 'kfjlksdjflksdjf999')).toStrictEqual(43);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('Should shuffle array in a non-deterministic way', () => {
|
|
31
|
+
const array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
|
|
32
|
+
const arrayCloned = [...array];
|
|
33
|
+
|
|
34
|
+
Utils.shuffle(array);
|
|
35
|
+
|
|
36
|
+
expect(array).not.toMatchObject(arrayCloned);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('Generate String', () => {
|
|
40
|
+
test('Generates a memo 6 characters in length', () => {
|
|
41
|
+
expect(Utils.randomString(6)).toHaveLength(6);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('Generates a memo using default 12 character length', () => {
|
|
45
|
+
expect(Utils.randomString()).toHaveLength(12);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('Random Range', () => {
|
|
50
|
+
test('Should generate a random number between 0 and 10', () => {
|
|
51
|
+
expect(Utils.randomRange(0, 10)).toBeLessThanOrEqual(10);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('Should generate the number 10', () => {
|
|
55
|
+
expect(Utils.randomRange(10, 10)).toStrictEqual(10);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('Only pass min and not max', () => {
|
|
59
|
+
expect(Utils.randomRange(0)).toBeLessThanOrEqual(2000);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('Pass non numeric values to random range', () => {
|
|
63
|
+
expect(Utils.randomRange('dd' as any, 'asjj' as any)).toBeNaN();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('Convert Hive Amount', () => {
|
|
68
|
+
test('Converts amount', async () => {
|
|
69
|
+
const amount = 25;
|
|
70
|
+
const fiatSymbol = 'USD';
|
|
71
|
+
const hiveSymbol = 'HIVE';
|
|
72
|
+
|
|
73
|
+
(fetch as any)
|
|
74
|
+
.once(JSON.stringify({'hive':{'usd':0.229951},'hive_dollar':{'usd':0.99805}})) // CoinGecko HIVE/HBD prices
|
|
75
|
+
.once(JSON.stringify({'date':'2025-07-31','usd':{'cad':1.38249328,'hkd':7.84969296,'isk':124.40606356,'php':58.05502018,'dkk':6.52928985,'huf':350.43324994,'czk':21.5182452,'gbp':0.75416895,'ron':4.43971718,'sek':9.77798397,'idr':16437.63140133,'inr':87.62805331,'brl':5.57697598,'rub':81.01377784,'hrk':6.59133796,'jpy':148.8919467,'thb':32.6921739,'chf':0.81307502,'eur':0.87482089,'myr':4.2526877,'bgn':1.71100093,'try':40.59221009,'cny':7.19127973,'nok':10.30319488,'nzd':1.69157541,'zar':17.98114271,'usd':1.0,'mxn':18.84341987,'sgd':1.29367688,'aud':1.5491513,'ils':3.38255864,'krw':1389.43611488,'pln':3.73980141}})); // Currency API fiat rates
|
|
76
|
+
|
|
77
|
+
const value = await Utils.convertHiveAmount(amount, fiatSymbol, hiveSymbol);
|
|
78
|
+
|
|
79
|
+
expect(fetch).toBeCalledWith('https://api.coingecko.com/api/v3/simple/price?ids=hive,hive_dollar&vs_currencies=usd');
|
|
80
|
+
expect(fetch).toBeCalledWith('https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.json');
|
|
81
|
+
|
|
82
|
+
expect(value).toStrictEqual(Number((amount / 0.229951).toFixed(3))); // amount / HIVE price from CoinGecko (fiat to HIVE conversion)
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe('Get transfer URL', () => {
|
|
87
|
+
test('Gets a transfer URL string', () => {
|
|
88
|
+
expect(Utils.getTransferUrl('beggars', 'TEST123', '10.000 HIVE', 'http://localhost:5001')).toStrictEqual(`https://hivesigner.com/sign/transfer?to=beggars&memo=TEST123&amount=10.000 HIVE&redirect_uri=http://localhost:5001`);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
95
92
|
});
|
package/tsconfig.build.json
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
|
-
{
|
|
2
|
-
"
|
|
3
|
-
|
|
4
|
-
"esModuleInterop": true,
|
|
5
|
-
"target": "esnext",
|
|
6
|
-
"allowSyntheticDefaultImports": true,
|
|
7
|
-
"emitDecoratorMetadata": true,
|
|
8
|
-
"experimentalDecorators": true,
|
|
9
|
-
"resolveJsonModule": true,
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"declaration": true,
|
|
12
|
-
"sourceMap": true,
|
|
13
|
-
"outDir": "dist",
|
|
14
|
-
"baseUrl": ".",
|
|
15
|
-
"paths": {
|
|
16
|
-
"*": [
|
|
17
|
-
"node_modules/*",
|
|
18
|
-
"src/types/*"
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
},
|
|
22
|
-
"exclude": ["node_modules", ".vscode", "dist", "tests"]
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"exclude": ["node_modules", ".vscode", "dist", "tests"]
|
|
23
4
|
}
|
package/tslint.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": [
|
|
3
|
-
"tslint:recommended"
|
|
4
|
-
],
|
|
5
|
-
"jsRules": {},
|
|
6
|
-
"rules": {
|
|
7
|
-
"quotemark": [true, "single"],
|
|
8
|
-
"ordered-imports": false,
|
|
9
|
-
"interface-name": false,
|
|
10
|
-
"object-literal-sort-keys": false,
|
|
11
|
-
"eofline": false,
|
|
12
|
-
"no-console": false,
|
|
13
|
-
"member-ordering": false,
|
|
14
|
-
"max-line-length": false,
|
|
15
|
-
"trailing-comma": false,
|
|
16
|
-
"no-string-literal": false,
|
|
17
|
-
"arrow-parens": false,
|
|
18
|
-
"object-literal-key-quotes": false
|
|
19
|
-
},
|
|
20
|
-
"rulesDirectory": []
|
|
1
|
+
{
|
|
2
|
+
"extends": [
|
|
3
|
+
"tslint:recommended"
|
|
4
|
+
],
|
|
5
|
+
"jsRules": {},
|
|
6
|
+
"rules": {
|
|
7
|
+
"quotemark": [true, "single"],
|
|
8
|
+
"ordered-imports": false,
|
|
9
|
+
"interface-name": false,
|
|
10
|
+
"object-literal-sort-keys": false,
|
|
11
|
+
"eofline": false,
|
|
12
|
+
"no-console": false,
|
|
13
|
+
"member-ordering": false,
|
|
14
|
+
"max-line-length": false,
|
|
15
|
+
"trailing-comma": false,
|
|
16
|
+
"no-string-literal": false,
|
|
17
|
+
"arrow-parens": false,
|
|
18
|
+
"object-literal-key-quotes": false
|
|
19
|
+
},
|
|
20
|
+
"rulesDirectory": []
|
|
21
21
|
}
|
package/wallaby.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
module.exports = function (wallaby) {
|
|
2
|
-
return {
|
|
3
|
-
files: [
|
|
4
|
-
"**/*.css",
|
|
5
|
-
"**/*.json",
|
|
6
|
-
"src/**/*.ts",
|
|
7
|
-
"src/**/*.html",
|
|
8
|
-
"tests/setup.ts",
|
|
9
|
-
"tsconfig.json",
|
|
10
|
-
],
|
|
11
|
-
|
|
12
|
-
tests: ["tests/**/*.spec.ts"],
|
|
13
|
-
|
|
14
|
-
compilers: {
|
|
15
|
-
"**/*.ts": wallaby.compilers.typeScript({
|
|
16
|
-
module: "commonjs",
|
|
17
|
-
typescript: require("typescript"),
|
|
18
|
-
}),
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
env: {
|
|
22
|
-
runner: "node",
|
|
23
|
-
type: "node",
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
};
|
|
1
|
+
module.exports = function (wallaby) {
|
|
2
|
+
return {
|
|
3
|
+
files: [
|
|
4
|
+
"**/*.css",
|
|
5
|
+
"**/*.json",
|
|
6
|
+
"src/**/*.ts",
|
|
7
|
+
"src/**/*.html",
|
|
8
|
+
"tests/setup.ts",
|
|
9
|
+
"tsconfig.json",
|
|
10
|
+
],
|
|
11
|
+
|
|
12
|
+
tests: ["tests/**/*.spec.ts"],
|
|
13
|
+
|
|
14
|
+
compilers: {
|
|
15
|
+
"**/*.ts": wallaby.compilers.typeScript({
|
|
16
|
+
module: "commonjs",
|
|
17
|
+
typescript: require("typescript"),
|
|
18
|
+
}),
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
env: {
|
|
22
|
+
runner: "node",
|
|
23
|
+
type: "node",
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
};
|
package/.env
DELETED