Last active
August 29, 2015 14:23
-
-
Save resilience-me/bdf7eabd2da0d9fe25cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var fs = require('fs'); | |
var app = express(); | |
var request = require('request') | |
var blockchainOracle = require('blockchain-oracle') | |
// the Oracle would require a Horizon javascript library | |
var horizon = require('horizon-lib') | |
// the Oracle manages its own Horizon account | |
var horizonAccount = horizon.generateAccount() // {account: "", secret_phrase: ""} | |
// the Oracle generates a cryptographic key that it will store (encrypted) on the Horizon blockchain | |
var blockchain_key = blockchainOracle.generateKey() | |
// the Oracle generates a hash of itself, that it will store (public) on the Horizon blockchain | |
var OracleHash = blockchainOracle.hashOracle() | |
// the Oracle creates a Bitnation Protocol Message that it will store on the Horizon blockchain | |
var data = {id: blockchainOracle, OracleHash: OracleHash, message: {key: blockchain_key, encrypted: true }} | |
// it stores the message. The Oracle is now tied to the Horizon blockchain | |
horizon.sendMessage(horizonAccount.secretphrase, data) | |
// the Oracle can now run any type of smart-contract logic, but it will only run as long as it gets the Oracle key from Horizon | |
function smart_contract_function(){ | |
// check if the Oracle is on the blockchain | |
horizon.getMessage() // filter by horizonAccount, find the Bitnation Protocol Message with the Oracle's hash and the Oracle's blockchain_key | |
if(...) // if the Oracle found its key on the Horizon blockchain, then the contract will run. | |
/** | |
* add smart-conract logic here | |
*/ | |
} | |
// add input-control: | |
app.post('/', function (req, res) { | |
}) | |
app.get('/', function(req, res) { | |
var public_data = { horizon_account: horizonAccount.account, oracle_hash: OracleHash } | |
res.send(public_data) | |
}); | |
app.listen(process.env.PORT || 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment