Browse Source

sample concept

master
extrapo 4 months ago
commit
ba36c990be
4 changed files with 264 additions and 0 deletions
  1. +48
    -0
      README.md
  2. +27
    -0
      sentinel.rb
  3. +10
    -0
      sentinel.sample.yml
  4. +179
    -0
      zcash.rb

+ 48
- 0
README.md View File

@ -0,0 +1,48 @@
# Zcash Sentinel Concept
(this name is gonna chance since we wanna avoid military terminologies and war machines like Nighhawk :P )
Sentinel observes the encrypted memo field received on zaddr transfers, waiting for commands to execute.
sentinel.rb
```
# hex2ascii
def decode_memo(hex_msg)
hex_msg.scan(/\\x(..)/).map{|a| a.first.to_i(16).chr}.join
end
nodes = YAML.load(File.read("sentinel.sample.yml"))
board = nodes['BoardNode']
Zcash.z_importviewingkey board['viewing_key']
loop true
transfers = Zcash.z_listreceivedbyaddress(board['zaddr'])
# todo: just act for new transfers, caching last execution datetime.
transfers.each |transfer|
memo = decode_memo transfer["memo"]
# sample: memo = {action: "reply", to: "$txid", msg: "$msg"}
if memo.key?(:action) && action = memo[:action]
# execute related action
cmd = board["actions"][action]["run"]
puts "Executing: #{cmd}"
`#{cmd}`
end
end
sleep 30
end
```
sentinel.sample.yml
```
nodes:
BoardNode:
zaddr: z[...]
viewing_key: zxview[...]
actions:
reply:
run: board.py --reply --id $txid --msg $message
validate: $amount >= 0.01
like:
run: board.py --like --id $txid
```

+ 27
- 0
sentinel.rb View File

@ -0,0 +1,27 @@
require 'yaml'
require "./zcash"
# hex2ascii
def decode_memo(hex_msg)
hex_msg.scan(/\\x(..)/).map{|a| a.first.to_i(16).chr}.join
end
nodes = YAML.load(File.read("sentinel.sample.yml"))
board = nodes['BoardNode']
Zcash.z_importviewingkey board['viewing_key']
loop true
transfers = Zcash.z_listreceivedbyaddress(board['zaddr'])
# todo: just act for new transfers, caching last execution datetime.
transfers.each |transfer|
memo = decode_memo transfer["memo"]
# sample: memo = {action: "reply", to: "$txid", msg: "$msg"}
if memo.key?(:action) && action = memo[:action]
# execute related action
cmd = board["actions"][action]["run"]
puts "Executing: #{cmd}"
`#{cmd}`
end
end
sleep 30
end

+ 10
- 0
sentinel.sample.yml View File

@ -0,0 +1,10 @@
nodes:
BoardNode:
zaddr: z[...]
viewing_key: zxview[...]
actions:
reply:
run: board.py --reply --id $txid --msg $message
validate: $amount >= 0.01
like:
run: board.py --like --id $txid

+ 179
- 0
zcash.rb View File

