@alephium/web3 2.0.6 → 2.0.8
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/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/contract/contract.js +4 -2
- package/dist/src/contract/events.d.ts +2 -0
- package/dist/src/contract/events.js +11 -2
- package/dist/src/global.d.ts +3 -0
- package/dist/src/global.js +23 -1
- package/package.json +1 -1
- package/src/contract/contract.ts +4 -2
- package/src/contract/events.ts +12 -2
- package/src/global.ts +24 -0
|
@@ -823,7 +823,8 @@ function subscribeEventsFromContract(options, address, eventIndex, decodeFunc, f
|
|
|
823
823
|
pollingInterval: options.pollingInterval,
|
|
824
824
|
messageCallback: messageCallback,
|
|
825
825
|
errorCallback: errorCallback,
|
|
826
|
-
onEventCountChanged: options.onEventCountChanged
|
|
826
|
+
onEventCountChanged: options.onEventCountChanged,
|
|
827
|
+
parallel: options.parallel
|
|
827
828
|
};
|
|
828
829
|
return (0, events_1.subscribeToEvents)(opt, address, fromCount);
|
|
829
830
|
}
|
|
@@ -1242,7 +1243,8 @@ function subscribeContractEvents(contract, instance, options, fromCount) {
|
|
|
1242
1243
|
pollingInterval: options.pollingInterval,
|
|
1243
1244
|
messageCallback: messageCallback,
|
|
1244
1245
|
errorCallback: errorCallback,
|
|
1245
|
-
onEventCountChanged: options.onEventCountChanged
|
|
1246
|
+
onEventCountChanged: options.onEventCountChanged,
|
|
1247
|
+
parallel: options.parallel
|
|
1246
1248
|
};
|
|
1247
1249
|
return (0, events_1.subscribeToEvents)(opt, instance.address, fromCount);
|
|
1248
1250
|
}
|
|
@@ -2,11 +2,13 @@ import { node } from '../api';
|
|
|
2
2
|
import { Subscription, SubscribeOptions } from '../utils';
|
|
3
3
|
export interface EventSubscribeOptions<Message> extends SubscribeOptions<Message> {
|
|
4
4
|
onEventCountChanged?: (eventCount: number) => Promise<void> | void;
|
|
5
|
+
parallel?: boolean;
|
|
5
6
|
}
|
|
6
7
|
export declare class EventSubscription extends Subscription<node.ContractEvent> {
|
|
7
8
|
readonly contractAddress: string;
|
|
8
9
|
private fromCount;
|
|
9
10
|
private onEventCountChanged?;
|
|
11
|
+
private parallel;
|
|
10
12
|
constructor(options: EventSubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number);
|
|
11
13
|
currentEventCount(): number;
|
|
12
14
|
private getEvents;
|
|
@@ -46,9 +46,11 @@ const utils_1 = require("../utils");
|
|
|
46
46
|
class EventSubscription extends utils_1.Subscription {
|
|
47
47
|
constructor(options, contractAddress, fromCount) {
|
|
48
48
|
super(options);
|
|
49
|
+
this.parallel = false;
|
|
49
50
|
this.contractAddress = contractAddress;
|
|
50
51
|
this.fromCount = typeof fromCount === 'undefined' ? 0 : fromCount;
|
|
51
52
|
this.onEventCountChanged = options.onEventCountChanged;
|
|
53
|
+
this.parallel = options.parallel ?? false;
|
|
52
54
|
}
|
|
53
55
|
currentEventCount() {
|
|
54
56
|
return this.fromCount;
|
|
@@ -72,8 +74,15 @@ class EventSubscription extends utils_1.Subscription {
|
|
|
72
74
|
if (this.fromCount === events.nextStart) {
|
|
73
75
|
return;
|
|
74
76
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
if (this.parallel) {
|
|
78
|
+
const promises = events.events.map((event) => this.messageCallback(event));
|
|
79
|
+
await Promise.all(promises);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
for (const event of events.events) {
|
|
83
|
+
await this.messageCallback(event);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
77
86
|
this.fromCount = events.nextStart;
|
|
78
87
|
if (this.onEventCountChanged !== undefined) {
|
|
79
88
|
await this.onEventCountChanged(this.fromCount);
|
package/dist/src/global.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ExplorerProvider, NodeProvider } from './api';
|
|
2
|
+
import { NetworkId } from './utils';
|
|
2
3
|
export declare function setCurrentNodeProvider(provider: NodeProvider): void;
|
|
3
4
|
export declare function setCurrentNodeProvider(baseUrl: string, apiKey?: string, customFetch?: typeof fetch): void;
|
|
4
5
|
export declare function getCurrentNodeProvider(): NodeProvider;
|
|
5
6
|
export declare function setCurrentExplorerProvider(provider: ExplorerProvider): void;
|
|
6
7
|
export declare function setCurrentExplorerProvider(baseUrl: string, apiKey?: string, customFetch?: typeof fetch): void;
|
|
7
8
|
export declare function getCurrentExplorerProvider(): ExplorerProvider | undefined;
|
|
9
|
+
export declare function getDefaultNodeProvider(networkId: NetworkId): NodeProvider;
|
|
10
|
+
export declare function getDefaultExplorerProvider(networkId: NetworkId): ExplorerProvider;
|
package/dist/src/global.js
CHANGED
|
@@ -17,7 +17,7 @@ You should have received a copy of the GNU Lesser General Public License
|
|
|
17
17
|
along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.getCurrentExplorerProvider = exports.setCurrentExplorerProvider = exports.getCurrentNodeProvider = exports.setCurrentNodeProvider = void 0;
|
|
20
|
+
exports.getDefaultExplorerProvider = exports.getDefaultNodeProvider = exports.getCurrentExplorerProvider = exports.setCurrentExplorerProvider = exports.getCurrentNodeProvider = exports.setCurrentNodeProvider = void 0;
|
|
21
21
|
const api_1 = require("./api");
|
|
22
22
|
let _currentNodeProvider = undefined;
|
|
23
23
|
function setCurrentNodeProvider(provider, apiKey, customFetch) {
|
|
@@ -52,3 +52,25 @@ function getCurrentExplorerProvider() {
|
|
|
52
52
|
return _currentExplorerProvider;
|
|
53
53
|
}
|
|
54
54
|
exports.getCurrentExplorerProvider = getCurrentExplorerProvider;
|
|
55
|
+
const DEFAULT_PROVIDER_URLS = {
|
|
56
|
+
mainnet: {
|
|
57
|
+
nodeUrl: 'https://node.mainnet.alephium.org',
|
|
58
|
+
explorerUrl: 'https://backend.mainnet.alephium.org'
|
|
59
|
+
},
|
|
60
|
+
testnet: {
|
|
61
|
+
nodeUrl: 'https://node.testnet.alephium.org',
|
|
62
|
+
explorerUrl: 'https://backend.testnet.alephium.org'
|
|
63
|
+
},
|
|
64
|
+
devnet: {
|
|
65
|
+
nodeUrl: 'http://127.0.0.1:22973',
|
|
66
|
+
explorerUrl: 'http://127.0.0.1:9090'
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
function getDefaultNodeProvider(networkId) {
|
|
70
|
+
return new api_1.NodeProvider(DEFAULT_PROVIDER_URLS[networkId].nodeUrl);
|
|
71
|
+
}
|
|
72
|
+
exports.getDefaultNodeProvider = getDefaultNodeProvider;
|
|
73
|
+
function getDefaultExplorerProvider(networkId) {
|
|
74
|
+
return new api_1.ExplorerProvider(DEFAULT_PROVIDER_URLS[networkId].explorerUrl);
|
|
75
|
+
}
|
|
76
|
+
exports.getDefaultExplorerProvider = getDefaultExplorerProvider;
|
package/package.json
CHANGED
package/src/contract/contract.ts
CHANGED
|
@@ -1334,7 +1334,8 @@ export function subscribeEventsFromContract<T extends Fields, M extends Contract
|
|
|
1334
1334
|
pollingInterval: options.pollingInterval,
|
|
1335
1335
|
messageCallback: messageCallback,
|
|
1336
1336
|
errorCallback: errorCallback,
|
|
1337
|
-
onEventCountChanged: options.onEventCountChanged
|
|
1337
|
+
onEventCountChanged: options.onEventCountChanged,
|
|
1338
|
+
parallel: options.parallel
|
|
1338
1339
|
}
|
|
1339
1340
|
return subscribeToEvents(opt, address, fromCount)
|
|
1340
1341
|
}
|
|
@@ -1907,7 +1908,8 @@ export function subscribeContractEvents(
|
|
|
1907
1908
|
pollingInterval: options.pollingInterval,
|
|
1908
1909
|
messageCallback: messageCallback,
|
|
1909
1910
|
errorCallback: errorCallback,
|
|
1910
|
-
onEventCountChanged: options.onEventCountChanged
|
|
1911
|
+
onEventCountChanged: options.onEventCountChanged,
|
|
1912
|
+
parallel: options.parallel
|
|
1911
1913
|
}
|
|
1912
1914
|
return subscribeToEvents(opt, instance.address, fromCount)
|
|
1913
1915
|
}
|
package/src/contract/events.ts
CHANGED
|
@@ -23,18 +23,21 @@ import { ContractEvents } from '../api/api-alephium'
|
|
|
23
23
|
|
|
24
24
|
export interface EventSubscribeOptions<Message> extends SubscribeOptions<Message> {
|
|
25
25
|
onEventCountChanged?: (eventCount: number) => Promise<void> | void
|
|
26
|
+
parallel?: boolean
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export class EventSubscription extends Subscription<node.ContractEvent> {
|
|
29
30
|
readonly contractAddress: string
|
|
30
31
|
private fromCount: number
|
|
31
32
|
private onEventCountChanged?: (eventCount: number) => Promise<void> | void
|
|
33
|
+
private parallel = false
|
|
32
34
|
|
|
33
35
|
constructor(options: EventSubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number) {
|
|
34
36
|
super(options)
|
|
35
37
|
this.contractAddress = contractAddress
|
|
36
38
|
this.fromCount = typeof fromCount === 'undefined' ? 0 : fromCount
|
|
37
39
|
this.onEventCountChanged = options.onEventCountChanged
|
|
40
|
+
this.parallel = options.parallel ?? false
|
|
38
41
|
}
|
|
39
42
|
|
|
40
43
|
currentEventCount(): number {
|
|
@@ -61,8 +64,15 @@ export class EventSubscription extends Subscription<node.ContractEvent> {
|
|
|
61
64
|
return
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
67
|
+
if (this.parallel) {
|
|
68
|
+
const promises = events.events.map((event) => this.messageCallback(event))
|
|
69
|
+
await Promise.all(promises)
|
|
70
|
+
} else {
|
|
71
|
+
for (const event of events.events) {
|
|
72
|
+
await this.messageCallback(event)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
66
76
|
this.fromCount = events.nextStart
|
|
67
77
|
|
|
68
78
|
if (this.onEventCountChanged !== undefined) {
|
package/src/global.ts
CHANGED
|
@@ -17,6 +17,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import { ExplorerProvider, NodeProvider } from './api'
|
|
20
|
+
import { NetworkId } from './utils'
|
|
20
21
|
|
|
21
22
|
let _currentNodeProvider: NodeProvider | undefined = undefined
|
|
22
23
|
|
|
@@ -62,3 +63,26 @@ export function setCurrentExplorerProvider(
|
|
|
62
63
|
export function getCurrentExplorerProvider(): ExplorerProvider | undefined {
|
|
63
64
|
return _currentExplorerProvider
|
|
64
65
|
}
|
|
66
|
+
|
|
67
|
+
const DEFAULT_PROVIDER_URLS = {
|
|
68
|
+
mainnet: {
|
|
69
|
+
nodeUrl: 'https://node.mainnet.alephium.org',
|
|
70
|
+
explorerUrl: 'https://backend.mainnet.alephium.org'
|
|
71
|
+
},
|
|
72
|
+
testnet: {
|
|
73
|
+
nodeUrl: 'https://node.testnet.alephium.org',
|
|
74
|
+
explorerUrl: 'https://backend.testnet.alephium.org'
|
|
75
|
+
},
|
|
76
|
+
devnet: {
|
|
77
|
+
nodeUrl: 'http://127.0.0.1:22973',
|
|
78
|
+
explorerUrl: 'http://127.0.0.1:9090'
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getDefaultNodeProvider(networkId: NetworkId): NodeProvider {
|
|
83
|
+
return new NodeProvider(DEFAULT_PROVIDER_URLS[networkId].nodeUrl)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function getDefaultExplorerProvider(networkId: NetworkId): ExplorerProvider {
|
|
87
|
+
return new ExplorerProvider(DEFAULT_PROVIDER_URLS[networkId].explorerUrl)
|
|
88
|
+
}
|