Adding heartbeat message andrequired functions for price plugins
This commit is contained in:
parent
65a55cede0
commit
9df77d5b30
|
@ -22,14 +22,28 @@
|
|||
}
|
||||
},
|
||||
|
||||
"heartbeat": {
|
||||
"enabled": true,
|
||||
"symKey": "0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b"
|
||||
},
|
||||
|
||||
"tokens": {
|
||||
"0x0000000000000000000000000000000000000000": {
|
||||
"name": "Ethereum",
|
||||
"symbol": "ETH"
|
||||
"symbol": "ETH",
|
||||
"minAccepted":{
|
||||
"value": 1,
|
||||
"currency": "USD"
|
||||
}
|
||||
},
|
||||
"0xD10e6dAe987Dcc0B3ADaA375C9f59690a4C97a27": {
|
||||
"name": "Status Network Token",
|
||||
"symbol": "SNT"
|
||||
"symbol": "SNT",
|
||||
"minAccepted":{
|
||||
"value": 1,
|
||||
"currency": "USD"
|
||||
},
|
||||
"pricePlugin": "../plugins/token-utils.js"
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -12,9 +12,19 @@ class ContractSettings {
|
|||
}
|
||||
|
||||
process(){
|
||||
this._setTokenPricePlugin();
|
||||
this._processContracts();
|
||||
}
|
||||
|
||||
_setTokenPricePlugin(){
|
||||
for(let token in this.tokens){
|
||||
if(this.tokens[token].pricePlugin !== undefined){
|
||||
let PricePlugin = require(this.tokens[token].pricePlugin);
|
||||
this.tokens[token].pricePlugin = new PricePlugin(this.tokens[token]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getToken(token){
|
||||
return this.tokens[token];
|
||||
}
|
||||
|
|
|
@ -96,6 +96,14 @@ class MessageProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
_getFactor(input, contract, gasToken){
|
||||
if(contract.allowedFunctions[input.functionName].isToken){
|
||||
return this.web3.utils.toBN(this.settings.getToken(gasToken).pricePlugin.getFactor());
|
||||
} else {
|
||||
return this.web3.utils.toBN(1);
|
||||
}
|
||||
}
|
||||
|
||||
async getBalance(token, input, gasToken){
|
||||
// Determining balances of token used
|
||||
if(token.symbol == "ETH"){
|
||||
|
|
|
@ -31,12 +31,14 @@ events.on('web3:connected', connURL => {
|
|||
});
|
||||
|
||||
|
||||
// Setting up Whisper options
|
||||
const shhOptions = {
|
||||
ttl: config.node.whisper.ttl,
|
||||
minPow: config.node.whisper.minPow,
|
||||
};
|
||||
|
||||
events.on('setup:complete', (settings) => {
|
||||
// Setting up Whisper options
|
||||
const shhOptions = {
|
||||
ttl: config.node.whisper.ttl,
|
||||
minPow: config.node.whisper.minPow,
|
||||
};
|
||||
|
||||
|
||||
let kId;
|
||||
let symKId;
|
||||
|
@ -58,6 +60,35 @@ events.on('setup:complete', (settings) => {
|
|||
shhOptions.topics = [contract];
|
||||
events.emit('server:listen', shhOptions, settings);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(config.heartbeat.enabled){
|
||||
let heartbeatSymKeyId;
|
||||
web3.shh.addSymKey(config.heartbeat.symKey)
|
||||
.then(heartbeatSymKeyId => {
|
||||
|
||||
// TODO: define minPriceAccepted
|
||||
let heartbeatPayload = {
|
||||
'minPriceAccepted': 0
|
||||
}
|
||||
|
||||
setInterval(() => {
|
||||
web3.shh.post({
|
||||
symKeyID: heartbeatSymKeyId,
|
||||
sig: keyId,
|
||||
ttl: config.node.whisper.ttl,
|
||||
powTarget:config.node.whisper.minPow,
|
||||
powTime: config.node.whisper.powTime,
|
||||
// TODO: topic must be a combination of heartbeat + token
|
||||
topic: web3.utils.toHex("relay-heartbeat").slice(0, 10),
|
||||
payload: web3.utils.toHex(JSON.stringify(heartbeatPayload))
|
||||
}).catch(console.error);
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue