-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnodeapi.service.js
44 lines (41 loc) · 1.22 KB
/
nodeapi.service.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
/**
* Node Trinity source code
* See LICENCE file at the top of the source tree
*
* ******************************************
*
* nodeapi.service.js
* Nodeapi module business logic
*
* ******************************************
*
* Authors: K. Zhidanov, A. Prudanov, M. Vasil'ev
*/
const Utils = require('./Utils');
const Pending = require('./Pending');
class NodeapiService {
constructor(db) {
this.db = db;
this.pending = new Pending(this.db);
}
async post_tx(tx){
let isValid = this.pending.validate(tx);
if(isValid.err !== 0)
return isValid;
tx.from = tx.from.toLowerCase();
tx.to = tx.to.toLowerCase();
tx.hash = Utils.get_txhash(tx);
let isExist = await this.db.pending_check(tx.hash);
if(isExist){
console.trace(`TX ${tx.hash} is already in txpool`);
return {err: 1, message : "TX is already in txpool"};
}
// TODO: check insertion
let result = await this.db.pending_add([tx]);
return {err: 0, result : [{hash: tx.hash, status: 0}]};
}
async check_pending(msg) {
return await this.db.get_pending();
};
}
module.exports.NodeapiService = NodeapiService;