-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathkeyid.coffee
76 lines (62 loc) · 2.96 KB
/
keyid.coffee
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
###
dnschain
http://dnschain.net
Copyright (c) 2014 okTurtles Foundation
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
###
module.exports = (dnschain) ->
# expose these into our namespace
for k of dnschain.globals
eval "var #{k} = dnschain.globals.#{k};"
BlockchainResolver = require('../blockchain.coffee')(dnschain)
class KeyidResolver extends BlockchainResolver
constructor: (@dnschain) ->
@log = gNewLogger 'KeyID'
@tld = 'p2p'
@name = 'keyid'
gFillWithRunningChecks @
config: ->
@log.debug "Loading #{@name} resolver"
return unless gConf.add @name, _.map(_.filter([
[process.env.APPDATA, 'KeyID', 'config.json'],
[process.env.HOME, '.KeyID', 'config.json'],
[process.env.HOME, 'Library', 'Application Support', 'KeyID', 'config.json']]
, (x) -> !!x[0])
, (x) -> path.join x...)
@params = _.transform ["httpd_endpoint", "rpc_user", "rpc_password"], (o,v) =>
o[v] = gConf.chains[@name].get 'rpc:'+v
, {}
unless _(@params).values().every()
missing = _.transform @params, ((o,v,k)->if !v then o.push 'rpc:'+k), []
@log.info "Disabled. Missing params:", missing
return
[@params.host, @params.port] = @params.httpd_endpoint.split ':'
@params.port = parseInt @params.port
gConf.chains[@name].set 'host', @params.host
@
start: ->
@startCheck (success) =>
params = _.at @params, ["port", "host", "rpc_user", "rpc_password"]
# TODO: $create doesn't actually connect. you need to open a raw socket
# or an http socket and see if that works before declaring it works
@peer = rpc.Client.$create(params...) or gErr "rpc create"
@log.info "rpc to bitshares_client on: %s:%d/rpc", @params.host, @params.port
success()
resources:
key: (property, operation, fmt, args, cb) ->
result = @resultTemplate()
@log.debug gLineInfo("#{@name} resolve"), {property:property}
@peer.call 'dotp2p_show', [property], property:'/rpc', (err, ans) ->
return cb(err) if err
if _.isString ans
try
result.data = JSON.parse ans
catch e
@log.error glineInfo(e.message)
return cb e
else if not _.isObject ans
@log.warn gLineInfo('type not string or object!'), {json: ans, type: typeof(ans)}
result.data = {}
cb null, result