日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 物聯(lián)網(wǎng) > 區(qū)塊鏈
[導讀] Libra是Facebook 在 6/18 發(fā)表的區(qū)塊鏈解決方案。提出 LibraCoin 加密貨幣來為金融基礎建設賦能。以 Facebook 與這次參與的合作伙伴,我相信在未來能讓支付、跨國跨

Libra是Facebook 在 6/18 發(fā)表的區(qū)塊鏈解決方案。提出 LibraCoin 加密貨幣來為金融基礎建設賦能。以 Facebook 與這次參與的合作伙伴,我相信在未來能讓支付、跨國跨境金融交易都能更加地便利。

Agenda

· 環(huán)境設置

· 下載與編譯 Libra

· 連上 Libra testnet

· 建立自己的 Libra account 與透過水龍頭 (Faucet) 取得 LibraCoin

· 查詢 Libra account 的余額

· 發(fā)送 LibraCoin

· 查詢發(fā)送的 transaction

環(huán)境設置

目前 Libra 只支持 Linux 與MacOS 兩種環(huán)境,以下將以 Linux Ubuntu 18.04 作為示范。

Environment: Ubuntu 18.04 on AWS EC2t3.xlarge

# 更新一下 apt 與安裝 git,其他的環(huán)境 Libra 有提供他的 script 來安裝。

sudo apt update

sudo apt upgrade

sudo apt install git

下載與編譯Libra

第一步:下載最新的Libra存儲

$ git clone https://github.com/libra/libra.git && cd libra

Cloning into ‘libra’。..

remote: EnumeraTIng objects: 133, done.

remote: CounTIng objects: 100% (133/133), done.

remote: Compressing objects: 100% (105/105), done.

remote: Total 1717 (delta 40), reused 55 (delta 25), pack-reused 1584

Receiving objects: 100% (1717/1717), 1.89 MiB | 1.88 MiB/s, done.

Resolving deltas: 100% (340/340), done.

第二步: 安裝 Libra Core 所需的 dependencies

$ 。/scripts/dev_setup.sh

Welcome to Libra!

This script will download and install the necessary dependencies

needed to

build Libra Core. This includes:

* Rust (and the necessary components, e.g. rust-fmt, clippy)

* CMake, protobuf, go (for building protobuf)

If you‘d prefer to install these dependencies yourself, please

exit this script

now with Ctrl-C.

Proceed with installing necessary dependencies? (y) 》

。..

。..

Installing CMake.。..。.

CMake is already installed

Installing Go.。..。.

Go is already installed

Installing Protobuf.。..。.

Protobuf is already installed

Step2-opTIonal. 在安裝 dependencies 的過程間我有遇到 protoc 安裝失敗,原因是 18.04 的 apt 上面的 protobuf 版本是 3.0.0,而 Libra 所需的版本為 》= 3.6.0 ,所以導致他安裝失敗。這時我們就需要手動安裝最新版本的 protobuf 來解決這個問題。

sudo apt install unzip

PROTOC_ZIP=protoc-3.8.0-linux-x86_64.zip

curl -OL https://github.com/google/protobuf/releases/download/v3.8.0/$PROTOC_ZIP

sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc

