libra_client 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/Rakefile +10 -0
- data/bin/console +16 -0
- data/bin/setup +8 -0
- data/gen_proto.sh +2 -0
- data/lib/libra/access_path.rb +51 -0
- data/lib/libra/account_address.rb +29 -0
- data/lib/libra/account_config.rb +57 -0
- data/lib/libra/account_resource.rb +38 -0
- data/lib/libra/mnemonic.rb +147 -0
- data/lib/libra/version.rb +3 -0
- data/lib/libra_client.rb +173 -0
- data/libra_client.gemspec +49 -0
- data/libra_client.sublime-project +16 -0
- data/proto-lib/access_path_pb.rb +17 -0
- data/proto-lib/account_state_blob_pb.rb +23 -0
- data/proto-lib/admission_control_pb.rb +37 -0
- data/proto-lib/admission_control_services_pb.rb +37 -0
- data/proto-lib/events_pb.rb +35 -0
- data/proto-lib/get_with_proof_pb.rb +88 -0
- data/proto-lib/ledger_info_pb.rb +31 -0
- data/proto-lib/mempool_status_pb.rb +21 -0
- data/proto-lib/proof_pb.rb +41 -0
- data/proto-lib/transaction_info_pb.rb +19 -0
- data/proto-lib/transaction_pb.rb +102 -0
- data/proto-lib/validator_change_pb.rb +19 -0
- data/proto-lib/vm_errors_pb.rb +215 -0
- data/protos/access_path.proto +11 -0
- data/protos/account_state_blob.proto +16 -0
- data/protos/admission_control.proto +76 -0
- data/protos/events.proto +38 -0
- data/protos/get_with_proof.proto +310 -0
- data/protos/ledger_info.proto +82 -0
- data/protos/mempool_status.proto +21 -0
- data/protos/proof.proto +72 -0
- data/protos/transaction.proto +170 -0
- data/protos/transaction_info.proto +26 -0
- data/protos/validator_change.proto +27 -0
- data/protos/vm_errors.proto +276 -0
- metadata +191 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 589f70194d44d82434013d5d4469f69a947c67190ae78bd68cc7b3960f5bb8b4
|
4
|
+
data.tar.gz: a94e79ed350ca47b747e2c2c31a3aa6eb1fbf9f828bd890844c92474d2d72842
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3642745ef336f66acf064ea77f7e3027ce0302a247101fa5ff6b1aa229a100a65db311123eb163d09468b42f230c128706688bd8a0a6cb2deb238fadedfd15e1
|
7
|
+
data.tar.gz: b7b53603586cbc630830cd072ef9d2a7ba22446502c06636f3a57c5ba8dc01c509c1287a443a8d9025cdda794392a3b109f51dd69ade9c97213436119dbfa4fb
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at yuanxinyu.hangzhou@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
libra_client (0.1.2)
|
5
|
+
canoser (~> 0.1.2)
|
6
|
+
grpc (~> 1.23)
|
7
|
+
rest-client (~> 2.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
byebug (11.0.1)
|
13
|
+
canoser (0.1.2)
|
14
|
+
domain_name (0.5.20190701)
|
15
|
+
unf (>= 0.0.5, < 1.0.0)
|
16
|
+
google-protobuf (3.9.1-x86_64-linux)
|
17
|
+
googleapis-common-protos-types (1.0.4)
|
18
|
+
google-protobuf (~> 3.0)
|
19
|
+
grpc (1.23.0-x86_64-linux)
|
20
|
+
google-protobuf (~> 3.8)
|
21
|
+
googleapis-common-protos-types (~> 1.0)
|
22
|
+
http-accept (1.7.0)
|
23
|
+
http-cookie (1.0.3)
|
24
|
+
domain_name (~> 0.5)
|
25
|
+
mime-types (3.2.2)
|
26
|
+
mime-types-data (~> 3.2015)
|
27
|
+
mime-types-data (3.2019.0331)
|
28
|
+
minitest (5.11.3)
|
29
|
+
netrc (0.11.0)
|
30
|
+
rake (10.5.0)
|
31
|
+
rest-client (2.1.0)
|
32
|
+
http-accept (>= 1.7.0, < 2.0)
|
33
|
+
http-cookie (>= 1.0.2, < 2.0)
|
34
|
+
mime-types (>= 1.16, < 4.0)
|
35
|
+
netrc (~> 0.8)
|
36
|
+
unf (0.1.4)
|
37
|
+
unf_ext
|
38
|
+
unf_ext (0.0.7.6)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
bundler (~> 2.0)
|
45
|
+
byebug (~> 11.0)
|
46
|
+
libra_client!
|
47
|
+
minitest (~> 5.0)
|
48
|
+
rake (~> 10.0)
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 yuan xinyu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# LibraClient
|
2
|
+
|
3
|
+
LibraClient is an unofficial client for [Libra blockchain](http://libra.org). The library allows Ruby program to interact with Libra nodes with [protobuf](https://developers.google.com/protocol-buffers/) message through [grpc](https://grpc.io/).
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'libra_client'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install libra_client
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Get Account state
|
25
|
+
```ruby
|
26
|
+
require 'libra_client'
|
27
|
+
client = Libra::Client.new(:testnet)
|
28
|
+
state = client.get_account_state("000000000000000000000000000000000000000000000000000000000a550c18")
|
29
|
+
state.balance #the balance of the account
|
30
|
+
state.sequence_number #the sequence_number of the account
|
31
|
+
```
|
32
|
+
|
33
|
+
### Get Transaction
|
34
|
+
```ruby
|
35
|
+
require 'libra_client'
|
36
|
+
client = Libra::Client.new(:testnet)
|
37
|
+
client.get_transaction(0) #get the genesis transaction
|
38
|
+
client.get_transaction(1) #get the first transaction
|
39
|
+
version = client.get_latest_transaction_version
|
40
|
+
client.get_transaction(version) #get the latest transaction
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yuanxinyu/libra_client. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "libra_client"
|
5
|
+
#require 'byebug'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
require 'irb/completion'
|
16
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/gen_proto.sh
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Suppose we have the following data structure in a smart contract:
|
2
|
+
#
|
3
|
+
# struct B {
|
4
|
+
# Map<String, String> mymap;
|
5
|
+
# }
|
6
|
+
#
|
7
|
+
# struct A {
|
8
|
+
# B b;
|
9
|
+
# int my_int;
|
10
|
+
# }
|
11
|
+
#
|
12
|
+
# struct C {
|
13
|
+
# List<int> mylist;
|
14
|
+
# }
|
15
|
+
#
|
16
|
+
# A a;
|
17
|
+
# C c;
|
18
|
+
#
|
19
|
+
# and the data belongs to Alice. Then an access to `a.b.mymap` would be translated to an access
|
20
|
+
# to an entry in key-value store whose key is `<Alice>/a/b/mymap`. In the same way, the access to
|
21
|
+
# `c.mylist` would need to query `<Alice>/c/mylist`.
|
22
|
+
#
|
23
|
+
# So an account stores its data in a directory structure, for example:
|
24
|
+
# <Alice>/balance: 10
|
25
|
+
# <Alice>/a/b/mymap: {"Bob" => "abcd", "Carol" => "efgh"}
|
26
|
+
# <Alice>/a/myint: 20
|
27
|
+
# <Alice>/c/mylist: [3, 5, 7, 9]
|
28
|
+
#
|
29
|
+
# If someone needs to query the map above and find out what value associated with "Bob" is,
|
30
|
+
# `address` will be set to Alice and `path` will be set to "/a/b/mymap/Bob".
|
31
|
+
#
|
32
|
+
# On the other hand, if you want to query only <Alice>/a/*, `address` will be set to Alice and
|
33
|
+
# `path` will be set to "/a" and use the `get_prefix()` method from statedb
|
34
|
+
|
35
|
+
|
36
|
+
module Libra
|
37
|
+
class AccessPath
|
38
|
+
attr_accessor :address
|
39
|
+
attr_accessor :path
|
40
|
+
|
41
|
+
def initialize(address_hex, path)
|
42
|
+
@address = AccountAddress.new(address_hex)
|
43
|
+
@path = path
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_proto
|
47
|
+
Types::AccessPath.new(address: address.addr, path: path)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# A struct that represents an account address.
|
2
|
+
# Currently Public Key is used.
|
3
|
+
|
4
|
+
module Libra
|
5
|
+
class AccountAddress
|
6
|
+
ADDRESS_LENGTH = 32;
|
7
|
+
|
8
|
+
SHORT_STRING_LENGTH = 4;
|
9
|
+
|
10
|
+
LIBRA_NETWORK_ID_SHORT = "lb";
|
11
|
+
|
12
|
+
attr_accessor :addr
|
13
|
+
attr_accessor :hex
|
14
|
+
|
15
|
+
def initialize(hex_literal)
|
16
|
+
@hex = hex_literal
|
17
|
+
@addr = [hex_literal].pack('H*')
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.hex_to_bytes(hex_literal)
|
21
|
+
[hex_literal].pack('H*')
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.from_public_key
|
25
|
+
#TODO
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
|
2
|
+
module Libra
|
3
|
+
class AccountConfig
|
4
|
+
# LibraCoin
|
5
|
+
COIN_MODULE_NAME = "LibraCoin";
|
6
|
+
COIN_STRUCT_NAME = "T";
|
7
|
+
|
8
|
+
# Account
|
9
|
+
ACCOUNT_MODULE_NAME = "LibraAccount";
|
10
|
+
ACCOUNT_STRUCT_NAME = "T";
|
11
|
+
|
12
|
+
# Hash
|
13
|
+
HASH_MODULE_NAME = "Hash";
|
14
|
+
|
15
|
+
# pub fn resource_access_vec(tag: &StructTag, accesses: &Accesses) -> Vec<u8> {
|
16
|
+
# let mut key = vec![];
|
17
|
+
# key.push(Self::RESOURCE_TAG);
|
18
|
+
|
19
|
+
# key.append(&mut tag.hash().to_vec());
|
20
|
+
|
21
|
+
# // We don't need accesses in production right now. Accesses are appended here just for
|
22
|
+
# // passing the old tests.
|
23
|
+
# key.append(&mut accesses.as_separated_string().into_bytes());
|
24
|
+
# key
|
25
|
+
# }
|
26
|
+
|
27
|
+
# /// Return the path to the Account resource. It can be used to create an AccessPath for an
|
28
|
+
# /// Account resource.
|
29
|
+
# pub fn account_resource_path() -> Vec<u8> {
|
30
|
+
# AccessPath::resource_access_vec(
|
31
|
+
# &StructTag {
|
32
|
+
# address: core_code_address(),
|
33
|
+
# module: ACCOUNT_MODULE_NAME.to_string(),
|
34
|
+
# name: ACCOUNT_STRUCT_NAME.to_string(),
|
35
|
+
# type_params: vec![],
|
36
|
+
# },
|
37
|
+
# &Accesses::empty(),
|
38
|
+
# )
|
39
|
+
# }
|
40
|
+
ACCOUNT_RESOURCE_PATH = [1, 33, 125, 166, 198, 179, 225, 159, 24, 37, 207, 178, 103, 109, 174, 204, 227, 191, 61, 224, 60, 242, 102, 71, 199, 141, 240, 11, 55, 27, 37, 204, 151]
|
41
|
+
|
42
|
+
def self.account_sent_event_path
|
43
|
+
path = ACCOUNT_RESOURCE_PATH + "/sent_events_count/".bytes
|
44
|
+
path.pack('C*')
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.account_received_event_path
|
48
|
+
path = ACCOUNT_RESOURCE_PATH + "/received_events_count/".bytes
|
49
|
+
path.pack('C*')
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.association_address
|
53
|
+
AccountAddress.new("000000000000000000000000000000000000000000000000000000000a550c18")
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
|
2
|
+
module Libra
|
3
|
+
class AccountState < Canoser::Struct
|
4
|
+
define_field :blob, {}
|
5
|
+
end
|
6
|
+
|
7
|
+
# pub struct AccountResource {
|
8
|
+
# balance: u64,
|
9
|
+
# sequence_number: u64,
|
10
|
+
# authentication_key: ByteArray,
|
11
|
+
# delegated_withdrawal_capability: bool,
|
12
|
+
# sent_events: EventHandle,
|
13
|
+
# received_events: EventHandle,
|
14
|
+
# }
|
15
|
+
|
16
|
+
# impl CanonicalSerialize for AccountResource {
|
17
|
+
# fn serialize(&self, serializer: &mut impl CanonicalSerializer) -> Result<()> {
|
18
|
+
# // TODO(drussi): the order in which these fields are serialized depends on some
|
19
|
+
# // implementation details in the VM.
|
20
|
+
# serializer
|
21
|
+
# .encode_struct(&self.authentication_key)?
|
22
|
+
# .encode_u64(self.balance)?
|
23
|
+
# .encode_bool(self.delegated_withdrawal_capability)?
|
24
|
+
# .encode_struct(&self.received_events)?
|
25
|
+
# .encode_struct(&self.sent_events)?
|
26
|
+
# .encode_u64(self.sequence_number)?;
|
27
|
+
# Ok(())
|
28
|
+
# }
|
29
|
+
# }
|
30
|
+
class AccountResource < Canoser::Struct
|
31
|
+
define_field :authentication_key, [Canoser::Uint8]
|
32
|
+
define_field :balance, Canoser::Uint64
|
33
|
+
define_field :delegated_withdrawal_capability, Canoser::Bool
|
34
|
+
define_field :received_events_count, Canoser::Uint64
|
35
|
+
define_field :sent_events_count, Canoser::Uint64
|
36
|
+
define_field :sequence_number, Canoser::Uint64
|
37
|
+
end
|
38
|
+
end
|