盧柏璋
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 2022/09/21 -- 2022/09/28 NOTE ## 盧柏璋 Working NOTE --- Original Ourchain Installation NOTE: https://hackmd.io/Bo8C0LogQfmq_eSuOExr0w?view --- Useful shell command learnt: 1. **top**: call out monitor for checking tasks working on the computer, press "q" to leave the monitor mode on terminal 2. **pgrep bitcoin**: check the label(5 or 4 digit integer Eg:29379) of the task bitcoin that you are running 3. **kill #task label integer#**: shut down the task you are running 4. **make -j 8**: means use multi-thread to work the make command, it would be 8 times faster than the normal make command 5. **gnome-screeshot**: take a screen-shot of the screen 6. **pkill -9 bitcoind**: forcely kill all working bitcoind tasks 7. **bitcoin-cli stop**: stop the bitcoin app --- NOTE: when the following error code occur on the terminal, the possible reason and method to tackel it: 1. Error: Cannot obtain a lock on data directory /home/lab408/.bitcoin/regtest. Bitcoin Core is probably already running. 1.1 ANS: "pkill" all running tasks or kill the bitcoin that is running on the computer and rerun the command : bitcoind --regtest --daemon To initiate the new node 2. --- ## 0.測試實驗 Purpose of Experiment: Understand the changes on ourchain when rpc commands input to the terminal, the EXP only focus on the changes to the folder: **"/home/lab408/Desktop/po-bitcoin-testnode1/ourchain-release/src/relay/regtest"** Notation: use **data_folder** for abbreviation of the above folder **Experiment 1:** Purpose: Understand where do the blockchain data stored ``` ./bitcoind --regtest --datadir=relay --daemon ./bitcoind --regtest --daemon ``` See the Difference in **data_folder** **Experiment 2:** Purpose: when pkill command is used, will the blockchain data still remian? ``` ``` See the Difference in data_folder **Experiment 3:** Purpose: after mining 101 blocks, what would be changed in **data_folder** ``` ``` See the Difference in data_folder **Experiment 4:** Purpose: when the contract is deployed, will elimination of the original contract#my-contract.c# affect the data in **data_folder** ``` ``` See the Difference in data_folder ## 1.安裝 Install 備註 PS: 1.The Lab 408 Computer use Ubuntu OS so use "sudo" in front of commands 2.沒有Linux環境請使用docker實驗 [參考這裡 here](https://hackmd.io/Bo8C0LogQfmq_eSuOExr0w?both#4%E7%94%A8Use-Docker%E5%BB%BA%E7%BD%AE-Build-OurChain) **安裝相關依賴套件, Installation of Dependent Packages ** ``` sudo apt-get update sudo apt-get install build-essential libtool autotools-dev automake pkg-config libssl-dev libevent-dev bsdmainutils sudo apt-get install software-properties-common ``` **若為 Ubuntu Ubuntu 18.04 或更新版本,請執行** ``` sudo add-apt-repository -y ppa:luke-jr/bitcoincore # for Ubuntu 18.04, 20.04 ``` **接著繼續安裝必要套件** ``` sudo apt-get update sudo apt-get install libdb4.8-dev libdb4.8++-dev sudo apt-get install libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-program-options-dev libboost-test-dev libboost-thread-dev sudo apt-get install git vim ``` ##### note: 亦可參考 https://github.com/bitcoin/bitcoin/blob/master/doc/build-unix.md **下載 Download OurChain code** ``` git clone -b test_version https://bitbucket.org/lab408/ourchain-release.git ``` **編譯 Compile OurChain** ``` cd ourchain-release/ ./autogen.sh ./configure make -j 8 # Or just use make but slower sudo make install # 這行是 optional 取決於你是否要把程式加到path 一般來說make完後檔案會在src內 ldconfig # sudo if needed ``` **新增 /home/lab408/Desktop/po-bitcoin-testnode1/ourchain-release/src/.bitcoin** ```shell= vim /home/lab408/Desktop/po-bitcoin-testnode1/ourchain-release/src/.bitcoin server=1 rpcuser=test rpcpassword=test rpcport=8332 rpcallowip=0.0.0.0/0 datadir=relay # means save block data to the relay folder under src ``` 恭喜你裝完了 --- ## 2.實驗 Experience **啟動比特幣回歸測試節點** --regtest代表回歸測試 在你的電腦上創建一個測試鏈 而非連到當前的主要OurChain(or bitcoin)網路 --因為我把project建立在桌面上而非根目錄下,所以有些指令可能不同 ``` Original version: bitcoind --regtest --daemon My project version: ./bitcoind --regtest --datadir=relay --daemon ``` **使用bitcoin-cli與你剛剛架設起來的測試OurChain溝通實驗** 在實驗的時候記得加上--regtest 代表你用bitcoin-cli要互動的對象是你創的回歸測試鏈 ``` bitcoin-cli --regtest getblockchaininfo //取得你剛剛架的回歸測試ourchain的整個區塊鏈資訊 ``` **OurChain挖礦實驗** 在實驗的時候記得加上--regtest 代表你用bitcoin-cli要互動的對象是你創的回歸測試鏈 ``` bitcoin-cli --regtest generate 101 //不同於bitcoin, ourcoin 挖礦使用的不是 generateblock, 而是 generate #number_of_blocks in integer ``` bitcoin-cli是bitcoin提供的一個 RPC interface 可以把他想成一個與bitcoin整個鏈互動的街口 透過bitcoin-cli提供的function來與整個bitcoin互動 有了bitcoin-cli你就可以開始你想要的實驗了 bitcoin-cli提供了很多跟ourchain互動的方法 像是剛剛的getblockchaininfo 包含其他像是創建地址、轉錢、挖礦等, 所有比特幣功能 備註:OurChain是基於bitcoin修改來的 所以適用以上功能 [請參考這裡了解所有bitcoin-cli提供的方法, all these supports](https://bitcoin.org/en/developer-reference#bitcoin-core-apis) 恭喜你 到這裡 你應該就有能力寫一個blockchain exploere 或是寫個簡單版本的wallet了 主要就是透過python(或你偏好的語言)找他的rpc-call套件 去訪問bitcoin網路取得你所需要的資料 並顯示在你的網頁上 或 APP上 --- ## 3.怎麼寫 OurContract 大致上與C一樣,不過有幾個重點需要注意 標頭檔必須加入 Need to include the following header file #include<ourcontract.h> 必須使用 need to use int contract_main(int argc,char** argv) 取代原本的to replace int main(int argc,char** argv),而且不可以使用do not use main() 因為沒有no stdout,所以請勿使用please do not use printf()等等功能,請使用 err_printf 他會輸出在bitcoin執行的資料夾下的it will output to contracts/err 範例:Hello World #include<ourcontract.h> #include<stdio.h> int contract_main(int argc,char** argv) { err_printf("Hello World %s\n",argv[0]); return 0; } 其餘功能[請參考 Refer to other functions](https://bitbucket.org/lab408/ourchain-release/src/test_version/src/contract/libourcontract.c) 如何在OurChain上執行合約 How to execute: 首先開啟ourchain後,確定自己有足夠多錢支付執行合約的手續費後,使用下面指令來發布合約並執行合約一次後 bitcoin-cli --regtest deploycontract [contract_path] 會獲得合約的名稱[contract_address] { "txid" : "[txid]" "contract address" : "[contract_address]" } 未來要再次執行合約,使用 bitcoin-cli --regtest callcontract [contract_address] ... 就可以再次執行合約,之後主動或等待他人挖礦後,合約就會自動被ourchain執行 其中上方指令後面所輸入的 [contract_address] ... 將會是int contract_main(int argc,char** argv)的 argv[0] ... --- ## 4.用Use Docker建置 Build OurChain [教學 Instruction](https://hackmd.io/@jKIkT8QLQ4SzITq06RQTvQ/H1108hT9V?type=view)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully