Recommanded Free YOUTUBE Lecture: <% selectedImage[1] %>

Contents

공부는 기본 개념 문서 + 개발 환경 구축해서 코드 따라하기가 최고이기는 하다. 우분투 리눅스 20.04에서 테스트 했다.

첫번째 트랜잭션

Libra Core 저장소를 clone 한다.
# git clone https://github.com/libra/libra.git && cd libra

testnet 브랜치를 checkout 한다.
# git checkout testnet

Libra Core가 제공하는 스크립트를 이용해서 종속성이 걸린 코드들을 설치한다.
# ./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
      * Clang

If you'd prefer to install these dependencies yourself, please exit this script
now with Ctrl-C.

Proceed with installing necessary dependencies? (y/N) > y
이 스크립트는 Libra 개발에 필요한 기타등등을 모두 설치해 준다.
  • rustup : Rust 프로그래밍 언어 인스톨 프로그램이다. Libra core를 rust로 만들었다.
  • rust-toolchain
  • CMake
  • protoc : protocol buffer 컴파일러
  • Go : protocol buffer를 빌딩하기 위해서
아뭏든 골고루 설치한다.

Libra CLI 클라이언트 빌드와 Testnet 연결

아래 스크립트를 이용해서 Libra testnet에 연결 할 수 있다.
# ./scripts/cli/start_cli_testnet.sh 
Building and running client in debug mode.
    Updating crates.io index
스크립트를 이용하면 cargo(Ruest의 패키지 관리자)를 이용해서 클라이언트를 빌드하고 testnet 노드에 연결한다. 함참을 빌드를 하고 나면 아래와 같이 libra 클라이언트 프롬프트가 뜬다.
	Prints this help
quit | q! 
	Exit this client


Please, input commands: 

libra% 

Alice와 Bob 어카운트를 만든다.

 Account Create

이렇게 클라이언트가 testnet에 연결했다. 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> <currency_code> [use_base_units (default=false)]
	Mint coins to the account. Suffix 'b' is for blocking
addc | addcb | ac | acb <account_address> <currency_code>
	Add specified currency to the account. Suffix 'b' is for blocking

이제 Alice 어카운트를 만들어보자.
libra% account create
>> Creating/retrieving next account from wallet
INFO 2020-07-10 01:32:38 testsuite/cli/src/libra_client.rs:255 Verified epoch changed to EpochState [epoch: 1, validator: ValidatorSet: [0e5c92a4: 1, 4c9e1d06: 1, 65fe97db: 1, b1aaf856: 1, dbd86357: 1, fe5dafe6: 1, ]]
Created/retrieved account #0 address ea9f56dd379009be6110f05a50a3792b
Alice 계정의 인덱스와 address를 확인 할 수 있다.

Bob 어카운트를 만든다.
libra% account create
>> Creating/retrieving next account from wallet
INFO 2020-07-10 01:42:54 testsuite/cli/src/libra_client.rs:268 Verified version change to: 61647315
Created/retrieved account #1 address f24528a936fe30786ddf8928fe06a3a4

어카운트 목록을 확인해보자.
libra% account list
User account index: 0, address: ea9f56dd379009be6110f05a50a3792b, sequence number: 0, status: Local
User account index: 1, address: f24528a936fe30786ddf8928fe06a3a4, sequence number: 0, status: Local
0 번이 Alice 1 번이 Bob이다.

Alice 어카운트와 Bob 어카운트에 Libra 코인 추가하기

 Mint

테스트넷 계정에 코인을 쉽게 추가하기 위한 Faucet가 존재한다. 어디까지나 테스트를 목적으로 하는 것이므로 테스트넷에만 있을 뿐 메인넷에는 존재하지 않는다.

Alice 어카운트에 110 LBR을 추가한다.

Alice 어카운트에 LBR을 추가했다.
libra% account mint 0 110 LBR
>> Minting coins
Mint request submitted
  • 0은 Alice 어카운트의 인덱스 번호다.
  • 110은 Alice 어카운트에 추가할 LBR 이다.
  • LBR은 Libra currency 코드다.
Mint request submitted가 출력되면 성공.

Bob 어카운트에 52 LBR을 추가한다.

libra% account mint 1 52 LBR
>> Minting coins
Mint request submitted

Balance 확인

Alice 어카운트의 balance(잔고)를 확인해보자.
libra% query balance 0
INFO 2020-07-10 06:41:26 testsuite/cli/src/libra_client.rs:268 Verified version change to: 63110844
Balance is: 110.000000LBR

Bob도 확인
libra% query balance 1
INFO 2020-07-10 06:43:24 testsuite/cli/src/libra_client.rs:268 Verified version change to: 63120677
Balance is: 52.000000LBR

Transaction Submit

Alice 계정에서 Bot 계정으로 Libra를 이전하기 위한 transaction을 제출하기 전에 각 계정의 sequence 번호를 쿼리해보자. 이를 통해서 거래가 실행 될 때 sequence가 어떻게 변경되는지 보다 쉽게 이해할 수 있을 것이다.

