cita-sdk-ruby 0.20.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +7 -1
- data/lib/cita/protos/blockchain_pb.rb +12 -2
- data/lib/cita/transaction_signer.rb +30 -14
- data/lib/cita/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13fa5f39c9959e2ad5e9ac909e53abd2b28e9a4622c2e6308092dc7d973b4689
|
4
|
+
data.tar.gz: 7e1cfdbf8c05e9c0505d563d5ffd7141894b9ef23b878623d863066b50e18087
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6a162dd52d2c41de0c2b62126b36a1094fdd25d0e1f063f46ecf3e2cd33dc3fba44532ce2f49eddb4130c4f5276b2788282b51a79303a3a7ab071ef0146dea1
|
7
|
+
data.tar.gz: c02e438621c191e2d9eadd074e6c95a409334dee6e914b139e6df8662d00b707659ce4856c3f1b3ffe56453f3c970b9f3eeccc771969cb3107091a82676893f4
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -54,6 +54,8 @@ content = CITA::TransactionSigner.encode(transaction, "you private key")
|
|
54
54
|
|
55
55
|
# you can unsign content by `decode` method
|
56
56
|
CITA::TransactionSigner.decode(content)
|
57
|
+
# you can set `recover` to false if you don't want to recover from address and public key
|
58
|
+
CITA::TransactionSigner.decode(content, recover: false)
|
57
59
|
```
|
58
60
|
|
59
61
|
send transaction
|
@@ -63,7 +65,7 @@ cita.rpc.send_transaction(transaction, private_key)
|
|
63
65
|
|
64
66
|
transfer tokens
|
65
67
|
```ruby
|
66
|
-
cita.rpc.transfer(to: "to address", value: 1000, private_key)
|
68
|
+
cita.rpc.transfer(to: "to address", value: 1000, private_key: "your private key")
|
67
69
|
```
|
68
70
|
|
69
71
|
contract
|
@@ -93,6 +95,10 @@ response = contract.send_func(tx: tx, private_key: private_key, method: :transfe
|
|
93
95
|
* rename to `cita-sdk-ruby`
|
94
96
|
* rename top module name to `CITA`
|
95
97
|
|
98
|
+
### v0.21.0
|
99
|
+
* add `recover` option for decode transaction, for CITA v0.21 provide `from` in `getTransaction` rpc call
|
100
|
+
* rename protobuf `Crypto` enum
|
101
|
+
|
96
102
|
## Contributing
|
97
103
|
|
98
104
|
Bug reports and pull requests are welcome on GitHub at https://github.com/cryptape/cita-sdk-ruby. 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.
|
@@ -61,11 +61,19 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
61
61
|
add_message "BlockBody" do
|
62
62
|
repeated :transactions, :message, 1, "SignedTransaction"
|
63
63
|
end
|
64
|
+
add_message "CompactBlockBody" do
|
65
|
+
repeated :tx_hashes, :bytes, 1
|
66
|
+
end
|
64
67
|
add_message "Block" do
|
65
68
|
optional :version, :uint32, 1
|
66
69
|
optional :header, :message, 2, "BlockHeader"
|
67
70
|
optional :body, :message, 3, "BlockBody"
|
68
71
|
end
|
72
|
+
add_message "CompactBlock" do
|
73
|
+
optional :version, :uint32, 1
|
74
|
+
optional :header, :message, 2, "BlockHeader"
|
75
|
+
optional :body, :message, 3, "CompactBlockBody"
|
76
|
+
end
|
69
77
|
add_message "BlockWithProof" do
|
70
78
|
optional :blk, :message, 1, "Block"
|
71
79
|
optional :proof, :message, 2, "Proof"
|
@@ -87,8 +95,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
87
95
|
value :Bft, 2
|
88
96
|
end
|
89
97
|
add_enum "Crypto" do
|
90
|
-
value :
|
91
|
-
value :
|
98
|
+
value :DEFAULT, 0
|
99
|
+
value :RESERVED, 1
|
92
100
|
end
|
93
101
|
end
|
94
102
|
|
@@ -102,7 +110,9 @@ module CITA::Protos
|
|
102
110
|
UnverifiedTransaction = Google::Protobuf::DescriptorPool.generated_pool.lookup("UnverifiedTransaction").msgclass
|
103
111
|
SignedTransaction = Google::Protobuf::DescriptorPool.generated_pool.lookup("SignedTransaction").msgclass
|
104
112
|
BlockBody = Google::Protobuf::DescriptorPool.generated_pool.lookup("BlockBody").msgclass
|
113
|
+
CompactBlockBody = Google::Protobuf::DescriptorPool.generated_pool.lookup("CompactBlockBody").msgclass
|
105
114
|
Block = Google::Protobuf::DescriptorPool.generated_pool.lookup("Block").msgclass
|
115
|
+
CompactBlock = Google::Protobuf::DescriptorPool.generated_pool.lookup("CompactBlock").msgclass
|
106
116
|
BlockWithProof = Google::Protobuf::DescriptorPool.generated_pool.lookup("BlockWithProof").msgclass
|
107
117
|
BlockTxs = Google::Protobuf::DescriptorPool.generated_pool.lookup("BlockTxs").msgclass
|
108
118
|
BlackList = Google::Protobuf::DescriptorPool.generated_pool.lookup("BlackList").msgclass
|
@@ -45,13 +45,11 @@ module CITA
|
|
45
45
|
CITA::Utils.from_bytes(encoded_unverified_tx)
|
46
46
|
end
|
47
47
|
|
48
|
-
#
|
48
|
+
# get sender info (from address & public key)
|
49
49
|
#
|
50
|
-
# @param
|
51
|
-
|
52
|
-
|
53
|
-
unverified_transaction = Protos::UnverifiedTransaction.decode(content_bytes)
|
54
|
-
|
50
|
+
# @param unverified_transaction [Hash]
|
51
|
+
# @return [Hash] address & public_key
|
52
|
+
def sender_info(unverified_transaction)
|
55
53
|
signature = unverified_transaction["signature"]
|
56
54
|
|
57
55
|
transaction = unverified_transaction["transaction"]
|
@@ -63,23 +61,40 @@ module CITA
|
|
63
61
|
from_address = Utils.keccak256(pubkey[1..-1])[-20..-1]
|
64
62
|
from_address_hex = Utils.from_bytes(from_address)
|
65
63
|
|
66
|
-
|
64
|
+
{
|
67
65
|
address: from_address_hex,
|
68
66
|
public_key: pubkey_hex
|
69
67
|
}
|
68
|
+
end
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
# decode transaction, CITA v0.21 returns the `from` address in `getTransaction` RPC call
|
71
|
+
# so you can not to recover `from` address from context
|
72
|
+
#
|
73
|
+
# @param tx_content [String] hex string
|
74
|
+
# @param recover [Boolean] set to false if you don't want to recover from address, default is true
|
75
|
+
def simple_decode(tx_content, recover: true)
|
76
|
+
content_bytes = CITA::Utils.to_bytes(tx_content)
|
77
|
+
unverified_transaction = Protos::UnverifiedTransaction.decode(content_bytes)
|
78
|
+
|
79
|
+
info = {
|
80
|
+
unverified_transaction: unverified_transaction.to_h
|
74
81
|
}
|
82
|
+
|
83
|
+
if recover
|
84
|
+
sender = sender_info(unverified_transaction)
|
85
|
+
info[:sender] = sender
|
86
|
+
end
|
87
|
+
|
88
|
+
info
|
75
89
|
end
|
76
90
|
|
77
91
|
# decode and support forks
|
78
92
|
#
|
79
93
|
# @param tx_content [String] hex string
|
94
|
+
# @param recover [Boolean] set to false if you don't want to recover from address, default is true
|
80
95
|
# @return [Hash]
|
81
|
-
def original_decode(tx_content)
|
82
|
-
data = simple_decode(tx_content)
|
96
|
+
def original_decode(tx_content, recover: true)
|
97
|
+
data = simple_decode(tx_content, recover: recover)
|
83
98
|
utx = data[:unverified_transaction]
|
84
99
|
tx = utx[:transaction]
|
85
100
|
version = tx[:version]
|
@@ -100,9 +115,10 @@ module CITA
|
|
100
115
|
# decode and parse bytes to hex string
|
101
116
|
#
|
102
117
|
# @param tx_content [String] hex string
|
118
|
+
# @param recover [Boolean] set to false if you don't want to recover from address, default is true
|
103
119
|
# @return [Hash]
|
104
|
-
def decode(tx_content)
|
105
|
-
data = original_decode(tx_content)
|
120
|
+
def decode(tx_content, recover: true)
|
121
|
+
data = original_decode(tx_content, recover: recover)
|
106
122
|
utx = data[:unverified_transaction]
|
107
123
|
tx = utx[:transaction]
|
108
124
|
version = tx[:version]
|
data/lib/cita/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cita-sdk-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- classicalliu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|