dnschain
Version:
A blockchain-based DNS + HTTPS server that fixes HTTPS security, and more!
77 lines (62 loc) • 3.03 kB
text/coffeescript
###
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) ->
gFillWithRunningChecks @
config: ->
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...)
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), []
return
[@params.host, @params.port] = @params.httpd_endpoint.split ':'
gConf.chains[@name].set 'host', @params.host
start: ->
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
success()
resources:
key: (property, operation, fmt, args, cb) ->
result = @resultTemplate()
return cb(err) if err
if _.isString ans
try
result.data = JSON.parse ans
catch e
return cb e
else if not _.isObject ans
result.data = {}
cb null, result