Libra从入门到精通或放弃
Facebook的Libra出来有一阵子, 追捧的有, 看衰的有,观望的有。笔者的观点是做总比不做好,数字货币也是社会发展的需要,官媒不也渐渐放出”数字人民币”的消息,天枰座的童虎还是不能小看的。
1.Libra是什么, 它的使命是什么?
Libra是全球最大的社交媒体facebook开发的数字货币,它的使命是建立一套简单的全球货币和金融基础设施,为数十亿人服务。
目标远大,但人家有底气啊, 二十多亿的用户,剩下就应该是监管和利益分配的问题了。
中文白皮书都准备了,文案写得还蛮好的,自行补脑。https://libra.org/zh-CN/white-paper/
2.Libra是怎么运营和管理的? Facebook一家独大?
Libra三部分组成: 它建立在安全、可扩展和可靠的区块链基础上; 它以赋予其内在价值的资产储备为后盾; 它由独立的Libra协会治理,该协会的任务是促进此金融生态系统的发展。
我们来看看站台的一些协会成员
Mastercard, visa, paypal, uber各行各业都有,计划是2020年协会创始人达到100。
有没中国玩家? 必须的,这两天, “火星财经与CSDN宣布联手发起Libra超级节点竞选” 。我觉得CSDN是想钱想疯了, gitchat也是搞钱, 可惜流量不好, 不然我也去赚点买菜钱。
天枰座的百龙霸打过来了,央行,银联,微信,支付宝和第三方支付等,后面应该会有动作,不是有一些国家想用人民币结算,虽然不多,但是数字货币基础设施总是要有的,不过会保守些,自然也是可监管,自主可控的,毕竟这里面的水很深,我们看看热闹就好。
3.聊聊技术, 官方的入门例子, my first transaction
(1)下载和构建libra核心库
git clone https://github.com/libra/libra.git
cd libra
git checkout testnet
./scripts/dev_setup.sh
看到装了rust心里有点纳闷,笔者很早就去学过rust的语法, 看了几天就给borrow checker打败了,但貌似rust蛮受外国开发者喜爱, fuchsia底层和一些区块链和数字钱包等实现也慢青睐rust, 或者真是在代码质量和内存泄漏方面有更好的保证吧。
(2)构建libra cli客户端,连接到Testnet
./scripts/cli/start_cli_testnet.sh
这里注意cmake版本必须是3以上, 否则会报一些路径不存在的错误,笔者的centos yum默认装了2的版本, yum有cmake3但好像用不了, 可能要软链接为cmake, 笔者是手工编译最新的cmake。
最后链接的时候如果发现error: linking with cc
failed: exit code: 1
通常是机器的内存不够,这些问题在libra社区都能有人碰到过,还不少国人。。
链接测试的libra节点之后应该有这样的一个控制台:
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 100000)] 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%
(3)创建账号
创建两个账号, 并列出来, 应该是相当于有个电子钱包了,长长的ID就是账号的ID了,#0是账号1, #1是账号2, 是账号下标
libra% account create
>> Creating/retrieving next account from wallet
Created/retrieved account #0 address 6d7767d1f85d6d42bb18fcea71dcb89c433d98f7779c993d25205c4b7098c608
libra% account create
>> Creating/retrieving next account from wallet
Created/retrieved account #1 address 5ce81c0cd430659fe7dcad87836a13fbff1abd77c26eb4e85b561156a2ca0543
libra% account list
User account index: 0, address: 6d7767d1f85d6d42bb18fcea71dcb89c433d98f7779c993d25205c4b7098c608, sequence number: 0, status: Local
User account index: 1, address: 5ce81c0cd430659fe7dcad87836a13fbff1abd77c26eb4e85b561156a2ca0543, sequence number: 0, status: Local
增加LBR货币到账号, 0是账号下标, 110是增加的货币数值.
libra% account mint 0 110
>> Minting coins
Mint request submitted
账号2增加52个LBR
libra% account mint 1 52
>> Minting coins
Mint request submitted
查询账户余额
libra% query balance 0
Balance is: 110.000000
libra% query balance 1
Balance is: 52.000000
(4)提起交易
查询账号交易序列号
libra% query sequence 0
>> Getting current sequence number
Sequence number is: 0
libra% query sequence 1
>> Getting current sequence number
Sequence number is: 0
转账
libra% transfer 0 1 10
>> Transferring
Transaction submitted to validator
To query for transaction status, run: query txn_acc_seq 0 0 <fetch_events=true|false>
从账号1转账给账号2, 转账金额为10个LBR 这是一个异步的交易, 可以按照提示查询交易的状态和结果
libra% query txn_acc_seq 0 0 true
>> Getting committed transaction by account and sequence number
Committed transaction: SignedTransaction {
raw_txn: RawTransaction {
sender: 6d7767d1f85d6d42bb18fcea71dcb89c433d98f7779c993d25205c4b7098c608,
sequence_number: 0,
payload: {,
transaction: peer_to_peer_transaction,
args: [
{ADDRESS: 5ce81c0cd430659fe7dcad87836a13fbff1abd77c26eb4e85b561156a2ca0543},
{U64: 10000000},
]
},
max_gas_amount: 100000,
gas_unit_price: 0,
expiration_time: 1566474041s,
},
public_key: Ed25519PublicKey(
PublicKey(CompressedEdwardsY: [15, 1, 46, 78, 137, 132, 53, 170, 38, 34, 128, 144, 239, 224, 147, 45, 134, 121, 54, 246, 18, 148, 49, 23, 149, 59, 107, 163, 117, 227, 86, 113]), EdwardsPoint{
X: FieldElement51([332936837460180, 1776699723642978, 1606759207621664, 84590882227320, 44106645692162]),
Y: FieldElement51([1553100140577039, 1673525488571718, 239582280306563, 1630075796195707, 1993887956219571]),
Z: FieldElement51([1, 0, 0, 0, 0]),
T: FieldElement51([1821266226982014, 1734000264833885, 270163309747504, 275455197065552, 1853637604830383])
}),
),
signature: Ed25519Signature(
Signature( R: CompressedEdwardsY: [220, 241, 175, 100, 238, 181, 30, 10, 252, 197, 249, 188, 143, 91, 254, 1, 0, 85, 74, 134, 77, 151, 127, 83, 31, 21, 141, 245, 68, 52, 86, 191], s: Scalar{
bytes: [100, 59, 214, 44, 139, 144, 234, 0, 179, 135, 106, 206, 52, 58, 175, 109, 166, 26, 91, 169, 121, 132, 246, 189, 156, 118, 191, 156, 197, 235, 63, 12],
} ),
),
}
Events:
ContractEvent { access_path: AccessPath { address: 6d7767d1f85d6d42bb18fcea71dcb89c433d98f7779c993d25205c4b7098c608, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/sent_events_count/" } , index: 0, event_data: AccountEvent { account: 5ce81c0cd430659fe7dcad87836a13fbff1abd77c26eb4e85b561156a2ca0543, amount: 10000000 } }
ContractEvent { access_path: AccessPath { address: 5ce81c0cd430659fe7dcad87836a13fbff1abd77c26eb4e85b561156a2ca0543, type: Resource, hash: "217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97", suffix: "/received_events_count/" } , index: 1, event_data: AccountEvent { account: 6d7767d1f85d6d42bb18fcea71dcb89c433d98f7779c993d25205c4b7098c608, amount: 10000000 } }
有点凌乱,但是看到gas的字段,嗯,类似转账是要手续费的。
也可以阻塞的调用转账,b代表是blocking
libra% transferb 0 1 10
最后验证下转账结果
libra% query balance 0
Balance is: 100.000000
libra% query balance 1
Balance is: 62.000000
4.聊下libra的设计架构
libra作为作为区块链,很多概念有些和fabric类似,例如交易,状态,账本,
也有一些自己专有的架构
具体可以参考 https://developers.libra.org/docs/libra-protocol
5.Libra用了什么共识算法?
使用的是LibraBFT, 一个HotStuff共识算法, 感觉应该是优化过, 具体参考 https://developers.libra.org/docs/crates/consensus 也有一些中文翻译, http://www.libra-cn.top/document/info/?id=17
6.智能合约使用什么语言开发?
交易脚本语言称为move, 应该也是跑在虚拟机上的, 有点solidity的感觉。 具体参考 https://developers.libra.org/docs/move-overview https://developers.libra.org/docs/assets/papers/libra-move-a-language-with-programmable-resources.pdf
简单的一个入门, 希望对大家有帮助。
- 原文作者:Zealot
- 原文链接:https://www.51discuss.com/posts/libra-introduction/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。