계정의 Sequence 번호 쿼리

libra% query sequence 0
>> Getting current sequence number
Sequence number is: 0
libra% query sequence 1
>> Getting current sequence number
Sequence number is: 0
두 계정 모두 Sequence가 0이다. transaction이 한번도 일어나지 않았음을 알 수 있다.

송금

Allice 가 Bob에게 10 LBR을 보낸다.
libra% transfer 0 1 10 LBR
>> Transferring
Transaction submitted to validator
To query for transaction status, run: query txn_acc_seq 0 0 <fetch_events=true|false>

query txn_acc_seq 0 0 true 명령으로 제출한 트랜잭션 정보를 확인 할 수 있다. 첫번째 매개변수는 발신자의 계정 인덱스이고, 두번째는 시퀀스 번호다.
libra% query txn_acc_seq 0 0 true
>> Getting committed transaction by account and sequence number
INFO 2020-07-10 06:48:06 testsuite/cli/src/libra_client.rs:268 Verified version change to: 63144545
Committed transaction: TransactionView {
    version: 63135218,
    transaction: UserTransaction {
        sender: "ea9f56dd379009be6110f05a50a3792b",
        signature_scheme: "Scheme::Ed25519",
        signature: "b5e919be0949d02818cd8ed1b5111b1822b8af029fbf138512827fafeb693eebe3181af3c9fe240594e30179a8fa756d2a8eea5087b8fcb1d5860daccda2910d",
        public_key: "d9c2268c30e2f7e9858dd21d73647fc0f620c3e760ad0be9919a150dcd14d0c4",
        sequence_number: 0,
        max_gas_amount: 1000000,
        gas_unit_price: 0,
        gas_currency: "LBR",
        expiration_time: 1594363674,
        script_hash: "63d97307fb9724746bc7873ae1b2573c1dee395bbdb40b3484af18cd422be27a",
        script: PeerToPeer {
            receiver: "f24528a936fe30786ddf8928fe06a3a4",
            amount: 10000000,
            currency: "LBR",
            metadata: BytesView(
                "",
            ),
            metadata_signature: BytesView(
                "",
            ),
        },
    },
    hash: "b39706a4",
    events: [
        EventView {
            key: BytesView(
                "0100000000000000ea9f56dd379009be6110f05a50a3792b",
            ),
            sequence_number: 0,
            transaction_version: 63135218,
            data: SentPayment {
                amount: AmountView {
                    amount: 10000000,
                    currency: "LBR",
                },
                receiver: BytesView(
                    "f24528a936fe30786ddf8928fe06a3a4",
                ),
                metadata: BytesView(
                    "",
                ),
            },
        },
        EventView {
            key: BytesView(
                "0000000000000000f24528a936fe30786ddf8928fe06a3a4",
            ),
            sequence_number: 1,
            transaction_version: 63135218,
            data: ReceivedPayment {
                amount: AmountView {
                    amount: 10000000,
                    currency: "LBR",
                },
                sender: BytesView(
                    "ea9f56dd379009be6110f05a50a3792b",
                ),
                metadata: BytesView(
                    "",
                ),
            },
        },
    ],
    vm_status: EXECUTED,
    gas_used: 74942,
}

트랜잭션이 완료된 후 Sequence 확인

libra% query sequence 0
>> Getting current sequence number
INFO 2020-07-10 07:17:47 testsuite/cli/src/libra_client.rs:268 Verified version change to: 63289629
Sequence number is: 1

libra% query sequence 1
>> Getting current sequence number
INFO 2020-07-10 07:23:47 testsuite/cli/src/libra_client.rs:268 Verified version change to: 63320340
Sequence number is: 0

Sequence number는 계정에서 발생한 트랜잭션의 갯수다. 트랜잭션이 완료될 때마다 1씩 늘어난다. Alice 계정의 트랜잭션 시퀀스가 1이다. 이는 지금까지 Alice의 계정에서 하나의 트랜잭션, 하나의 거래가 전송되었음을 나타낸다. Bob의 경우 시퀀스가 실행되지 않았는데, 이는 Bob이 트랜잭션을 수행하지 않았음을 즉 거래를 전송하지 않았음을 의미한다.

밸런스 확인

거래가 성공적으로 수행했는지 잔액을 확인해 보자.
libra% query balance 0
Balance is: 100.000000LBR

libra% query balance 1
Balance is: 62.000000LBR

Libra Blockchain explore

Libra Blockchain explorer 사이트를 이용해서 어카운트와 트랜잭션 정보를 확인 할 수 있다.

 Libra blockchain explorer

테스트에 사용했던 address로 검색을 하면 아래와 같이 현재 Balance, Transaction 정보를 확인 할 수 있다.

 트랜잭션 정보

Transaction Version을 클릭하면 상세정보를 확인 할 수 있다.

 Transaction 상세정보
  • Type : P2P 트랜잭션
  • From : 송신자
  • To : 수신자
  • Value : 거래 금액
  • Signature : 서명문자열
  • Signature Schema : 서명을 만들기 위해서 사용한 암호화 알고리즘