libra_client 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3bc46b6395e05c4343cda7aec07f2e11795dfac4cacda24129d7882211942bbb
4
- data.tar.gz: 0107ac1a41b781e0133a12ec3553eed865d4f76b09d075d5c7d9a2351392965e
3
+ metadata.gz: 2ee0031b3c2294d7aa714045e404828a129d3141f51bd1e71fcdf61c5f085b9b
4
+ data.tar.gz: f25cfe316bedb6904b6e87c321c56d2e116b63381fe874f30d4df8e5f324a1c3
5
5
  SHA512:
6
- metadata.gz: eb573450b9cfb7cec39f2b896e200bda99a43cdf683b7df35a5d6988f40ef24d04b50b164bc8117baadcea0349ea50a86e01672df95ba82b5b04efea7f167259
7
- data.tar.gz: 1d786e9f754687cc57cba17f0e0d6a9539ea54f4c7acc7d2e61b0fe055dc678b598103116265f19a905ac655c6ed7d7fd38b9cf029703b55e196d150bfd96804
6
+ metadata.gz: 7b860682cb2b2c5c5c59971eedbe091698adbe457ee670eed30adf0c605142078128bd8077b74db9df322ca0698c15c354ea95601c54a78d3615f4224ec9b07a
7
+ data.tar.gz: 568504cec1ae771f1d536e0454a1bcd64806461cfbe321823d2bbd1205997e708f675dd7696dacd250f43777e94e921fcbf8c8025307505097b1071460c80256
data/README.md CHANGED
@@ -22,7 +22,16 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+
26
+ ```ruby
27
+ require 'libra_client'
28
+ LibraClient.get_transaction(0) #get the genesis transaction
29
+ LibraClient.get_transaction(1) #get the first transaction
30
+ version = LibraClient.get_latest_transaction_version
31
+ LibraClient.get_transaction(version) #get the latest transaction
32
+
33
+ LibraClient.get_account_state(ASSOCIATION_ADDRESS)
34
+ ```
26
35
 
27
36
  ## Development
28
37
 
@@ -1,6 +1,76 @@
1
- require "libra_client/version"
1
+ protolib = File.expand_path(File.dirname(__FILE__) + '/../proto-lib')
2
+ $LOAD_PATH.unshift(protolib) if File.directory?(protolib) && !$LOAD_PATH.include?(protolib)
3
+
4
+ require 'grpc'
5
+ require 'admission_control_services_pb'
6
+
7
+ LIBRA_TESTNET_HOST = "ac.testnet.libra.org:8000"
8
+ FAUCET_HOST = "http://faucet.testnet.libra.org"
9
+ #ACCOUNT_STATE_PATH = bytes.fromhex("01217da6c6b3e19f1825cfb2676daecce3bf3de03cf26647c78df00b371b25cc97")
10
+
11
+ 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]
12
+ ACCOUNT_SENT_EVENT_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, 47, 115, 101, 110, 116, 95, 101, 118, 101, 110, 116, 115, 95, 99, 111, 117, 110, 116, 47]
13
+ ASSOCIATION_ADDRESS = "000000000000000000000000000000000000000000000000000000000a550c18"
14
+
2
15
 
3
16
  module LibraClient
4
- class Error < StandardError; end
5
- # Your code goes here...
17
+
18
+ def self.get_latest_transaction_version
19
+ stub = AdmissionControl::AdmissionControl::Stub.new("ac.testnet.libra.org:8000",:this_channel_is_insecure)
20
+ resp = stub.update_to_latest_ledger(Types::UpdateToLatestLedgerRequest.new())
21
+ resp.ledger_info_with_sigs.ledger_info.version
22
+ end
23
+
24
+ def self.update_to_latest_ledger(requested_items)
25
+ request = Types::UpdateToLatestLedgerRequest.new(client_known_version: 3747, requested_items: requested_items)
26
+ stub = AdmissionControl::AdmissionControl::Stub.new("ac.testnet.libra.org:8000",:this_channel_is_insecure)
27
+ response = stub.update_to_latest_ledger(request)
28
+ # [:response_items, :ledger_info_with_sigs, :validator_change_events]
29
+ response
30
+ end
31
+
32
+ def self.get_account_state(address)
33
+ address = [address].pack('H*')
34
+ query = Types::GetAccountStateRequest.new(address: address)
35
+ item = Types::RequestItem.new(get_account_state_request: query)
36
+ resp = update_to_latest_ledger([item])
37
+ state = resp.response_items[0].get_account_state_response.account_state_with_proof
38
+ state
39
+ end
40
+
41
+ def self.get_transactions(start_version, limit=1, fetch_events=false)
42
+ query = Types::GetTransactionsRequest.new(start_version: start_version, limit: limit, fetch_events: fetch_events)
43
+ item = Types::RequestItem.new(get_transactions_request: query)
44
+ resp = update_to_latest_ledger([item])
45
+ txn_list_with_proof = resp.response_items[0].get_transactions_response.txn_list_with_proof
46
+ #[:transactions, :infos, :events_for_versions, :first_transaction_version, :proof_of_first_transaction, :proof_of_last_transaction]
47
+ txn_list_with_proof.transactions
48
+ end
49
+
50
+ def self.get_transaction(start_version)
51
+ #Types::SignedTransaction [:raw_txn_bytes, :sender_public_key, :sender_signature]
52
+ get_transactions(start_version)[0]
53
+ end
54
+
55
+ def self.get_account_transaction(address, sequence_number, fetch_events=true)
56
+ address = [address].pack('H*')
57
+ query = Types::GetAccountTransactionBySequenceNumberRequest.new(account: address, sequence_number: sequence_number, fetch_events: fetch_events)
58
+ item = Types::RequestItem.new(get_account_transaction_by_sequence_number_request: query)
59
+ resp = update_to_latest_ledger([item])
60
+ transaction = resp.response_items[0].get_account_transaction_by_sequence_number_response.signed_transaction_with_proof
61
+ #Types::SignedTransactionWithProof [:version, :signed_transaction, :proof, :events]
62
+ transaction
63
+ end
64
+
65
+ def self.get_events(address, start_sequence_number, ascending=true, limit=1)
66
+ address = [address].pack('H*')
67
+ path = ACCOUNT_SENT_EVENT_PATH.map{|x| x.chr}.join("")
68
+ access_path = Types::AccessPath.new(address: address, path: path)
69
+ query = Types::GetEventsByEventAccessPathRequest.new(access_path: access_path, start_event_seq_num: start_sequence_number, ascending: ascending, limit: limit)
70
+ item = Types::RequestItem.new(get_events_by_event_access_path_request: query)
71
+ resp = update_to_latest_ledger([item])
72
+ resp.response_items[0].get_events_by_event_access_path_response.events_with_proof
73
+ end
74
+
75
+
6
76
  end
@@ -1,3 +1,3 @@
1
1
  module LibraClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libra_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yuan xinyu