libra-client:适用于Libra网络的python客户端

  • y2_177706
    了解作者
  • 105.2KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-18 03:41
    上传日期
天秤座客户 LibraClient是工具集,可让您轻松地与交互。 它提供了三种访问天秤座的方式: libra_shell ,一个交互式的shell程序。 它与Libra官方客户端兼容。 对于初学者来说,它使您可以直接开始尝试使用libra进行第一次事务,而无需耗时的下载并编译庞大的整个Libra项目源代码。 libra ,一个命令行工具。 它具有现代的彩色文本界面,其输出是标准的json格式。 因此,它可以轻松集成到任何编程语言中。 python api ,客户端访问libra的python api的集合。 对于Python程序员,您可以调用此客户端api来与Libra Network进行交互,而不是通过使用libra命令来进行更多控制。 在下面的文档中,所有带有$命令前缀都表示它已在标准linux shell中键入并运行; 所有带有libra%命令前缀都意味着它已在libra_
libra-client-master.zip
  • libra-client-master
  • .github
  • workflows
  • pythonpackage.yml
    1.3KB
  • scripts
  • gen_cli_help.sh
    806B
  • parse_version.py
    326B
  • test_new_published_version.sh
    206B
  • publish_pip.sh
    32B
  • update_requirements.sh
    126B
  • gen_requirements.sh
    81B
  • build_dist.sh
    36B
  • test
  • test_client.py
    5.8KB
  • pay_1.module.mvir
    152B
  • test_error.py
    977B
  • test_key_factory.py
    1.3KB
  • test.wallet
    159B
  • test_events.py
    1.4KB
  • test_genesis.py
    627B
  • testnet_local.sh
    142B
  • test_json_print.py
    614B
  • devnet_test.sh
    66B
  • test_command.py
    1.8KB
  • stress_test.py
    2KB
  • peer_to_peer.mv
    205B
  • use_pay.mvir
    140B
  • test_local_libra-swarm.py
    2.8KB
  • test_transaction.py
    6.7KB
  • test_shell.py
    6.6KB
  • test_wallet_library.py
    3.1KB
  • libra_client
  • cli
  • account_cmds.py
    5KB
  • color.py
    1KB
  • ledger_cmds.py
    1.7KB
  • main.py
    3.4KB
  • dual_command.py
    401B
  • __main__.py
    413B
  • transaction_cmds.py
    3.3KB
  • command.py
    4.5KB
  • wallet_cmds.py
    3.8KB
  • shell
  • client_proxy.py
    8.9KB
  • libra_shell.py
    4.2KB
  • __init__.py
    0B
  • transfer_commands.py
    2KB
  • __main__.py
    431B
  • query_commands.py
    5.3KB
  • account_commands.py
    3.2KB
  • dev_commands.py
    5.1KB
  • error.py
    582B
  • wallet_library.py
    4.9KB
  • __init__.py
    363B
  • key_factory.py
    2.3KB
  • client.py
    12.2KB
  • version.py
    19B
  • docs
  • test_over_local_testnet.md
    1.9KB
  • cli_help.html
    5.6KB
  • first_transaction.md
    15.9KB
  • shell.jpg
    64.8KB
  • libra-client.sublime-project
    349B
  • MANIFEST.in
    145B
  • .flake8
    53B
  • flake_check.sh
    176B
  • dev-requirements.in
    52B
  • requirements.txt
    678B
  • LICENSE
    1.1KB
  • setup.py
    1.7KB
  • README.md
    10.8KB
  • .gitignore
    159B
  • dev-requirements.txt
    2KB
  • venv.sh
    70B
