操作系統(tǒng):MAC OS 10.14.x,libra版本:testnet
搭建Libra測(cè)試網(wǎng)絡(luò)
由于Libra網(wǎng)絡(luò)還沒(méi)有正式運(yùn)轉(zhuǎn),我們要體驗(yàn)Libra體系架構(gòu),可以通過(guò)測(cè)試網(wǎng)絡(luò)來(lái)進(jìn)行。
根據(jù)Libra的文檔,想要運(yùn)行Libra測(cè)試網(wǎng)絡(luò),需要Linux或MacOS操作系統(tǒng),本文以MacOS系統(tǒng)為例進(jìn)行講解。
官方的例子,My First Transaction
1、下載和構(gòu)建Libra核心庫(kù)
git clone https://github.com/libra/libra.git
cd libra
//注意切換到測(cè)試分支
git checkout testnet
//安裝依賴,需要一些時(shí)間
./scripts/dev_setup.sh
2、構(gòu)建Libra cli客戶端,連接Testnet
還是貼上第一手資料,直接開發(fā)者網(wǎng)站進(jìn)去
https://developers.libra.org/docs/my-first-transaction
./scripts/cli/start_cli_testnet.sh
連接測(cè)試網(wǎng)節(jié)點(diǎn)之后會(huì)出現(xiàn)Libra的控制臺(tái):
Building and running client in debug mode.
Finished dev [unoptimized + debuginfo] target(s) in 0.93s
Running `target/debug/client --host ac.testnet.libra.org --port 8000 -s ./scripts/cli/consensus_peers.config.toml`
Connected to validator at: ac.testnet.libra.org:8000
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_in_micro_libras (default=0)] [max_gas_amount_in_micro_libras (default 140000)] Suffix 'b' is for blocking.
Transfer coins (in libra) from account to another.
help | h
Prints this help
quit | q!
Exit this client
Please, input commands:
libra%
可能的錯(cuò)誤
一開始我沒(méi)有切換到測(cè)試網(wǎng)分支,出現(xiàn)以下錯(cuò)誤:
Not able to connect to validator at ac.testnet.libra.org:80, error RpcFailure(RpcStatus { status: DeadlineExceeded, details: Some("Deadline Exceeded") })
查看issue, https://github.com/libra/libra/issues/38
需要修改libra/client/src/grpc_client.rs 增大5000
fn get_default_grpc_call_option() -> CallOption {
CallOption::default()
.wait_for_ready(true)
.timeout(std::time::Duration::from_millis(5000))
}
嘗試后沒(méi)有用,切換到testnet分支,無(wú)須改這個(gè)參數(shù)也可以運(yùn)行。但是還是建議將5000增大,控制臺(tái)交互的時(shí)候會(huì)報(bào)錯(cuò)。
3、創(chuàng)建賬號(hào)
libra% account create
>> Creating/retrieving next account from wallet
Created/retrieved account #0 address dcaaf919d82f969f72ee873cb472c8bffd009f36bcfddce15c61acb8cff43fb8
libra% account create
>> Creating/retrieving next account from wallet
Created/retrieved account #1 address 2fdc5c83f862983c1af2f4478a9c9e75a52b084ae18b7adf18c62aba92ea9f57
libra% account list
User account index: 0, address: dcaaf919d82f969f72ee873cb472c8bffd009f36bcfddce15c61acb8cff43fb8, sequence number: 5, status: Persisted
User account index: 1, address: 2fdc5c83f862983c1af2f4478a9c9e75a52b084ae18b7adf18c62aba92ea9f57, sequence number: 1, status: Persisted
給賬號(hào)添加LBR,因?yàn)槭菧y(cè)試網(wǎng),可以任意給
1.給賬號(hào)0增加libra貨幣,0是賬號(hào)的序號(hào),99999時(shí)增加的貨幣數(shù)量
libra% account mint 0 99999
>> Minting coins
Mint request submitted
2.賬號(hào)1增加999990000 libra
libra% account mint 1 999990000
>> Minting coins
Mint request submitted
查詢賬戶余額
libra% query balance 0
Balance is: 111758.000000
libra% query balance 1
Balance is: 999992428.000000
因?yàn)槲乙呀?jīng)多次測(cè)試了,每次產(chǎn)生的賬號(hào)都是一樣的,我每次新增libra,賬號(hào)的的幣一直增加的,所以查出來(lái)的值和新增的數(shù)量不一樣。
4、發(fā)起交易
libra% transfer 0 1 199
>> Transferring
Transaction submitted to validator
To query for transaction status, run: query txn_acc_seq 0 5 <fetch_events=true|false>
從賬號(hào)0 給賬號(hào)1轉(zhuǎn)賬,金額為199個(gè)LBR
這是一個(gè)異步的交易,可以按照提示查詢交易的狀態(tài)和結(jié)果
libra% query txn_acc_seq 0 5 true
>> Getting committed transaction by account and sequence number
Committed transaction: SignedTransaction {
raw_txn: RawTransaction {
sender: dcaaf919d82f969f72ee873cb472c8bffd009f36bcfddce15c61acb8cff43fb8,
sequence_number: 5,
payload: {,
transaction: peer_to_peer_transaction,
args: [{
ADDRESS: 2 fdc5c83f862983c1af2f4478a9c9e75a52b084ae18b7adf18c62aba92ea9f57
},
{
U64: 199000000
},
]
},
max_gas_amount: 140000,
gas_unit_price: 0,
expiration_time: 1574768307 s,
},
public_key: Ed25519PublicKey(
PublicKey(CompressedEdwardsY: [132, 63, 87, 219, 131, 225, 137, 96, 167, 50, 234, 206, 254, 61, 126, 127, 125, 85, 133, 190, 0, 51, 37, 96, 113, 203, 176, 144, 227, 70, 142, 19]), EdwardsPoint {
X: FieldElement51([1176422284674184, 2225165124562903, 675262596504187, 1992089984303741, 814523880810113]),
Y: FieldElement51([529431413604228, 2209869227944977, 586408896887031, 1610441249357919, 344028729641740]),
Z: FieldElement51([1, 0, 0, 0, 0]),
T: FieldElement51([939970195170134, 1770098148800191, 1254516232889842, 768125926758313, 861953446577628])
}),
),
signature: Ed25519Signature(
Signature(R: CompressedEdwardsY: [69, 224, 12, 118, 196, 144, 20, 71, 54, 203, 181, 195, 132, 4, 20, 44, 145, 163, 96, 227, 66, 158, 51, 106, 225, 80, 181, 255, 159, 152, 203, 145], s: Scalar {
bytes: [122, 15, 164, 241, 3, 55, 37, 235, 119, 169, 163, 159, 129, 120, 6, 7, 209, 223, 65, 192, 234, 149, 158, 150, 14, 42, 202, 208, 127, 226, 26, 14],
}),
),
}
Events:
ContractEvent {
key: 7943 a726db0d1376bf935dbb032a3840219de0b2f66f484686110358855dda62,
index: 5,
type: Struct(StructTag {
address: 0000000000000000000000000000000000000000000000000000000000000000,
module: Identifier("LibraAccount"),
name: Identifier("SentPaymentEvent"),
type_params: []
}),
event_data: AccountEvent {
amount: 199000000,
account: 2 fdc5c83f862983c1af2f4478a9c9e75a52b084ae18b7adf18c62aba92ea9f57
}
}
ContractEvent {
key: e4a2f1506d395fdba536d8f6df31a3486b43295b6487a515bcdd0b4aef3f23a9,
index: 9,
type: Struct(StructTag {
address: 0000000000000000000000000000000000000000000000000000000000000000,
module: Identifier("LibraAccount"),
name: Identifier("ReceivedPaymentEvent"),
type_params: []
}),
event_data: AccountEvent {
amount: 199000000,
account: dcaaf919d82f969f72ee873cb472c8bffd009f36bcfddce15c61acb8cff43fb8
}
}
顯示的信息比較雜,不像eth、eos簡(jiǎn)潔,吐槽。。。發(fā)送方和接收方都有event。
查詢賬號(hào)的余額,發(fā)生變化199的變化,轉(zhuǎn)賬成功,可以根據(jù)序號(hào)和地址查詢
libra% query balance 0
Balance is: 111559.000000
libra% query balance 1
Balance is: 999992627.000000
libra% query balance dcaaf919d82f969f72ee873cb472c8bffd009f36bcfddce15c61acb8cff43fb8
Balance is: 111559.000000
libra% query balance 2fdc5c83f862983c1af2f4478a9c9e75a52b084ae18b7adf18c62aba92ea9f57
Balance is: 999992627.000000
如果需要確認(rèn)狀態(tài)轉(zhuǎn)賬成功, 可以用阻塞轉(zhuǎn)賬命令,本地目測(cè)也是1s左右完成吧,b代表是blocking
libra% transferb 0 1 10
>> Transferring
waiting transaction is stored!
Finished transaction!
To query for transaction status, run: query txn_acc_seq 0 6 <fetch_events=true|false>
5、一些有用的命令:
libra% query account_state 0
>> Getting latest account state
Latest account state is:
Account: dcaaf919d82f969f72ee873cb472c8bffd009f36bcfddce15c61acb8cff43fb8
State: Some(
AccountStateBlob {
Raw: 0x010000002100000001a208df134fefed8442b1f01fab59071898f5a1af5164e12c594de55a7004a91c8e00000020000000dcaaf919d82f969f72ee873cb472c8bffd009f36bcfddce15c61acb8cff43fb840a9d6f81900000000000700000000000000200000002b6d9dc7398d37ef178df6c492722418638ad40664e5ff5c5410c540a84915c70700000000000000200000007943a726db0d1376bf935dbb032a3840219de0b2f66f484686110358855dda620700000000000000
Decoded: AccountResource {
authentication_key: 0xdcaaf919d82f969f72ee873cb472c8bffd009f36bcfddce15c61acb8cff43fb8,
balance: 111549000000,
delegated_key_rotation_capability: false,
delegated_withdrawal_capability: false,
received_events: EventHandle {
count: 7,
key: EventKey(
[
43,
109,
157,
199,
57,
141,
55,
239,
23,
141,
246,
196,
146,
114,
36,
24,
99,
138,
212,
6,
100,
229,
255,
92,
84,
16,
197,
64,
168,
73,
21,
199,
],
),
},
sent_events: EventHandle {
count: 7,
key: EventKey(
[
121,
67,
167,
38,
219,
13,
19,
118,
191,
147,
93,
187,
3,
42,
56,
64,
33,
157,
224,
178,
246,
111,
72,
70,
134,
17,
3,
88,
133,
93,
218,
98,
],
),
},
sequence_number: 7,
}
},
)
Blockchain Version: 98542
這個(gè)顯示是不是bug,EventKey顯示有問(wèn)題。
忘記命令格式會(huì)有提示
libra% transfer 0 1
Invalid number of arguments for transfer
transfer | transferb | t | tb
<sender_account_address>|<sender_account_ref_id> <receiver_account_address>|<receiver_account_ref_id> <number_of_coins> [gas_unit_price_in_micro_libras (default=0)] [max_gas_amount_in_micro_libras (default 140000)] Suffix 'b' is for blocking.
6、Libra一手資料
Libra 官網(wǎng)
Libra 白皮書
Libra 技術(shù)白皮書
Libra 開發(fā)者文檔: 這個(gè)寫的非常詳細(xì),可以快速上手。
?
?
接下來(lái)一段時(shí)間,和大家一起學(xué)習(xí)Libra。
交流可加QQ群:693883930