sudo unzip -o $PROTOC_ZIP -d /usr/local include/*

rm -f $PROTOC_ZIP

第三步:編譯并執(zhí)行 Libra Cli 來連上 testnet

$ 。/scripts/cli/start_cli_testnet.sh

Building and running client in debug mode.

UpdaTIng crates.io index

Updating git repository `https://github.com/pingcap/rust-rocksdb.git`

Updating git repository `https://github.com/alexcrichton/bzip2-rs.git`

Updating git repository `https://github.com/busyjay/lz4-rs.git`

Updating git repository `https://github.com/busyjay/rust-snappy.git`

Updating git repository `https://github.com/gyscos/zstd-rs.git`

Compiling proc-macro2 v0.4.30

Compiling unicode-xid v0.1.0

Compiling syn v0.15.36

。..

。..

。..

Finished dev [unoptimized + debuginfo] target(s) in 。..s

Running `target/debug/client --host ac.testnet.libra.org --port 80 -s 。/scripts/cli/trusted_peers.config.toml`

Connected to validator at: ac.testnet.libra.org:80

usage: 《command》 《args》

Use the following commands:

account | a

Account operations

query | q

Query operations

transfer | transferb | t | tb

《sender_account_address》|《sender_account_ref_id》 《receiver_account_address》|《receiver_account_ref_id》 《number_of_coins》 [gas_unit_price (default=0)] [max_gas_amount (default 10000)] Suffix ’b‘ is for blocking.

Transfer coins from account to another.

help | h

Prints this help

quit | q!

Exit this client

Please, input commands:

libra%

看到 libra% 出現(xiàn)就代表我們已經(jīng)大功告成連上 testnet 了!

連接testnet

其實跟編譯 libra cli 是同一個 script ,除非原始碼有更動,他就不會浪費時間在重復編譯上了。

$ 。/scripts/cli/start_cli_testnet.sh

Building and running client in debug mode.

。..

。..

。..

。..

Finished dev [unoptimized + debuginfo] target(s) in 。..s

Running `target/debug/client --host ac.testnet.libra.org --port 80 -s 。/scripts/cli/trusted_peers.config.toml`

Connected to validator at: ac.testnet.libra.org:80

usage: 《command》 《args》

Use the following commands:

account | a

Account operations

query | q

Query operations

transfer | transferb | t | tb

《sender_account_address》|《sender_account_ref_id》 《receiver_account_address》|《receiver_account_ref_id》 《number_of_coins》 [gas_unit_price (default=0)] [max_gas_amount (default 10000)] Suffix ’b‘ is for blocking.

Transfer coins from account to another.

help | h

Prints this help

quit | q!

Exit this client

Please, input commands:

libra%

建立自己的Libra account

所有跟 account 相關的功能都在 account 下面,我們可以先下 account 這個指令來看看有哪些功能可以使用吧!

libra% account

usage: account 《arg》

Use the following args for this command:

create | c

Create an account. Returns reference ID to use in other operations

list | la

Print all accounts that were created or loaded

recover | r 《file_path》

Recover Libra wallet from the file path

write | w 《file_path》

Save Libra wallet mnemonic recovery seed to disk

mint | mintb | m | mb 《receiver_account_ref_id》|《receiver_account_address》 《number_of_coins》

Mint coins to the account. Suffix ’b‘ is for blocking

它主要有五大功能:

· Create: 建立一個賬號,每個賬號在 local 會給一個 reference ID,舉例來說,第一個被建立的賬號就是 ID=0。

libra% account create

》》 Creating/retrieving next account from wallet

Created/retrieved account #0 address

fafbbc8aeed4b019ee8d1be854aa5279b26a07d5957b3a5a04e9aaa351bea2f0

# 可以看到我建立的第一個賬號,他的 reference ID #0

# 以及我的 address 就是下面那一大串 hex string

# 如果是在同一個 libra cli 操作,我們都可以使用 reference ID 作為賬號的

alias。如果是要請別人從他的 libra cli 發(fā) transaction 給你的賬號,

那就需要直接給對方你的 address 了。

· List: 印出所有被建立或者被加載的賬號。

libra% account list

User account index: 0, address:

fafbbc8aeed4b019ee8d1be854aa5279b26a07d5957b3a5a04e9aaa351bea2f0,

sequence number: 0, status: Persisted

# 列出現(xiàn)有的賬號。Sequence number 則是代表了這個 account

發(fā)起過幾個 transaction。

· Recover: 從一個文件還原一個錢包賬號。像是 import wallet。

· Write: 將錢包賬號儲存到一個檔案。像是 export wallet。

· Mint: 請水龍頭 (Faucet) 發(fā)錢給一個指定的賬號。

# 請水龍頭發(fā)錢的指令是

# account mint 《account address/ref_id》 《number_of_coin》

# 以下示范發(fā) 320 顆 Libra Token 給第一個賬號。

libra% account mint 0 320

》》 Minting coins

Mint request submitted

· Hint: 跟 transaction 相關的操作(mint/transfer)都有提供 blocking 與 non-blocking 的版本。想要使用 blocking 的版本,比如說要等水龍頭真的發(fā)錢給你,那我們可以使用下面這種語法:

libra% account mintb 1 1205

》》 Minting coins

[waiting

Transaction completed, found sequence number 9357

Finished minting!

他就會直接卡住并印出 waiting 直到這個 Transaction 被完成為止。

查詢Libra account的余額

語法是 query balance 《account address/ref_id》

libra% query balance 0

Balance is: 320

發(fā)送Libra幣

轉(zhuǎn)賬的語法如下:

transfer 《sender address/ref_id》 《receiver address/ref_id》

《number_of_coins》 [gas_unit_price (default=0)]

[max_gas_amount (default 10000)]

tranfer 一共有五個參數(shù):

1. Sender Account 的 address 或 reference id

2. Receiver Account 的 address 或 reference id

3. 要發(fā)送多少數(shù)量的 libra

4. 這次 transaction 的 gas 手續(xù)費,預設是 0。這個參數(shù)可以不給。

5. 這次 transaction 的最高 gas 限制,預設是 10000。這個參數(shù)可以不給。

舉例而言,如果我想從Account #0 轉(zhuǎn) 100Libra 給Account #1,我可以這樣寫 transfer 0 1 100 。

查詢發(fā)送的transaction

查詢交易的指令為:

query txn_acc_seq 《account address/ref_id》 《sequence_number》

《fetch_events=true|false》

一共有三個參數(shù):

1. Account 的 address 或 reference ID。

2. Sequence Number: 在 Libra 的設計中,sequence number 代表了該 account 發(fā)起了幾個交易,每發(fā)起一次交易且被收進 Libra blockchain 中這個數(shù)字就會 +1 。這個設計是為了避免 replay 攻擊,每個發(fā)送出去的transaction 帶有當前 account 的 sequence number ,而發(fā)送出去的 transaction 會先被放入 mempool 中等待被執(zhí)行。當 Libra blockchain 從 mempool 中拿 transaction 出來執(zhí)行的時候會去比對當前的 account sequence number 是否跟 transaction 的 sequence number 相同。若相同才能執(zhí)行,且馬上會把 account 的 sequence number +1 ,這樣即使在 mempool 中有多個重復的 transaction 也只會有一個合法的能被執(zhí)行,其他的將會被丟棄。

3. 是否需要抓取 events。

完整的情景案例

在發(fā)送 LibraCoin 之前,我們需要有兩個賬號來進行轉(zhuǎn)賬。以下將示范從建立兩個賬號、各自從水龍頭領到 LibraCoin 以及轉(zhuǎn)賬的過程吧!

# 建立第一個賬號 alice

libra% account create

》》 Creating/retrieving next account from wallet

Created/retrieved account #0 address

7faff73ba54fc82503ecd6438455e8a4ab0a26dc35d399e6593bb1058338e140

# 建立第二個賬號 bob

libra% account create

》》 Creating/retrieving next account from wallet

Created/retrieved account #1 address

bf2df78de21ea3727e0d48ae7142718f8c33f7eca854ac81b8866361fa2bd15d

# 幫 alice 要 320 個 libra

libra% account mint 0 320

》》 Minting coins

Mint request submitted

# 查詢 alice 的 balance

libra% query balance 0

Balance is: 320

# 幫 bob 要 1205 個 libra

libra% account mint 1 1205

》》 Minting coins

Mint request submitted

# 查詢 bob 的 balance

libra% query balance 1

Balance is: 1205

# 從 alice 轉(zhuǎn) 20 個 libra 給 bob

libra% transfer 0 1 20

》》 Transferring

Transaction submitted to validator

To query for transaction status, run: query txn_acc_seq 0 0

《fetch_events=true|false》

# 查詢 transaction

libra% query txn_acc_seq 0 0 true

》》 Getting committed transaction by account and sequence number

Committed transaction: SignedTransaction {

raw_txn: RawTransaction {

sender:

7faff73ba54fc82503ecd6438455e8a4ab0a26dc35d399e6593bb1058338e140,

sequence_number: 0,

payload: {,

transaction: peer_to_peer_transaction,

args: [

{ADDRESS:

bf2df78de21ea3727e0d48ae7142718f8c33f7eca854ac81b8866361fa2bd15d},

{U64: 20000000},

},

max_gas_amount: 10000,

gas_unit_price: 0,

expiration_time: 1560912163s,

},

public_key:

a2b9f68d1abbc887a39789a7f428df68adabfff395fff71bd0d0fe5674bdfbad,

signature: Signature( R: CompressedEdwardsY:

[74, 249, 58, 185, 235, 16, 175, 193, 158, 86, 31, 249, 215, 97,

138, 153, 65, 183, 161, 229, 162, 198, 30, 107, 246, 191, 44, 250,

12, 96, 20, 55], s: Scalar{

bytes: [170, 99, 70, 224, 9, 167, 230, 162, 110, 38, 87, 53, 164,

36, 91, 34, 116, 52, 73, 91, 169, 141, 159, 194, 40, 206, 16, 151,

5, 101, 91, 1],

} ),

}

Events:

ContractEvent { access_path: AccessPath { address:

7faff73ba54fc82503ecd6438455e8a4ab0a26dc35d399e6593bb1058338e140,

type: Resource, hash:

“217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97”,

suffix: “/sent_events_count/” } , index: 0, event_data: AccountEvent {

account: bf2df78de21ea3727e0d48ae7142718f8c33f7eca854ac81b8866361fa2b

d15d, amount: 20000000 } }

ContractEvent { access_path: AccessPath { address:

bf2df78de21ea3727e0d48ae7142718f8c33f7eca854ac81b8866361fa2bd15d,

type: Resource, hash: “217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647

c78df00b371b25cc97”, suffix: “/received_events_count/” } ,

index: 0, event_data: AccountEvent {

account: 7faff73ba54fc82503ecd6438455e8a4ab0a26dc35d399e6593bb1058338

e140, amount: 20000000 } }

常見錯誤

Libra testnet 有擋一個區(qū)間內(nèi)的爆量 request,如果你在短時間內(nèi)送一堆 transaction (mint or transfer) 有機會拿到下面這個 error:

[ERROR] Error minting coins: Failed to query remote faucet server

[status=429 Too Many Requests]: “《html》《body》《h1》429 Too Many Requests

《/h1》 You have sent too many requests in a given amount of time.

《/body》《/html》 ”

這時候只要稍等一下再重新送那筆 transaction 就能解除了。

本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

LED驅(qū)動電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關鍵字: 驅(qū)動電源

在工業(yè)自動化蓬勃發(fā)展的當下,工業(yè)電機作為核心動力設備,其驅(qū)動電源的性能直接關系到整個系統(tǒng)的穩(wěn)定性和可靠性。其中,反電動勢抑制與過流保護是驅(qū)動電源設計中至關重要的兩個環(huán)節(jié),集成化方案的設計成為提升電機驅(qū)動性能的關鍵。

關鍵字: 工業(yè)電機 驅(qū)動電源

LED 驅(qū)動電源作為 LED 照明系統(tǒng)的 “心臟”,其穩(wěn)定性直接決定了整個照明設備的使用壽命。然而,在實際應用中,LED 驅(qū)動電源易損壞的問題卻十分常見,不僅增加了維護成本,還影響了用戶體驗。要解決這一問題,需從設計、生...

關鍵字: 驅(qū)動電源 照明系統(tǒng) 散熱

根據(jù)LED驅(qū)動電源的公式,電感內(nèi)電流波動大小和電感值成反比,輸出紋波和輸出電容值成反比。所以加大電感值和輸出電容值可以減小紋波。

關鍵字: LED 設計 驅(qū)動電源

電動汽車(EV)作為新能源汽車的重要代表,正逐漸成為全球汽車產(chǎn)業(yè)的重要發(fā)展方向。電動汽車的核心技術之一是電機驅(qū)動控制系統(tǒng),而絕緣柵雙極型晶體管(IGBT)作為電機驅(qū)動系統(tǒng)中的關鍵元件,其性能直接影響到電動汽車的動力性能和...

關鍵字: 電動汽車 新能源 驅(qū)動電源

在現(xiàn)代城市建設中,街道及停車場照明作為基礎設施的重要組成部分,其質(zhì)量和效率直接關系到城市的公共安全、居民生活質(zhì)量和能源利用效率。隨著科技的進步,高亮度白光發(fā)光二極管(LED)因其獨特的優(yōu)勢逐漸取代傳統(tǒng)光源,成為大功率區(qū)域...

關鍵字: 發(fā)光二極管 驅(qū)動電源 LED

LED通用照明設計工程師會遇到許多挑戰(zhàn),如功率密度、功率因數(shù)校正(PFC)、空間受限和可靠性等。

關鍵字: LED 驅(qū)動電源 功率因數(shù)校正

在LED照明技術日益普及的今天,LED驅(qū)動電源的電磁干擾(EMI)問題成為了一個不可忽視的挑戰(zhàn)。電磁干擾不僅會影響LED燈具的正常工作,還可能對周圍電子設備造成不利影響,甚至引發(fā)系統(tǒng)故障。因此,采取有效的硬件措施來解決L...

關鍵字: LED照明技術 電磁干擾 驅(qū)動電源

開關電源具有效率高的特性,而且開關電源的變壓器體積比串聯(lián)穩(wěn)壓型電源的要小得多,電源電路比較整潔,整機重量也有所下降,所以,現(xiàn)在的LED驅(qū)動電源

關鍵字: LED 驅(qū)動電源 開關電源

LED驅(qū)動電源是把電源供應轉(zhuǎn)換為特定的電壓電流以驅(qū)動LED發(fā)光的電壓轉(zhuǎn)換器,通常情況下:LED驅(qū)動電源的輸入包括高壓工頻交流(即市電)、低壓直流、高壓直流、低壓高頻交流(如電子變壓器的輸出)等。

關鍵字: LED 隧道燈 驅(qū)動電源
關閉