内容介绍
# LibraClient ![Python package](https://github.com/yuan-xy/libra-client/workflows/Python%20package/badge.svg) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) LibraClient is a collection of tools which allows you interact whith [Libra Network](http://libra.org) easily. It provides three ways to access Libra: 1. **`libra_shell`**, an interactive shell program. It is compatible with official Libra client. For beginners, it lets you get started directly to try your first transaction with libra without requiring time-consuming downloads and compiles the huge entire Libra project source code. 2. **`libra`**, a command line tool. It has a modern colorful text interface and its output is the standard json format. So, it can be integrated to any programming language easily. 3. **`python api`**, a collection of apis for client access to libra. For Python programmers, you can call this client side api to interact with Libra Network with more control than by using `libra` command. In following docuement, all command prefix with `$` meants it is typed and run in standard linux shell; all command prefix with `libra%` meants it is typed and run in `libra_shell`. For exmaple, **`$ libra`** meants run `libra` command in linux shell, which is different than **`libra%`**. ## Installation Require python 3.7 or above installed. ```sh $ python3 -m pip install libra-client ``` If you had a problem during installation, following command should works anyway. ```sh $ python3 -m pip install --index-url https://pypi.org/project/ --user libra-client ``` ## Usage of 'libra_shell' To start 'libra_shell' and connect to a validator node running on the Libra testnet, just input the 'libra_shell' command on termial as shown below. ```bash $ libra_shell ``` Once the client connects to a node on the testnet, you will see the following output. To quit the client at any time, use the `quit` command. ![libra shell](https://github.com/yuan-xy/libra-client/raw/master/docs/shell.jpg "libra shell") [This document will guide you through executing your first transaction on the Libra Blockchain](https://github.com/yuan-xy/libra-client/blob/master/docs/first_transaction.md). We will walk you through creating accounts for two users. ## Usage of 'libra' command The command 'libra' contains four subcommands 'account', 'transaction', 'wallet' and 'ledger'. All subcommands have their own parameters. ### Leger Time Example For example, using 'ledger' command to query the ledger start time and latest transaction time of testnet: ```bash $ libra ledger time ``` You will get the json output like this: ```json { "start_time": "2019-10-03T05:19:59", "latest_time": "2019-10-16T17:04:17" } ``` ### Account Balance Example To query the balance of some account by address, ```bash $ libra account balance 000000000000000000000000000000000000000000000000000000000a550c18 ``` You will get the balance of that address: ```json { "balance": 24075309756646968 } ``` ### Wallet Example To query the total balance of a wallet, ```bash $ libra wallet balance <some mnemonic file of the wallet> ``` You will get the total balance and balance of every accounts in that wallet: ```json { "7af57a0c206fbcc846532f75f373b5d1db9333308dbc4673c5befbca5db60e2f": 123, "f1f48f56c4deea75f4393e832edef247547eb76e1cd498c27cc972073ec4dbde": 0, "total_balance": 123 } ``` ### Help message of `libra` If you input `libra` without any parameters as following, ```bash $ libra ``` You will get the help message: ``` USAGE: libra [options] command [command parameters ...] Optional arguments: -a | --host HOST Host address/name to connect to. [default:testnet] -p | --port PORT Admission Control port to connect to. [default: 8000] -v | --verbose Verbose output -V | --version Show program's version number and exit -h | --help Show this help message and exit Use the following commands: account | a Account query by address transaction | t Transaction query wallet | w show account information of a wallet derived from mnemonic file ledger | lg show ledger info of Libra blockchain ``` ### Help message of subcommand If you input the libra subcommand without any parameter, you will get the help message of that subcommand. For example: ```bash $ libra wallet ``` You will get the help message: ``` USAGE: wallet <arg rel='nofollow' onclick='return false;'> Use one of the following args for this command: show | s <mnemonic_file_path> Show the mnemonic words, seed and addresses of a wallet account | a <mnemonic_file_path> Show the keypair and address of accounts in a wallet balance | b <mnemonic_file_path> Get the balance of all accounts in a wallet create | c <mnemonic_file_path> create a new wallet and save the mnemonic file to <mnemonic_file_path> ``` More instructions can be found here [libra command help](https://raw.githubusercontent.com/yuan-xy/libra-client/master/docs/cli_help.html). ## Client side Libra API for python programmer ### Wallet You can create a wallet using `WalletLibrary` class. A wallet is like your masterkey and you can create almost infinitely many Libra accounts from it. Note that LibraClient's mnemonic scheme is compatible with that of [Libra's CLI](https://github.com/libra/libra/tree/master/client/src), so you can import mnemonic between the two libraries. ```py from libra_client import WalletLibrary # Create a new random wallet wallet = WalletLibrary.new() # Create a new wallet from mnemonic words wallet = WalletLibrary.new_from_mnemonic(mnemonic, child_count) # Recover wallet from a offical Libra CLI backup file wallet = WalletLibrary.recover(filename) ``` ### Account An `Account` can be created by calling `new_account` function on a wallet, each Account has an integer index in wallet, start from zero. An `Account` contains its `address`, `public_key`, and `private_key`. ```py print(wallet.child_count) account1 = wallet.new_account() print(wallet.child_count) print(account1.address) print(account1.public_key) print(account1.private_key) ``` ### Client A `Client` must be created in order to send protobuf message to a Libra node. You can create a client with the following code. ```py from libra_client import Client client1 = Client("testnet") # Default client connecting to the official testnet client2 = Client.new('localhost', 8000, "validator_file_path") # Client connecting to a local node ``` ### Get Account Data of an Address ``` plaintext # An account stores its data in a directory structure, for example: # <alice rel='nofollow' onclick='return false;'>/balance: 10 # <alice rel='nofollow' onclick='return false;'>/a/b/mymap: {"Bob" => "abcd", "Carol" => "efgh"} # <alice rel='nofollow' onclick='return false;'>/a/myint: 20 # <alice rel='nofollow' onclick='return false;'>/c/mylist: [3, 5, 7, 9] # # If someone needs to query the map above and find out what value associated with "Bob" is, # `address` will be set to Alice and `path` will be set to "/a/b/mymap/Bob". # # On the other hand, if you want to query only <alice rel='nofollow' onclick='return false;'>/a/*, `address` will be set to Alice and # `path` will be set to "/a" and use the `get_prefix()` method from statedb ``` #### Get Account State Blob of an Address No longer supported in json-rpc. #### Get Account State of an Address If the Account has been created, you can call `get_account_state` function which return a `AccountState` object with 'ordered_map' field; other wise, AccountError will be thrown. ```py client = Client("testnet") amap = client.get_account_state(address) ``` #### Get Account Resource of an Address If you want to get account balance / sequence / authentication_key etc from account state, you can calling `get_account_resource` function, which will deserialize the account resource from account state map. ```py client = Client("testnet") resource = client.get_account_resour
评论
    相关推荐