forked from jondubois/capitalisk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
212 lines (196 loc) · 5.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
* Copyright © 2019 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*/
'use strict';
const { config: DefaultConfig } = require('./defaults');
const Chain = require('./chain');
const { migrations } = require('./migrations');
const {
TransferTransaction,
SecondSignatureTransaction,
DelegateTransaction,
VoteTransaction,
MultisignatureTransaction
} = require('@liskhq/lisk-transactions');
const {
DappTransaction,
InTransferTransaction,
OutTransferTransaction
} = require('./extra_transactions');
const BaseModule = require('leasehold-lisk-framework/src/modules/base_module');
const DEFAULT_MODULE_ALIAS = 'leasehold_chain';
const pkg = require('./package.json');
/* eslint-disable class-methods-use-this */
/**
* Leasehold module specification
*
* @namespace Framework.Modules
* @type {module.LeaseholdChainModule}
*/
module.exports = class LeaseholdChainModule extends BaseModule {
constructor(options) {
super({...DefaultConfig.default, ...options});
if (!options) {
options = {};
}
this.alias = options.alias || DEFAULT_MODULE_ALIAS;
this.logger = options.logger;
this.chain = null;
}
static get dependencies() {
return ['app', 'network'];
}
static get alias() {
return DEFAULT_MODULE_ALIAS;
}
static get info() {
return {
author: 'Jonathan Gros-Dubois',
version: pkg.version,
name: DEFAULT_MODULE_ALIAS,
};
}
static get migrations() {
return [];
}
static get defaults() {
return DefaultConfig;
}
get events() {
return [
'bootstrap',
'blocks:change',
'transactions:confirmed:change',
'signature:change',
'transactions:change',
'rounds:change',
'multisignatures:signature:change',
'multisignatures:change',
'delegates:fork',
'loader:sync',
'dapps:change',
];
}
get actions() {
return {
calculateSupply: {
handler: action => this.chain.actions.calculateSupply(action),
},
calculateMilestone: {
handler: action => this.chain.actions.calculateMilestone(action),
},
calculateReward: {
handler: action => this.chain.actions.calculateReward(action),
},
generateDelegateList: {
handler: action => this.chain.actions.generateDelegateList(action),
},
updateForgingStatus: {
handler: async action => this.chain.actions.updateForgingStatus(action),
},
getForgingStatusForAllDelegates: {
handler: async () =>
this.chain.actions.getForgingStatusForAllDelegates(),
},
getTransactionsFromPool: {
handler: async action =>
this.chain.actions.getTransactionsFromPool(action),
},
getTransactions: {
handler: async () => this.chain.actions.getTransactions(),
isPublic: true,
},
postTransaction: {
handler: async action => this.chain.actions.postTransaction(action),
},
getDelegateBlocksRewards: {
handler: async action =>
this.chain.actions.getDelegateBlocksRewards(action),
},
getSlotNumber: {
handler: async action => this.chain.actions.getSlotNumber(action),
},
calcSlotRound: {
handler: async action => this.chain.actions.calcSlotRound(action),
},
getNodeStatus: {
handler: async () => this.chain.actions.getNodeStatus(),
},
getLastBlock: {
handler: async () => this.chain.actions.getLastBlock(),
},
blocks: {
handler: async action => this.chain.actions.blocks(action),
isPublic: true,
},
blocksCommon: {
handler: async action => this.chain.actions.blocksCommon(action),
isPublic: true,
},
getMultisigWalletMembers: {
handler: async action => this.chain.actions.getMultisigWalletMembers(action),
},
getMinMultisigRequiredSignatures: {
handler: async action => this.chain.actions.getMinMultisigRequiredSignatures(action),
},
getInboundTransactions: {
handler: async action => this.chain.actions.getInboundTransactions(action),
},
getOutboundTransactions: {
handler: async action => this.chain.actions.getOutboundTransactions(action),
},
getInboundTransactionsFromBlock: {
handler: async action => this.chain.actions.getInboundTransactionsFromBlock(action),
},
getOutboundTransactionsFromBlock: {
handler: async action => this.chain.actions.getOutboundTransactionsFromBlock(action),
},
getLastBlockAtTimestamp: {
handler: async action => this.chain.actions.getLastBlockAtTimestamp(action),
},
getMaxBlockHeight: {
handler: async action => this.chain.actions.getMaxBlockHeight(action),
},
getBlocksBetweenHeights: {
handler: async action => this.chain.actions.getBlocksBetweenHeights(action),
},
getBlockAtHeight: {
handler: async action => this.chain.actions.getBlockAtHeight(action),
},
getModuleOptions: {
handler: async action => this.chain.actions.getModuleOptions(action),
}
};
}
async load(channel, options) {
this.options = options;
this.options.registeredTransactions = {
'0': Object.freeze(TransferTransaction),
'1': Object.freeze(SecondSignatureTransaction),
'2': Object.freeze(DelegateTransaction),
'3': Object.freeze(VoteTransaction),
'4': Object.freeze(MultisignatureTransaction),
'5': Object.freeze(DappTransaction),
'6': Object.freeze(InTransferTransaction),
'7': Object.freeze(OutTransferTransaction)
};
this.chain = new Chain(channel, this.options, this.alias, this.logger, {
[this.alias]: migrations
});
await this.chain.bootstrap();
channel.publish(`${this.alias}:bootstrap`);
}
async unload() {
return this.chain.cleanup();
}
};