@ -0,0 +1,179 @@
# Rules de Zcashd node
class Zcash
@commands = %w{getaddressbalance getaddressdeltas getaddressmempool getaddresstxids getaddressutxos getbestblockhash getblock getblockchaininfo getblockcount getblockdeltas getblockhash getblockhashes getblockheader getchaintips getdifficulty getmempoolinfo getrawmempool getspentinfo gettxout gettxoutproof gettxoutsetinfo verifychain verifytxoutproof z_gettreestate getexperimentalfeatures getinfo getmemoryinfo setlogfilter stop z_getpaymentdisclosure z_validatepaymentdisclosure generate getgenerate setgenerate getblocksubsidy getblocktemplate getlocalsolps getmininginfo getnetworkhashps getnetworksolps prioritisetransaction submitblock addnode clearbanned disconnectnode getaddednodeinfo getconnectioncount getdeprecationinfo getnettotals getnetworkinfo getpeerinfo listbanned ping setban createrawtransaction decoderawtransaction decodescript fundrawtransaction getrawtransaction sendrawtransaction signrawtransaction createmultisig estimatefee estimatepriority validateaddress verifymessage z_validateaddress addmultisigaddress backupwallet dumpprivkey dumpwallet encryptwallet getaccount getaccountaddress getaddressesbyaccount getbalance getnewaddress getrawchangeaddress getreceivedbyaccount getreceivedbyaddress gettransaction getunconfirmedbalance getwalletinfo importaddress importprivkey importpubkey importwallet keypoolrefill listaccounts listaddressgroupings listlockunspent listreceivedbyaccount listreceivedbyaddress listsinceblock listtransactions listunspent lockunspent move sendfrom sendmany sendtoaddress setaccount settxfee signmessage z_exportkey z_exportviewingkey z_exportwallet z_getbalance z_getmigrationstatus z_getnewaddress z_getnotescount z_getoperationresult z_getoperationstatus z_gettotalbalance z_importkey z_importviewingkey z_importwallet z_listaddresses z_listoperationids z_listreceivedbyaddress z_listunspent z_mergetoaddress z_sendmany z_setmigration z_shieldcoinbase z_viewtransaction zcbenchmark zcrawjoinsplit zcrawkeygen zcrawreceive zcsamplejoinsplit}
def self.cli(cmd, *params)
result = {}
begin
raise "Inexistent method #{cmd}" unless @commands.include?(cmd)
params = '' if params.empty?
result = JSON.parse `zcash-cli #{cmd} #{params}`
rescue Exception => e
result["error"] = e.message
end
result
end
# use Ruby's meta-programming feature
def self.method_missing(method, *args)
cli(method, *args)
end
# sample usage:
# Zcash.getinfo
# Zcash.getmempoolinfo
end
# == Addressindex ==
# getaddressbalance {"addresses": ["taddr", ...]}
# getaddressdeltas {"addresses": ["taddr", ...], ("start": n), ("end": n), ("chainInfo": true|false)}
# getaddressmempool {"addresses": ["taddr", ...]}
# getaddresstxids {"addresses": ["taddr", ...], ("start": n), ("end": n)}
# getaddressutxos {"addresses": ["taddr", ...], ("chainInfo": true|false)}
# == Blockchain ==
# getbestblockhash
# getblock "hash|height" ( verbosity )
# getblockchaininfo
# getblockcount
# getblockdeltas "blockhash"
# getblockhash index
# getblockhashes high low ( {"noOrphans": true|false, "logicalTimes": true|false} )
# getblockheader "hash" ( verbose )
# getchaintips
# getdifficulty
# getmempoolinfo
# getrawmempool ( verbose )
# getspentinfo {"txid": "txidhex", "index": n}
# gettxout "txid" n ( includemempool )
# gettxoutproof ["txid",...] ( blockhash )
# gettxoutsetinfo
# verifychain ( checklevel numblocks )
# verifytxoutproof "proof"
# z_gettreestate "hash|height"
# == Control ==
# getexperimentalfeatures
# getinfo
# getmemoryinfo
# help ( "command" )
# setlogfilter "directives"
# stop
# == Disclosure ==
# z_getpaymentdisclosure "txid" "js_index" "output_index" ("message")
# z_validatepaymentdisclosure "paymentdisclosure"
# == Generating ==
# generate numblocks
# getgenerate
# setgenerate generate ( genproclimit )
# == Mining ==
# getblocksubsidy height
# getblocktemplate ( "jsonrequestobject" )
# getlocalsolps
# getmininginfo
# getnetworkhashps ( blocks height )
# getnetworksolps ( blocks height )
# prioritisetransaction <txid> <priority delta> <fee delta>
# submitblock "hexdata" ( "jsonparametersobject" )
# == Network ==
# addnode "node" "add|remove|onetry"
# clearbanned
# disconnectnode "node"
# getaddednodeinfo dns ( "node" )
# getconnectioncount
# getdeprecationinfo
# getnettotals
# getnetworkinfo
# getpeerinfo
# listbanned
# ping
# setban "ip(/netmask)" "add|remove" (bantime) (absolute)
# == Rawtransactions ==
# createrawtransaction [{"txid":"id","vout":n},...] {"address":amount,...} ( locktime ) ( expiryheight )
# decoderawtransaction "hexstring"
# decodescript "hex"
# fundrawtransaction "hexstring" includeWatching
# getrawtransaction "txid" ( verbose "blockhash" )
# sendrawtransaction "hexstring" ( allowhighfees )
# signrawtransaction "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] ["privatekey1",...] sighashtype )
# == Util ==
# createmultisig nrequired ["key",...]
# estimatefee nblocks
# estimatepriority nblocks
# validateaddress "zcashaddress"
# verifymessage "zcashaddress" "signature" "message"
# z_validateaddress "zaddr"
# == Wallet ==
# addmultisigaddress nrequired ["key",...] ( "account" )
# backupwallet "destination"
# dumpprivkey "t-addr"
# dumpwallet "filename"
# encryptwallet "passphrase"
# getaccount "zcashaddress"
# getaccountaddress "account"
# getaddressesbyaccount "account"
# getbalance ( "account" minconf includeWatchonly inZat )
# getnewaddress ( "account" )
# getrawchangeaddress
# getreceivedbyaccount "account" ( minconf ) ( inZat )
# getreceivedbyaddress "zcashaddress" ( minconf ) ( inZat )
# gettransaction "txid" ( includeWatchonly )
# getunconfirmedbalance
# getwalletinfo
# importaddress "address" ( "label" rescan p2sh )
# importprivkey "zcashprivkey" ( "label" rescan )
# importpubkey "pubkey" ( "label" rescan )
# importwallet "filename"
# keypoolrefill ( newsize )
# listaccounts ( minconf includeWatchonly)
# listaddressgroupings
# listlockunspent
# listreceivedbyaccount ( minconf includeempty includeWatchonly)
# listreceivedbyaddress ( minconf includeempty includeWatchonly)
# listsinceblock ( "blockhash" target-confirmations includeWatchonly)
# listtransactions ( "account" count from includeWatchonly)
# listunspent ( minconf maxconf ["address",...] )
# lockunspent unlock [{"txid":"txid","vout":n},...]
# move "fromaccount" "toaccount" amount ( minconf "comment" )
# sendfrom "fromaccount" "tozcashaddress" amount ( minconf "comment" "comment-to" )
# sendmany "fromaccount" {"address":amount,...} ( minconf "comment" ["address",...] )
# sendtoaddress "zcashaddress" amount ( "comment" "comment-to" subtractfeefromamount )
# setaccount "zcashaddress" "account"
# settxfee amount
# signmessage "t-addr" "message"
# z_exportkey "zaddr"
# z_exportviewingkey "zaddr"
# z_exportwallet "filename"
# z_getbalance "address" ( minconf inZat )
# z_getmigrationstatus
# z_getnewaddress ( type )
# z_getnotescount
# z_getoperationresult (["operationid", ... ])
# z_getoperationstatus (["operationid", ... ])
# z_gettotalbalance ( minconf includeWatchonly )
# z_importkey "zkey" ( rescan startHeight )
# z_importviewingkey "vkey" ( rescan startHeight )
# z_importwallet "filename"
# z_listaddresses ( includeWatchonly )
# z_listoperationids
# z_listreceivedbyaddress "address" ( minconf )
# z_listunspent ( minconf maxconf includeWatchonly ["zaddr",...] )
# z_mergetoaddress ["fromaddress", ... ] "toaddress" ( fee ) ( transparent_limit ) ( shielded_limit ) ( memo )
# z_sendmany "fromaddress" [{"address":... ,"amount":...},...] ( minconf ) ( fee )
# z_setmigration enabled
# z_shieldcoinbase "fromaddress" "tozaddress" ( fee ) ( limit )
# z_viewtransaction "txid"
# zcbenchmark benchmarktype samplecount
# zcrawjoinsplit rawtx inputs outputs vpub_old vpub_new
# zcrawkeygen
# zcrawreceive zcsecretkey encryptednote
# zcsamplejoinsplit

Loading…
Cancel
Save