Skip to content

Commit

Permalink
#14 - Added "tokenlist" method for Blockscout
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeryVa committed Oct 31, 2018
1 parent 706c3ee commit 2ced58c
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions hyperloot-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BLOCKCHAIN="Ropsten" node .
41 changes: 41 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"loopback-boot": "^2.6.5",
"loopback-component-explorer": "^6.0.0",
"loopback-connector-mongodb": "^3.8.0",
"loopback-connector-rest": "^3.4.1",
"serve-favicon": "^2.0.1",
"strong-error-handler": "^2.0.0"
},
Expand Down
13 changes: 13 additions & 0 deletions server/boot/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,18 @@ module.exports = function(server) {
});
});

router.get('/blockscout/tokenList', function(req, res, next) {
var address = req.query['address'];
var blockscout = server.models.Blockscout;
blockscout.getTokenList(address, function(err, list) {
if (err) {
sendError(res, err);
return;
}

res.send(list);
});
});

server.use(router);
};
31 changes: 31 additions & 0 deletions server/datasources.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,36 @@
"name": "hlapi",
"user": "hyperloot",
"connector": "mongodb"
},
"blockscout": {
"name": "blockscout",
"crud": false,
"connector": "rest",
"options": {
"headers": {
"accept": "application/json",
"content-type": "application/json"
}
},
"operations": [
{
"template": {
"method": "GET",
"url": "https://blockscout.com/eth/{network}/api",
"query": {
"network": "{network}",
"module": "{module=account}",
"action": "{action=tokenlist}",
"address": "{address}"
}
},
"functions": {
"tokenlist": [
"network",
"address"
]
}
}
]
}
}
4 changes: 4 additions & 0 deletions server/model-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,9 @@
"Wallet": {
"dataSource": "hlapi",
"public": true
},
"Blockscout": {
"dataSource": "blockscout",
"public": false
}
}
24 changes: 24 additions & 0 deletions server/models/blockscout.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

module.exports = function(Blockscout) {

var Blockchain = {"Main": "mainnet", "Ropsten": "ropsten"};
Object.freeze(Blockchain);

function currentBlockchain() {
var networkName = process.env.BLOCKCHAIN;
if (networkName == null) {
return Blockchain.Ropsten;
}

return Blockchain[networkName];
}

Blockscout.getTokenList = function(address, callback) {
console.log(currentBlockchain());
Blockscout.tokenlist(currentBlockchain(), address, function(err, result) {
callback(err, result);
});
};

};
13 changes: 13 additions & 0 deletions server/models/blockscout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Blockscout",
"base": "Model",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}

0 comments on commit 2ced58c

Please sign in to comment.