hive-stream 2.0.6 → 3.0.1
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/AGENTS.md +35 -0
- package/CHANGELOG.md +166 -0
- package/CLAUDE.md +75 -0
- package/DOCUMENTATION.md +380 -0
- package/LICENSE +21 -21
- package/README.md +429 -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 +43 -25
- package/dist/adapters/base.adapter.js +79 -49
- package/dist/adapters/base.adapter.js.map +1 -1
- package/dist/adapters/mongodb.adapter.d.ts +44 -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 +66 -0
- package/dist/adapters/postgresql.adapter.js +598 -0
- package/dist/adapters/postgresql.adapter.js.map +1 -0
- package/dist/adapters/sqlite.adapter.d.ts +57 -41
- package/dist/adapters/sqlite.adapter.js +561 -397
- package/dist/adapters/sqlite.adapter.js.map +1 -1
- package/dist/api.d.ts +6 -6
- package/dist/api.js +181 -55
- package/dist/api.js.map +1 -1
- package/dist/config.d.ts +19 -16
- package/dist/config.js +21 -18
- package/dist/config.js.map +1 -1
- package/dist/contracts/coinflip.contract.d.ts +9 -14
- package/dist/contracts/coinflip.contract.js +232 -94
- package/dist/contracts/coinflip.contract.js.map +1 -1
- package/dist/contracts/contract.d.ts +3 -0
- package/dist/contracts/contract.js +26 -0
- package/dist/contracts/contract.js.map +1 -0
- package/dist/contracts/dice.contract.d.ts +10 -29
- package/dist/contracts/dice.contract.js +217 -155
- package/dist/contracts/dice.contract.js.map +1 -1
- package/dist/contracts/exchange.contract.d.ts +11 -0
- package/dist/contracts/exchange.contract.js +492 -0
- package/dist/contracts/exchange.contract.js.map +1 -0
- package/dist/contracts/lotto.contract.d.ts +16 -20
- package/dist/contracts/lotto.contract.js +238 -246
- package/dist/contracts/lotto.contract.js.map +1 -1
- package/dist/contracts/nft.contract.d.ts +28 -0
- package/dist/contracts/nft.contract.js +598 -0
- package/dist/contracts/nft.contract.js.map +1 -0
- package/dist/contracts/poll.contract.d.ts +4 -0
- package/dist/contracts/poll.contract.js +105 -0
- package/dist/contracts/poll.contract.js.map +1 -0
- package/dist/contracts/rps.contract.d.ts +9 -0
- package/dist/contracts/rps.contract.js +217 -0
- package/dist/contracts/rps.contract.js.map +1 -0
- package/dist/contracts/tipjar.contract.d.ts +4 -0
- package/dist/contracts/tipjar.contract.js +60 -0
- package/dist/contracts/tipjar.contract.js.map +1 -0
- package/dist/contracts/token.contract.d.ts +4 -0
- package/dist/contracts/token.contract.js +311 -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 +11 -0
- package/dist/exchanges/coingecko.js +57 -0
- package/dist/exchanges/coingecko.js.map +1 -0
- package/dist/exchanges/exchange.d.ts +16 -9
- package/dist/exchanges/exchange.js +80 -26
- package/dist/exchanges/exchange.js.map +1 -1
- package/dist/hive-rates.d.ts +34 -9
- package/dist/hive-rates.js +208 -75
- package/dist/hive-rates.js.map +1 -1
- package/dist/index.d.ts +19 -11
- package/dist/index.js +47 -32
- package/dist/index.js.map +1 -1
- package/dist/streamer.d.ts +233 -93
- package/dist/streamer.js +1063 -545
- package/dist/streamer.js.map +1 -1
- package/dist/test.d.ts +1 -1
- package/dist/test.js +24 -25
- package/dist/test.js.map +1 -1
- package/dist/types/hive-stream.d.ts +106 -6
- package/dist/types/hive-stream.js +2 -2
- package/dist/types/rates.d.ts +47 -0
- package/dist/types/rates.js +29 -0
- package/dist/types/rates.js.map +1 -0
- package/dist/utils.d.ts +334 -27
- package/dist/utils.js +960 -261
- package/dist/utils.js.map +1 -1
- package/ecosystem.config.js +17 -17
- package/examples/contracts/README.md +8 -0
- package/examples/contracts/exchange.ts +38 -0
- package/examples/contracts/poll.ts +21 -0
- package/examples/contracts/rps.ts +19 -0
- package/examples/contracts/tipjar.ts +19 -0
- package/jest.config.js +8 -8
- package/package.json +54 -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 +94 -132
- package/tests/contracts/dice.contract.spec.ts +87 -160
- package/tests/contracts/entrants.json +728 -728
- package/tests/contracts/exchange.contract.spec.ts +84 -0
- package/tests/contracts/lotto.contract.spec.ts +59 -324
- package/tests/contracts/nft.contract.spec.ts +948 -0
- package/tests/contracts/token.contract.spec.ts +90 -0
- package/tests/exchanges/coingecko.exchange.spec.ts +169 -0
- package/tests/exchanges/exchange.base.spec.ts +246 -0
- package/tests/helpers/mock-adapter.ts +214 -0
- package/tests/helpers/mock-fetch.ts +165 -0
- package/tests/hive-chain-features.spec.ts +238 -0
- package/tests/hive-rates.spec.ts +443 -0
- package/tests/integration/hive-rates.integration.spec.ts +35 -0
- package/tests/setup.ts +29 -18
- package/tests/streamer-actions.spec.ts +274 -0
- package/tests/streamer.spec.ts +342 -152
- package/tests/types/rates.spec.ts +216 -0
- package/tests/utils.spec.ts +113 -95
- package/tsconfig.build.json +3 -22
- package/tslint.json +20 -20
- package/wallaby.js +26 -26
package/dist/streamer.d.ts
CHANGED
|
@@ -1,93 +1,233 @@
|
|
|
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 { ContractDefinition, EscrowOperationType } 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 escrowSubscriptions;
|
|
13
|
+
private attempts;
|
|
14
|
+
private config;
|
|
15
|
+
private client;
|
|
16
|
+
private hive;
|
|
17
|
+
private username;
|
|
18
|
+
private postingKey;
|
|
19
|
+
private activeKey;
|
|
20
|
+
private blockNumberTimeout;
|
|
21
|
+
private latestBlockTimer;
|
|
22
|
+
private lastBlockNumber;
|
|
23
|
+
private headBlockNumber;
|
|
24
|
+
private isPollingBlock;
|
|
25
|
+
private isCatchingUp;
|
|
26
|
+
private blockId;
|
|
27
|
+
private previousBlockId;
|
|
28
|
+
private transactionId;
|
|
29
|
+
private blockTime;
|
|
30
|
+
private latestBlockchainTime;
|
|
31
|
+
private disableAllProcessing;
|
|
32
|
+
private contracts;
|
|
33
|
+
private adapter;
|
|
34
|
+
private actions;
|
|
35
|
+
private lastStateSave;
|
|
36
|
+
private stateSaveInterval;
|
|
37
|
+
private blockProcessingQueue;
|
|
38
|
+
private isProcessingQueue;
|
|
39
|
+
private readonly maxSubscriptions;
|
|
40
|
+
private subscriptionCleanupInterval;
|
|
41
|
+
private actionFrequencyMap;
|
|
42
|
+
private contractCache;
|
|
43
|
+
private blockCache;
|
|
44
|
+
private transactionCache;
|
|
45
|
+
private accountCache;
|
|
46
|
+
private readonly cacheTimeout;
|
|
47
|
+
private readonly maxCacheSize;
|
|
48
|
+
private utils;
|
|
49
|
+
constructor(userConfig?: Partial<ConfigInterface>);
|
|
50
|
+
private _initializeAdapter;
|
|
51
|
+
registerAdapter(adapter: AdapterBase): Promise<void>;
|
|
52
|
+
getAdapter(): AdapterBase;
|
|
53
|
+
/**
|
|
54
|
+
* Register a new action with improved validation and persistence
|
|
55
|
+
*/
|
|
56
|
+
registerAction(action: TimeAction): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Validate that the contract and method exist for the action
|
|
59
|
+
*/
|
|
60
|
+
private validateActionContract;
|
|
61
|
+
private isActionTriggerAllowed;
|
|
62
|
+
/**
|
|
63
|
+
* Remove an action by ID
|
|
64
|
+
*/
|
|
65
|
+
removeAction(actionId: string): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Get all registered actions
|
|
68
|
+
*/
|
|
69
|
+
getActions(): TimeAction[];
|
|
70
|
+
/**
|
|
71
|
+
* Get action by ID
|
|
72
|
+
*/
|
|
73
|
+
getAction(actionId: string): TimeAction | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Enable/disable an action
|
|
76
|
+
*/
|
|
77
|
+
setActionEnabled(actionId: string, enabled: boolean): Promise<boolean>;
|
|
78
|
+
/**
|
|
79
|
+
* Save actions to disk asynchronously
|
|
80
|
+
*/
|
|
81
|
+
private saveActionsToDisk;
|
|
82
|
+
/**
|
|
83
|
+
* Resets a specific action time value
|
|
84
|
+
*/
|
|
85
|
+
resetAction(id: string): Promise<boolean>;
|
|
86
|
+
registerContract(contract: ContractDefinition): Promise<void>;
|
|
87
|
+
unregisterContract(name: string): Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* setConfig
|
|
90
|
+
*
|
|
91
|
+
* Allows specific configuration settings to be overridden
|
|
92
|
+
*
|
|
93
|
+
* @param config
|
|
94
|
+
*/
|
|
95
|
+
setConfig(config: Partial<ConfigInterface>): this;
|
|
96
|
+
/**
|
|
97
|
+
* Start
|
|
98
|
+
*
|
|
99
|
+
* Starts the streamer bot to get blocks from the Hive API
|
|
100
|
+
*
|
|
101
|
+
*/
|
|
102
|
+
start(): Promise<Streamer>;
|
|
103
|
+
/**
|
|
104
|
+
* Stop
|
|
105
|
+
*
|
|
106
|
+
* Stops the streamer from running
|
|
107
|
+
*/
|
|
108
|
+
stop(): Promise<void>;
|
|
109
|
+
private getLatestBlock;
|
|
110
|
+
private getBlock;
|
|
111
|
+
private loadBlock;
|
|
112
|
+
processOperation(op: [string, any], blockNumber: number, blockId: string, prevBlockId: string, trxId: string, blockTime: Date): Promise<void>;
|
|
113
|
+
private normalizeContractPayload;
|
|
114
|
+
private isEscrowOperationType;
|
|
115
|
+
private buildEscrowDetails;
|
|
116
|
+
private buildContractContext;
|
|
117
|
+
private dispatchContractAction;
|
|
118
|
+
private processActions;
|
|
119
|
+
/**
|
|
120
|
+
* Clean up completed or disabled actions to prevent memory leaks
|
|
121
|
+
*/
|
|
122
|
+
private cleanupActions;
|
|
123
|
+
saveStateToDisk(): Promise<void>;
|
|
124
|
+
private saveStateThrottled;
|
|
125
|
+
saveToHiveApi(from: string, data: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
126
|
+
getAccountTransfers(account: string, from?: number, limit?: number): Promise<any[]>;
|
|
127
|
+
transferHiveTokens(from: string, to: string, amount: string, symbol: string, memo?: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
128
|
+
transferHiveTokensMultiple(from: string, accounts: string[], amount: string, symbol: string, memo?: string): Promise<boolean>;
|
|
129
|
+
broadcastOperations(operations: Array<[string, any]>, signingKeys?: string | string[]): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
130
|
+
broadcastMultiSigOperations(operations: Array<[string, any]>, signingKeys: string[]): any;
|
|
131
|
+
createAuthority(keyAuths?: Array<[string, number]>, accountAuths?: Array<[string, number]>, weightThreshold?: number): any;
|
|
132
|
+
updateAccountAuthorities(account: string, authorityUpdate: {
|
|
133
|
+
owner?: any;
|
|
134
|
+
active?: any;
|
|
135
|
+
posting?: any;
|
|
136
|
+
memo_key?: string;
|
|
137
|
+
json_metadata?: string;
|
|
138
|
+
posting_json_metadata?: string;
|
|
139
|
+
useAccountUpdate2?: boolean;
|
|
140
|
+
}, signingKeys?: string | string[]): Promise<any>;
|
|
141
|
+
escrowTransfer(options: {
|
|
142
|
+
from: string;
|
|
143
|
+
to: string;
|
|
144
|
+
agent: string;
|
|
145
|
+
escrow_id: number;
|
|
146
|
+
hive_amount?: string;
|
|
147
|
+
hbd_amount?: string;
|
|
148
|
+
fee: string;
|
|
149
|
+
ratification_deadline: string | Date;
|
|
150
|
+
escrow_expiration: string | Date;
|
|
151
|
+
json_meta?: string | Record<string, any>;
|
|
152
|
+
}, signingKeys?: string | string[]): any;
|
|
153
|
+
escrowApprove(options: {
|
|
154
|
+
from: string;
|
|
155
|
+
to: string;
|
|
156
|
+
agent: string;
|
|
157
|
+
who: string;
|
|
158
|
+
escrow_id: number;
|
|
159
|
+
approve: boolean;
|
|
160
|
+
}, signingKeys?: string | string[]): any;
|
|
161
|
+
escrowDispute(options: {
|
|
162
|
+
from: string;
|
|
163
|
+
to: string;
|
|
164
|
+
agent: string;
|
|
165
|
+
who: string;
|
|
166
|
+
escrow_id: number;
|
|
167
|
+
}, signingKeys?: string | string[]): any;
|
|
168
|
+
escrowRelease(options: {
|
|
169
|
+
from: string;
|
|
170
|
+
to: string;
|
|
171
|
+
agent: string;
|
|
172
|
+
who: string;
|
|
173
|
+
receiver: string;
|
|
174
|
+
escrow_id: number;
|
|
175
|
+
hive_amount?: string;
|
|
176
|
+
hbd_amount?: string;
|
|
177
|
+
}, signingKeys?: string | string[]): any;
|
|
178
|
+
recurrentTransfer(options: {
|
|
179
|
+
from: string;
|
|
180
|
+
to: string;
|
|
181
|
+
amount: string;
|
|
182
|
+
memo?: string;
|
|
183
|
+
recurrence: number;
|
|
184
|
+
executions: number;
|
|
185
|
+
}, signingKeys?: string | string[]): any;
|
|
186
|
+
createProposal(options: {
|
|
187
|
+
creator: string;
|
|
188
|
+
receiver: string;
|
|
189
|
+
start_date: string | Date;
|
|
190
|
+
end_date: string | Date;
|
|
191
|
+
daily_pay: string;
|
|
192
|
+
subject: string;
|
|
193
|
+
permlink: string;
|
|
194
|
+
}, signingKeys?: string | string[]): any;
|
|
195
|
+
updateProposalVotes(options: {
|
|
196
|
+
voter: string;
|
|
197
|
+
proposal_ids: number[];
|
|
198
|
+
approve: boolean;
|
|
199
|
+
}, signingKeys?: string | string[]): any;
|
|
200
|
+
removeProposals(options: {
|
|
201
|
+
proposal_owner: string;
|
|
202
|
+
proposal_ids: number[];
|
|
203
|
+
}, signingKeys?: string | string[]): any;
|
|
204
|
+
transferHiveEngineTokens(from: string, to: string, symbol: string, quantity: string, memo?: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
205
|
+
transferHiveEngineTokensMultiple(from: string, accounts: any[], symbol: string, memo?: string, amount?: string): Promise<void>;
|
|
206
|
+
issueHiveEngineTokens(from: string, to: string, symbol: string, quantity: string, memo?: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
207
|
+
issueHiveEngineTokensMultiple(from: string, accounts: any[], symbol: string, memo?: string, amount?: string): Promise<void>;
|
|
208
|
+
upvote(votePercentage: string, username: string, permlink: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
209
|
+
downvote(votePercentage: string, username: string, permlink: string): Promise<import("@hiveio/dhive").TransactionConfirmation>;
|
|
210
|
+
getTransaction(blockNumber: number, transactionId: string): Promise<import("@hiveio/dhive").SignedTransaction>;
|
|
211
|
+
getStatus(): {
|
|
212
|
+
lastBlockNumber: number;
|
|
213
|
+
headBlockNumber: number;
|
|
214
|
+
blocksBehind: number;
|
|
215
|
+
latestBlockchainTime: Date;
|
|
216
|
+
isCatchingUp: boolean;
|
|
217
|
+
};
|
|
218
|
+
verifyTransfer(transaction: any, from: string, to: string, amount: string): Promise<boolean>;
|
|
219
|
+
onComment(callback: any): void;
|
|
220
|
+
onPost(callback: any): void;
|
|
221
|
+
onTransfer(account: string, callback: () => void): void;
|
|
222
|
+
onCustomJson(callback: any): void;
|
|
223
|
+
onCustomJsonId(callback: any, id: string): void;
|
|
224
|
+
onHiveEngine(callback: any): void;
|
|
225
|
+
onEscrowTransfer(callback: any): void;
|
|
226
|
+
onEscrowApprove(callback: any): void;
|
|
227
|
+
onEscrowDispute(callback: any): void;
|
|
228
|
+
onEscrowRelease(callback: any): void;
|
|
229
|
+
private cleanupSubscriptions;
|
|
230
|
+
removeTransferSubscription(account: string): void;
|
|
231
|
+
removeCustomJsonIdSubscription(id: string): void;
|
|
232
|
+
removeEscrowSubscriptions(type?: EscrowOperationType): void;
|
|
233
|
+
}
|