APCLab / bitcoin

Bitcoin Core integration/staging tree
https://bitcoin.org/en/download
MIT License
1 stars 1 forks source link

encode&decode #11

Open hychang23 opened 8 years ago

hychang23 commented 8 years ago

現在要處理的是在交易中能encode&decode所加上去的東西

@iblis17 : 誰可以跟我解釋 tx 裡的 Script 是啥? 我猜這個 function ScriptPubKeyToJSON 是 encode

iblislin commented 8 years ago

https://en.bitcoin.it/w/images/en/e/e1/TxBinaryMap.png

iblislin commented 8 years ago

https://en.bitcoin.it/wiki/Script 找個人看完,沒人要看再跟我說

hychang23 commented 8 years ago

我先看 https://en.bitcoin.it/wiki/Script

iblislin commented 8 years ago

https://en.bitcoin.it/wiki/Contract 看起來這就是說明怎麼應用?

hychang23 commented 8 years ago

我覺得Contract這篇比較像在講概念說可以用腳本寫一些應用

iblislin commented 8 years ago

聽起來就是我們要的?

hychang23 commented 8 years ago

看起來是應用3較相關 另外Scrip那篇有看沒有懂耶 第2部分的範例看不太懂

iblislin commented 8 years ago

@HuaYang-Chang 這禮拜找個時間當面聽你解釋?

hychang23 commented 8 years ago

可以阿 看你哪時方便再跟我說一下

iblislin commented 8 years ago

@HuaYang-Chang 三下午之後都可

hychang23 commented 8 years ago

好阿 我在207 下午會跟老師meeting

iblislin commented 8 years ago

/me 2 點後到

mchliu commented 8 years ago

@iblis17 華洋找到了null data transaction的寫法

https://bitcointalk.org/index.php?topic=453086.0 裡面的#19處

目前好像是可以把data放入交易了 BUT 不知道怎麼把放進去的Data取出來 需要你神來一筆

iblislin commented 8 years ago

不是有個 decode transaction 的 api?

iblislin commented 8 years ago

明天找個時間用 skype 來看看好了

iblislin commented 8 years ago

decoderawtransaction 的話會看到啥

hychang23 commented 8 years ago

ok了 有成功 我們是用getrawtransaction

hychang23 commented 8 years ago

./bitcoin-cli listunspent 找一個txid和相對應的vout

bitcoin-cli createrawtransaction '[{"txid":"from listunspent","vout":0}]' '{"data":"將要傳的data轉成hex","要給的address":$$}' return hex-encoded transaction in a string (are not signed)

./bitcoin-cli signrawtransaction hex-encoded transaction in a string return 'Returns json object with keys'

./bitcoin-cli sendrawtransaction raw transaction with signature(s) (hex-encoded string) return txid

./bitcoin-cli getrawtransaction txid 1 returns a JSON Object containing information about the transaction data會在OP_RETURN裡面

iblislin commented 8 years ago

(Y) 現在的資料量 可以放多少字?

hychang23 commented 8 years ago

目前是80bytes

iblislin commented 8 years ago

那麼 超過 80 bytes 怎麼辦?

hychang23 commented 8 years ago

sendrawtransaction那邊會出錯 error code: -26 error message: 64: scriptpubkey

iblislin commented 8 years ago

想個方法存超過 80 bytes 吧?

不過那筆交易是怎麼存到 block 裡面的?給手續費?

mchliu commented 8 years ago

@iblis17 yep 交易一定要有錢 EX: 拿一個50元 放DATA 給自己49.999 差價就是手續費給掉

老師現在要我們想辦法可以爬data下來分析 是不是要寫爬蟲還什麼東西 給個方向吧俊頤大大

iblislin commented 8 years ago

老師現在要我們想辦法可以爬data下來分析

有更多細節嘛?分析啥

mchliu commented 8 years ago

@iblis17 細節是?

就是可能在DATA裡面存評價訊息 例如: 劉銘騏 麥當勞 3分 太油太膩

然後要把資料從BLOCK CHAIN裡面撈出來

iblislin commented 8 years ago

這不是之前就做完了?

mchliu commented 8 years ago

@iblis17 撈出來放到資料庫之類的地方 要做統計或是查詢用的

我們只是可以看到裡面的東西 不知道怎麼把它通通抓出來

iblislin commented 8 years ago

大概的想法:

  1. 找出 api: 怎麼 iter 過所有的 blocks
  2. block 裡應該有 transaction id
mchliu commented 8 years ago

@iblis17 意思是先想辦法掃過所有block嗎

那請問一下要怎麼紀錄下那些txid?

iblislin commented 8 years ago

先看看 api 了, 記在哪裡啥的都還好,先抓到記在 memory

mchliu commented 8 years ago

@iblis17 不知道要用什麼記阿 :/

iblislin commented 8 years ago

@mchliu 用個 arrray 存,就是存在 memory 中,總之先拿到資料,後續再考慮存在哪裡。

iblislin commented 8 years ago

你要用啥語言都沒關係,總之用該語言的 premitive type 就會在 memory 中了

mchliu commented 8 years ago

@iblis17 有笨方法 就x=getblockhash 1 然後getblock x 然後一路掃下去 好像沒有直接掃全部的API

iblislin commented 8 years ago

@mchliu 很好啊,下個問題想:有沒有 programmable 的 api?

我是在想 bitcoin-cli 是實作了 json rpc 的 client ,他底下也是去問 bitcoind 的 rpc api。 我們需要的是 知道 bitcoind 的 rcp api 怎麼 call,然後實作隻 client 程式 拿到 json response。

https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)

這裡有 sample @mchliu 去吧 就是你了

iblislin commented 8 years ago

想寫 python 嗎

mchliu commented 8 years ago

@iblis17 找到了 listsinceblock 會把某block之後的tx通通列出

可以啊我都沒寫過

iblislin commented 8 years ago

(Y) try it out

mchliu commented 8 years ago

@iblis17 然後實作隻 client 程式 拿到 json response。 HOW?

iblislin commented 8 years ago

Here is example: https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)

mchliu commented 8 years ago

@iblis17 所以是要先弄 http://json-rpc.org/wiki/python-json-rpc 這東西嗎

可以請你解釋一下這東西在幹嘛嗎 毫無頭緒阿阿啊阿啊阿啊

iblislin commented 8 years ago

python-jsonrpc is the official JSON-RPC implementation for Python. It automatically generates Python methods for RPC calls. However, due to its design for supporting old versions of Python, it is also rather inefficient. jgarzik has forked it as Python-BitcoinRPC and optimized it for current versions. Generally, this version is recommended.

那麼就用 Bitcoin-RPC 吧

mchliu commented 8 years ago

@iblis17 Bitcoin-RPC是指? Python-BitcoinRPC?

iblislin commented 8 years ago

哦對

mchliu commented 8 years ago

@iblis17 他抓不到我扔在bitcoin.conf的username跟password阿阿阿阿阿阿 完全卡住

mchliu commented 8 years ago

@iblis17 經過一波折是可以用python叫bitcoin的API了俊頤大大 你什麼時候會回LAB?

iblislin commented 8 years ago

@mchliu 我在 313

mchliu commented 8 years ago

@iblis17 原來噢.... 以後要找你就上去找你是嗎哈

iblislin commented 8 years ago

ok