Rubyライブラリ"counterparty_ruby"を使ってみる(3/3)
はじめに
前回に引き続き@derosetechのcounterparty_rubyを使ってみます。
今回はCounterparty Contractsをやります。現在はTestnet上のみ動作可能です。
目次
- pyethereum(Ethereum Python Client)インストール
- Serpent Contract実装、実行
pyethereum(Ethereum Python Client)インストール
Ethereumのプロダクトをインストールします。
$ git clone https://github.com/ethereum/pyethereum/ $ sudo python setup.py install
Serpent Contract実装、実行
/home/xcp/counterparty_ruby-master/demo_smartcontract.rb
require 'open3' require 'counterparty_ruby' class Serpent # Be sure to use the version from : https://github.com/ethereum/pyethereum SERPENT='/usr/local/bin/serpent' def compile(contract) serpent 'compile', '-s', :stdin_data => contract end def encode_datalist(data) serpent 'encode_datalist', data end private def serpent(*args) options = (args.last.kind_of? Hash) ? args.pop : {} stdout, status = Open3.capture2( ([SERPENT]+args).join(' '), options) raise StandardError, "Compile Failed: %s" % status.exitstatus unless status.success? stdout.chomp end end SOURCE_ADDRESS="mo1kgfktQfRaLMR5SvehDMHLa9Cu7xJp4m" Counterparty.test! serpent = Serpent.new compiled_script = serpent.compile <<-eos return(msg.data[0]*2) eos contract_id = Counterparty::Publish.new( source: SOURCE_ADDRESS, code_hex: compiled_script, gasprice: 1, startgas: 1000000, endowment: 0, allow_unconfirmed_inputs: true ).save! datalist = serpent.encode_datalist '53' execute_id = Counterparty::Execute.new( source: SOURCE_ADDRESS, contract_id: contract_id, payload_hex: datalist, gasprice: 5, startgas: 160000, value: 10, allow_unconfirmed_inputs: true ).save! puts "Executed Transaction ID: %s" % execute_id
実行
ruby -I /home/xcp/counterparty_ruby-master/lib demo_smartcontract.rb
まとめ
Blockscanを見るとBlockchainに内容が登録されていますが、その内容の意味がよく分かりません。Counterparty ContractsとEthereumのドキュメントを読む必要がありそうです(大変だ..)
とりあえず今回は、Testnet上はCounterparty Contractsを動かすことができる。ということが分かりました。