mixin_bot 3.0.3 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/AGENTS.md +12 -2
- data/CHANGELOG.md +135 -0
- data/README.md +3 -2
- data/docs/agent/cli.md +4 -2
- data/lib/mixin_bot/address.rb +73 -62
- data/lib/mixin_bot/api/attachment.rb +18 -8
- data/lib/mixin_bot/api/blaze.rb +7 -2
- data/lib/mixin_bot/api/blaze_async.rb +169 -4
- data/lib/mixin_bot/api/computer_api.rb +7 -7
- data/lib/mixin_bot/api/encrypted_message.rb +75 -52
- data/lib/mixin_bot/api/multisig.rb +9 -7
- data/lib/mixin_bot/api/pin.rb +9 -8
- data/lib/mixin_bot/api/tip.rb +1 -1
- data/lib/mixin_bot/api/transaction.rb +70 -41
- data/lib/mixin_bot/api/transfer.rb +3 -2
- data/lib/mixin_bot/api/user.rb +6 -6
- data/lib/mixin_bot/api.rb +1 -0
- data/lib/mixin_bot/bot_auth.rb +1 -1
- data/lib/mixin_bot/cli/schema.rb +2 -0
- data/lib/mixin_bot/cli.rb +9 -3
- data/lib/mixin_bot/client.rb +43 -19
- data/lib/mixin_bot/computer.rb +39 -23
- data/lib/mixin_bot/configuration.rb +48 -8
- data/lib/mixin_bot/invoice.rb +126 -77
- data/lib/mixin_bot/nfo.rb +54 -43
- data/lib/mixin_bot/proxy.rb +184 -0
- data/lib/mixin_bot/transaction/decoder.rb +201 -138
- data/lib/mixin_bot/transaction/encoder.rb +156 -118
- data/lib/mixin_bot/transaction.rb +15 -1
- data/lib/mixin_bot/utils/address.rb +1 -1
- data/lib/mixin_bot/utils/amount.rb +25 -0
- data/lib/mixin_bot/utils/base58.rb +97 -0
- data/lib/mixin_bot/utils/crypto.rb +188 -56
- data/lib/mixin_bot/utils/cursor.rb +147 -0
- data/lib/mixin_bot/utils/decoder.rb +111 -6
- data/lib/mixin_bot/utils/encoder.rb +90 -21
- data/lib/mixin_bot/utils/options.rb +26 -0
- data/lib/mixin_bot/utils/sodium.rb +169 -0
- data/lib/mixin_bot/utils.rb +17 -2
- data/lib/mixin_bot/uuid.rb +6 -13
- data/lib/mixin_bot/version.rb +1 -1
- data/lib/mixin_bot.rb +1 -3
- data/lib/mvm/client.rb +44 -9
- data/lib/mvm/registry.rb +45 -17
- data/llms.txt +1 -1
- metadata +6 -44
- data/lib/mixin_bot/transaction/buffer.rb +0 -34
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'base64'
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
6
|
+
module MixinBot
|
|
7
|
+
##
|
|
8
|
+
# Immutable HTTP/HTTPS proxy configuration parsed from a String, URI, Hash, or Proxy.
|
|
9
|
+
#
|
|
10
|
+
class Proxy
|
|
11
|
+
SUPPORTED_SCHEMES = %w[http https].freeze
|
|
12
|
+
ALLOWED_HASH_KEYS = %i[uri user password].freeze
|
|
13
|
+
|
|
14
|
+
attr_reader :uri, :user, :password
|
|
15
|
+
|
|
16
|
+
class << self
|
|
17
|
+
##
|
|
18
|
+
# Parses a proxy specification into a {MixinBot::Proxy}, or returns +nil+ for +nil+/blank strings.
|
|
19
|
+
#
|
|
20
|
+
# @param value [String, URI, Hash, MixinBot::Proxy, nil]
|
|
21
|
+
# @return [MixinBot::Proxy, nil]
|
|
22
|
+
# @raise [MixinBot::ArgumentError] when the proxy format or scheme is invalid
|
|
23
|
+
#
|
|
24
|
+
def parse(value)
|
|
25
|
+
case value
|
|
26
|
+
when nil
|
|
27
|
+
nil
|
|
28
|
+
when self
|
|
29
|
+
value
|
|
30
|
+
when String
|
|
31
|
+
stripped = value.strip
|
|
32
|
+
return nil if stripped.empty?
|
|
33
|
+
|
|
34
|
+
parse_uri_and_build(stripped)
|
|
35
|
+
when URI
|
|
36
|
+
build_from_uri(value)
|
|
37
|
+
when Hash
|
|
38
|
+
parse_hash(value)
|
|
39
|
+
else
|
|
40
|
+
raise ArgumentError, "proxy must be a String, URI, Hash, or MixinBot::Proxy, got #{value.class}"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def parse_uri_and_build(raw_uri, user_override: nil, password_override: nil)
|
|
47
|
+
parsed = URI.parse(raw_uri)
|
|
48
|
+
build_from_uri(parsed, user_override:, password_override:)
|
|
49
|
+
rescue URI::InvalidURIError => e
|
|
50
|
+
raise ArgumentError, "invalid proxy URI: #{e.message}"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def build_from_uri(parsed, user_override: nil, password_override: nil)
|
|
54
|
+
scheme = parsed.scheme&.downcase
|
|
55
|
+
unless SUPPORTED_SCHEMES.include?(scheme)
|
|
56
|
+
raise ArgumentError, "unsupported proxy scheme: #{parsed.scheme.inspect} (expected http or https)"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
raise ArgumentError, 'proxy URI must include a host' if parsed.host.nil? || parsed.host.empty?
|
|
60
|
+
|
|
61
|
+
normalized = parsed.dup.normalize
|
|
62
|
+
uri_user = normalized.user ? URI::DEFAULT_PARSER.unescape(normalized.user) : nil
|
|
63
|
+
uri_password = normalized.password ? URI::DEFAULT_PARSER.unescape(normalized.password) : nil
|
|
64
|
+
|
|
65
|
+
clean_uri = normalized.dup
|
|
66
|
+
clean_uri.user = nil
|
|
67
|
+
clean_uri.password = nil
|
|
68
|
+
|
|
69
|
+
new(
|
|
70
|
+
uri: clean_uri,
|
|
71
|
+
user: user_override.nil? ? uri_user : user_override.to_s,
|
|
72
|
+
password: password_override.nil? ? uri_password : password_override.to_s
|
|
73
|
+
)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def parse_hash(hash)
|
|
77
|
+
symbolized = hash.transform_keys { |k| k.is_a?(Symbol) || k.is_a?(String) ? k.to_sym : k }
|
|
78
|
+
unknown = symbolized.keys - ALLOWED_HASH_KEYS
|
|
79
|
+
raise ArgumentError, "unknown proxy option(s): #{unknown.join(', ')}" unless unknown.empty?
|
|
80
|
+
|
|
81
|
+
raw_uri = symbolized[:uri]
|
|
82
|
+
raise ArgumentError, 'proxy hash must include a non-empty :uri' if raw_uri.nil? || (raw_uri.is_a?(String) && raw_uri.strip.empty?)
|
|
83
|
+
|
|
84
|
+
user_override = symbolized[:user]
|
|
85
|
+
password_override = symbolized[:password]
|
|
86
|
+
|
|
87
|
+
case raw_uri
|
|
88
|
+
when String
|
|
89
|
+
parse_uri_and_build(raw_uri.strip, user_override:, password_override:)
|
|
90
|
+
when URI
|
|
91
|
+
build_from_uri(raw_uri, user_override:, password_override:)
|
|
92
|
+
else
|
|
93
|
+
raise ArgumentError, "proxy :uri must be a String or URI, got #{raw_uri.class}"
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def initialize(uri:, user: nil, password: nil)
|
|
99
|
+
clean = uri.dup
|
|
100
|
+
clean.user = nil
|
|
101
|
+
clean.password = nil
|
|
102
|
+
@uri = clean.freeze
|
|
103
|
+
@user = user.nil? ? nil : user.to_s.freeze
|
|
104
|
+
@password = password.nil? ? nil : password.to_s.freeze
|
|
105
|
+
freeze
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def scheme
|
|
109
|
+
uri.scheme
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def host
|
|
113
|
+
uri.host
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def hostname
|
|
117
|
+
uri.hostname
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def port
|
|
121
|
+
uri.port
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def https?
|
|
125
|
+
scheme == 'https'
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def origin
|
|
129
|
+
"#{scheme}://#{host}:#{port}"
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def basic_auth_header
|
|
133
|
+
return nil if user.nil?
|
|
134
|
+
|
|
135
|
+
"Basic #{Base64.strict_encode64("#{user}:#{password}")}"
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def faraday_options
|
|
139
|
+
opts = { uri: uri }
|
|
140
|
+
opts[:user] = user unless user.nil?
|
|
141
|
+
opts[:password] = password unless password.nil?
|
|
142
|
+
opts
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def faye_options
|
|
146
|
+
opts = { origin: origin }
|
|
147
|
+
auth = basic_auth_header
|
|
148
|
+
opts[:headers] = { 'Proxy-Authorization' => auth } if auth
|
|
149
|
+
opts
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def connect_headers(authority)
|
|
153
|
+
headers = { 'Host' => authority }
|
|
154
|
+
auth = basic_auth_header
|
|
155
|
+
headers['Proxy-Authorization'] = auth if auth
|
|
156
|
+
headers
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def ==(other)
|
|
160
|
+
other.is_a?(self.class) && uri == other.uri && user == other.user && password == other.password
|
|
161
|
+
end
|
|
162
|
+
alias eql? ==
|
|
163
|
+
|
|
164
|
+
def hash
|
|
165
|
+
[uri, user, password].hash
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def to_s
|
|
169
|
+
origin
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
def inspect
|
|
173
|
+
if user && password
|
|
174
|
+
"#<#{self.class} #{scheme}://#{user}:***@#{host}:#{port}>"
|
|
175
|
+
elsif user
|
|
176
|
+
"#<#{self.class} #{scheme}://#{user}@#{host}:#{port}>"
|
|
177
|
+
elsif password
|
|
178
|
+
"#<#{self.class} #{scheme}://:***@#{host}:#{port}>"
|
|
179
|
+
else
|
|
180
|
+
"#<#{self.class} #{origin}>"
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end
|
|
@@ -5,78 +5,56 @@ module MixinBot
|
|
|
5
5
|
##
|
|
6
6
|
# Parses raw transaction bytes into a {Transaction} instance.
|
|
7
7
|
#
|
|
8
|
+
# The raw bytes are read through a {Utils::Cursor}, so a raw that ends
|
|
9
|
+
# before every field is read raises {MixinBot::ArgumentError} at the
|
|
10
|
+
# missing field instead of decoding short values.
|
|
11
|
+
#
|
|
8
12
|
class Decoder
|
|
9
13
|
def initialize(transaction)
|
|
10
14
|
@tx = transaction
|
|
11
15
|
end
|
|
12
16
|
|
|
13
17
|
def decode
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
hex = @tx.hex
|
|
19
|
+
raise ArgumentError, 'invalid transaction hex' unless hex.is_a?(String) && hex.bytesize.even? && hex.match?(/\A\h*\z/)
|
|
20
|
+
|
|
21
|
+
raw = [hex].pack('H*')
|
|
22
|
+
@buf = MixinBot::Utils::Cursor.new(raw)
|
|
17
23
|
|
|
18
|
-
magic = @buf.
|
|
19
|
-
raise ArgumentError, 'Not valid raw' unless magic == Transaction::
|
|
24
|
+
magic = @buf.read(2)
|
|
25
|
+
raise ArgumentError, 'Not valid raw' unless magic == Transaction::MAGIC_BINARY
|
|
20
26
|
|
|
21
|
-
|
|
22
|
-
@tx.version
|
|
27
|
+
@tx.version = @buf.read_uint16
|
|
28
|
+
supported_version = @tx.version.between?(Transaction::TX_VERSION, Transaction::SAFE_TX_VERSION)
|
|
29
|
+
raise ArgumentError, 'unsupported transaction version' unless supported_version
|
|
30
|
+
raise ArgumentError, 'transaction is too large' if @tx.safe_wire? && raw.bytesize > @tx.max_extra_size
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
@tx.asset =
|
|
32
|
+
@tx.hash = SHA3::Digest::SHA3_256.hexdigest(raw) unless @tx.safe_wire?
|
|
33
|
+
@tx.asset = @buf.read(32).unpack1('H*')
|
|
26
34
|
|
|
27
35
|
decode_inputs
|
|
28
36
|
decode_outputs
|
|
29
37
|
decode_references if @tx.version >= Transaction::REFERENCES_TX_VERSION
|
|
30
38
|
|
|
31
|
-
extra_size =
|
|
32
|
-
@tx.
|
|
39
|
+
extra_size = @buf.read_uint32
|
|
40
|
+
raise ArgumentError, 'extra is too long' if @tx.safe_wire? && extra_size > @tx.max_extra_size
|
|
33
41
|
|
|
34
|
-
|
|
35
|
-
if num == Transaction::MAX_ENCODE_INT
|
|
36
|
-
@tx.aggregated = {}
|
|
37
|
-
|
|
38
|
-
prefix = MixinBot.utils.decode_uint16(@buf.shift(2))
|
|
39
|
-
raise ArgumentError, 'invalid aggregated' unless prefix == Transaction::AGGREGATED_SIGNATURE_PREFIX
|
|
40
|
-
|
|
41
|
-
@tx.aggregated['signature'] = @buf.shift(64).pack('C*').unpack1('H*')
|
|
42
|
-
|
|
43
|
-
byte = @buf.shift
|
|
44
|
-
case byte
|
|
45
|
-
when Transaction::AGGREGATED_SIGNATURE_ORDINAY_MASK.first
|
|
46
|
-
@tx.aggregated['signers'] = []
|
|
47
|
-
masks_size = MixinBot.utils.decode_uint16 @buf.shift(2)
|
|
48
|
-
masks = @buf.shift(masks_size)
|
|
49
|
-
masks = Array(masks)
|
|
50
|
-
|
|
51
|
-
masks.each_with_index do |mask, i|
|
|
52
|
-
8.times do |j|
|
|
53
|
-
k = 1 << j
|
|
54
|
-
@tx.aggregated['signers'].push((i * 8) + j) if mask & k == k
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
when Transaction::AGGREGATED_SIGNATURE_SPARSE_MASK.first
|
|
58
|
-
signers_size = MixinBot.utils.decode_uint16 @buf.shift(2)
|
|
59
|
-
@tx.aggregated['signers'] = []
|
|
60
|
-
unless signers_size.zero?
|
|
61
|
-
signers_size.times do
|
|
62
|
-
@tx.aggregated['signers'].push MixinBot.utils.decode_uint16(@buf.shift(2))
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
elsif num.present? && num.positive? && @buf.size.positive?
|
|
67
|
-
@tx.signatures = []
|
|
68
|
-
num.times do
|
|
69
|
-
signature = {}
|
|
42
|
+
@tx.extra = @buf.read(extra_size)
|
|
70
43
|
|
|
71
|
-
|
|
44
|
+
signature_offset = @buf.pos
|
|
45
|
+
num = @buf.read_uint16
|
|
46
|
+
if num == Transaction::MAX_ENCODE_INT
|
|
47
|
+
decode_aggregated_signature
|
|
48
|
+
elsif num.positive?
|
|
49
|
+
raise ArgumentError, 'too many signatures' if @tx.safe_wire? && num > Transaction::SAFE_SLICE_LIMIT
|
|
72
50
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
51
|
+
decode_signatures num
|
|
52
|
+
end
|
|
53
|
+
if @tx.safe_wire?
|
|
54
|
+
raise ArgumentError, 'trailing transaction bytes' unless @buf.empty?
|
|
77
55
|
|
|
78
|
-
|
|
79
|
-
|
|
56
|
+
unsigned = num.zero? ? raw : raw.byteslice(0, signature_offset) << Transaction::NULL_BINARY
|
|
57
|
+
@tx.hash = Digest::Blake3.hexdigest(unsigned)
|
|
80
58
|
end
|
|
81
59
|
|
|
82
60
|
@tx
|
|
@@ -84,143 +62,228 @@ module MixinBot
|
|
|
84
62
|
|
|
85
63
|
private
|
|
86
64
|
|
|
65
|
+
def read_count
|
|
66
|
+
count = @buf.read_uint16
|
|
67
|
+
raise ArgumentError, 'too many items' if @tx.safe_wire? && count > Transaction::SAFE_SLICE_LIMIT
|
|
68
|
+
|
|
69
|
+
count
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def read_amount
|
|
73
|
+
size = @buf.read_uint16
|
|
74
|
+
raise ArgumentError, 'non-canonical transaction amount' if @tx.safe_wire? && size.positive? && @buf.peek(1) == "\0".b
|
|
75
|
+
|
|
76
|
+
@buf.read_int(size)
|
|
77
|
+
end
|
|
78
|
+
|
|
87
79
|
def decode_inputs
|
|
88
|
-
inputs_size =
|
|
80
|
+
inputs_size = read_count
|
|
89
81
|
@tx.inputs = []
|
|
90
82
|
inputs_size.times do
|
|
91
83
|
input = {}
|
|
92
|
-
hash = @buf.
|
|
93
|
-
input['
|
|
94
|
-
|
|
95
|
-
index = @buf.shift(2)
|
|
96
|
-
input['index'] = MixinBot.utils.decode_uint16 index
|
|
84
|
+
input['hash'] = @buf.read(32).unpack1('H*')
|
|
85
|
+
input['index'] = @buf.read_uint16
|
|
86
|
+
raise ArgumentError, 'invalid input index' if @tx.safe_wire? && input['index'] > Transaction::SAFE_INPUT_INDEX_LIMIT
|
|
97
87
|
|
|
98
|
-
if @buf.peek(2) == Transaction::
|
|
99
|
-
@buf.
|
|
88
|
+
if @buf.peek(2) == Transaction::NULL_BINARY
|
|
89
|
+
@buf.read(2)
|
|
100
90
|
else
|
|
101
|
-
genesis_size =
|
|
102
|
-
genesis = @buf.
|
|
103
|
-
input['genesis'] = genesis.pack('C*').unpack1('H*')
|
|
91
|
+
genesis_size = @buf.read_uint16
|
|
92
|
+
input['genesis'] = @buf.read(genesis_size).unpack1('H*')
|
|
104
93
|
end
|
|
105
94
|
|
|
106
|
-
if @buf.peek(2) == Transaction::
|
|
107
|
-
@buf.
|
|
95
|
+
if @buf.peek(2) == Transaction::NULL_BINARY
|
|
96
|
+
@buf.read(2)
|
|
108
97
|
else
|
|
109
|
-
magic = @buf.
|
|
110
|
-
raise ArgumentError, 'Not valid input' unless magic == Transaction::
|
|
98
|
+
magic = @buf.read(2)
|
|
99
|
+
raise ArgumentError, 'Not valid input' unless magic == Transaction::MAGIC_BINARY
|
|
111
100
|
|
|
112
|
-
deposit =
|
|
113
|
-
|
|
101
|
+
input['deposit'] = decode_deposit
|
|
102
|
+
end
|
|
114
103
|
|
|
115
|
-
|
|
116
|
-
|
|
104
|
+
if @buf.peek(2) == Transaction::NULL_BINARY
|
|
105
|
+
@buf.read(2)
|
|
106
|
+
else
|
|
107
|
+
magic = @buf.read(2)
|
|
108
|
+
raise ArgumentError, 'Not valid input' unless magic == Transaction::MAGIC_BINARY
|
|
117
109
|
|
|
118
|
-
|
|
119
|
-
|
|
110
|
+
input['mint'] = decode_mint
|
|
111
|
+
end
|
|
120
112
|
|
|
121
|
-
|
|
113
|
+
@tx.inputs.push input
|
|
114
|
+
end
|
|
115
|
+
end
|
|
122
116
|
|
|
123
|
-
|
|
124
|
-
|
|
117
|
+
def decode_deposit
|
|
118
|
+
deposit = {}
|
|
119
|
+
deposit['chain'] = @buf.read(32).unpack1('H*')
|
|
125
120
|
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
asset_size = @buf.read_uint16
|
|
122
|
+
asset = @buf.read(asset_size)
|
|
123
|
+
deposit['asset'] = @tx.safe_wire? ? asset : asset.unpack1('H*')
|
|
128
124
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
magic = @buf.shift(2)
|
|
133
|
-
raise ArgumentError, 'Not valid input' unless magic == Transaction::MAGIC
|
|
134
|
-
|
|
135
|
-
mint = {}
|
|
136
|
-
if @buf.peek(2) == Transaction::NULL_BYTES
|
|
137
|
-
@buf.shift(2)
|
|
138
|
-
else
|
|
139
|
-
group_size = MixinBot.utils.decode_uint16 @buf.shift(2)
|
|
140
|
-
mint['group'] = @buf.shift(group_size).unpack1('H*')
|
|
141
|
-
end
|
|
125
|
+
transaction_size = @buf.read_uint16
|
|
126
|
+
transaction = @buf.read(transaction_size)
|
|
127
|
+
deposit['transaction'] = @tx.safe_wire? ? transaction : transaction.unpack1('H*')
|
|
142
128
|
|
|
143
|
-
|
|
144
|
-
_amount_size = MixinBot.utils.decode_uint16 @buf.shift(2)
|
|
145
|
-
mint['amount'] = MixinBot.utils.decode_int @buf.shift(_amount_size)
|
|
129
|
+
deposit['index'] = @buf.read_uint64
|
|
146
130
|
|
|
147
|
-
|
|
148
|
-
|
|
131
|
+
amount = read_amount
|
|
132
|
+
deposit['amount'] = @tx.safe_wire? ? MixinBot.utils.format_safe_amount(amount) : amount
|
|
149
133
|
|
|
150
|
-
|
|
134
|
+
deposit
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def decode_mint
|
|
138
|
+
mint = {}
|
|
139
|
+
if @buf.peek(2) == Transaction::NULL_BINARY
|
|
140
|
+
@buf.read(2)
|
|
141
|
+
else
|
|
142
|
+
group_size = @buf.read_uint16
|
|
143
|
+
group = @buf.read(group_size)
|
|
144
|
+
mint['group'] = @tx.safe_wire? ? group : group.unpack1('H*')
|
|
151
145
|
end
|
|
152
146
|
|
|
153
|
-
@
|
|
147
|
+
mint['batch'] = @buf.read_uint64
|
|
148
|
+
amount = read_amount
|
|
149
|
+
mint['amount'] = @tx.safe_wire? ? MixinBot.utils.format_safe_amount(amount) : amount
|
|
150
|
+
|
|
151
|
+
mint
|
|
154
152
|
end
|
|
155
153
|
|
|
156
154
|
def decode_outputs
|
|
157
|
-
outputs_size =
|
|
155
|
+
outputs_size = read_count
|
|
158
156
|
@tx.outputs = []
|
|
159
157
|
outputs_size.times do
|
|
160
158
|
output = {}
|
|
161
159
|
|
|
162
|
-
@buf.
|
|
163
|
-
|
|
164
|
-
|
|
160
|
+
prefix = @buf.read_uint8
|
|
161
|
+
raise ArgumentError, 'invalid output prefix' if @tx.safe_wire? && !prefix.zero?
|
|
162
|
+
|
|
163
|
+
output['type'] = @buf.read_uint8
|
|
165
164
|
|
|
166
|
-
|
|
167
|
-
output['amount'] = format('%.8f', MixinBot.utils.decode_int(@buf.shift(amount_size)).to_f / 1e8).gsub(/\.?0+$/, '')
|
|
165
|
+
output['amount'] = MixinBot.utils.format_safe_amount(read_amount)
|
|
168
166
|
|
|
169
167
|
output['keys'] = []
|
|
170
|
-
keys_size =
|
|
168
|
+
keys_size = read_count
|
|
171
169
|
keys_size.times do
|
|
172
|
-
output['keys'].push @buf.
|
|
170
|
+
output['keys'].push @buf.read(32).unpack1('H*')
|
|
173
171
|
end
|
|
174
172
|
|
|
175
|
-
output['mask'] = @buf.
|
|
173
|
+
output['mask'] = @buf.read(32).unpack1('H*')
|
|
176
174
|
|
|
177
|
-
script_size =
|
|
178
|
-
output['script'] = @buf.
|
|
175
|
+
script_size = @buf.read_uint16
|
|
176
|
+
output['script'] = @buf.read(script_size).unpack1('H*')
|
|
179
177
|
|
|
180
|
-
if @buf.peek(2) == Transaction::
|
|
181
|
-
@buf.
|
|
178
|
+
if @buf.peek(2) == Transaction::NULL_BINARY
|
|
179
|
+
@buf.read(2)
|
|
182
180
|
else
|
|
183
|
-
magic = @buf.
|
|
184
|
-
raise ArgumentError, 'Not valid output' unless magic == Transaction::
|
|
181
|
+
magic = @buf.read(2)
|
|
182
|
+
raise ArgumentError, 'Not valid output' unless magic == Transaction::MAGIC_BINARY
|
|
185
183
|
|
|
186
|
-
withdrawal =
|
|
187
|
-
|
|
184
|
+
output['withdrawal'] = decode_withdrawal
|
|
185
|
+
end
|
|
188
186
|
|
|
189
|
-
|
|
190
|
-
|
|
187
|
+
@tx.outputs.push output
|
|
188
|
+
end
|
|
189
|
+
end
|
|
191
190
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
else
|
|
195
|
-
address_size = MixinBot.utils.decode_uint16 @buf.shift(2)
|
|
196
|
-
withdrawal['address'] = @buf.shift(address_size).pack('C*').unpack1('H*')
|
|
197
|
-
end
|
|
191
|
+
def decode_withdrawal
|
|
192
|
+
return { 'address' => @buf.read(@buf.read_uint16), 'tag' => @buf.read(@buf.read_uint16) } if @tx.safe_wire?
|
|
198
193
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
else
|
|
202
|
-
tag_size = MixinBot.utils.decode_uint16 @buf.shift(2)
|
|
203
|
-
withdrawal['tag'] = @buf.shift(tag_size).pack('C*').unpack1('H*')
|
|
204
|
-
end
|
|
194
|
+
withdrawal = {}
|
|
195
|
+
withdrawal['chain'] = @buf.read(32).unpack1('H*')
|
|
205
196
|
|
|
206
|
-
|
|
207
|
-
|
|
197
|
+
asset_size = @buf.read_uint16
|
|
198
|
+
withdrawal['asset'] = @buf.read(asset_size).unpack1('H*')
|
|
208
199
|
|
|
209
|
-
|
|
200
|
+
if @buf.peek(2) == Transaction::NULL_BINARY
|
|
201
|
+
@buf.read(2)
|
|
202
|
+
else
|
|
203
|
+
address_size = @buf.read_uint16
|
|
204
|
+
withdrawal['address'] = @buf.read(address_size).unpack1('H*')
|
|
210
205
|
end
|
|
211
206
|
|
|
212
|
-
@
|
|
207
|
+
if @buf.peek(2) == Transaction::NULL_BINARY
|
|
208
|
+
@buf.read(2)
|
|
209
|
+
else
|
|
210
|
+
tag_size = @buf.read_uint16
|
|
211
|
+
withdrawal['tag'] = @buf.read(tag_size).unpack1('H*')
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
withdrawal
|
|
213
215
|
end
|
|
214
216
|
|
|
215
217
|
def decode_references
|
|
216
|
-
references_size =
|
|
218
|
+
references_size = read_count
|
|
217
219
|
@tx.references = []
|
|
218
220
|
|
|
219
221
|
references_size.times do
|
|
220
|
-
@tx.references.push @buf.
|
|
222
|
+
@tx.references.push @buf.read(32).unpack1('H*')
|
|
221
223
|
end
|
|
224
|
+
end
|
|
222
225
|
|
|
223
|
-
|
|
226
|
+
def decode_aggregated_signature
|
|
227
|
+
@tx.aggregated = {}
|
|
228
|
+
|
|
229
|
+
prefix = @buf.read_uint16
|
|
230
|
+
raise ArgumentError, 'invalid aggregated' unless prefix == Transaction::AGGREGATED_SIGNATURE_PREFIX
|
|
231
|
+
|
|
232
|
+
@tx.aggregated['signature'] = @buf.read(64).unpack1('H*')
|
|
233
|
+
|
|
234
|
+
mask_type = @buf.read_uint8
|
|
235
|
+
case mask_type
|
|
236
|
+
when Transaction::AGGREGATED_SIGNATURE_ORDINAY_MASK.first
|
|
237
|
+
masks_size = @buf.read_uint16
|
|
238
|
+
raise ArgumentError, 'invalid signer mask size' if @tx.safe_wire? && masks_size > ((Transaction::MAX_ENCODE_INT / 8) + 1)
|
|
239
|
+
|
|
240
|
+
signers = []
|
|
241
|
+
masks_size.times do |i|
|
|
242
|
+
mask = @buf.read_uint8
|
|
243
|
+
8.times do |j|
|
|
244
|
+
signers.push((i * 8) + j) if mask.allbits?(1 << j)
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
@tx.aggregated['signers'] = signers
|
|
248
|
+
when Transaction::AGGREGATED_SIGNATURE_SPARSE_MASK.first
|
|
249
|
+
signers_size = @buf.read_uint16
|
|
250
|
+
@tx.aggregated['signers'] = []
|
|
251
|
+
signers_size.times do
|
|
252
|
+
@tx.aggregated['signers'].push @buf.read_uint16
|
|
253
|
+
end
|
|
254
|
+
else
|
|
255
|
+
raise ArgumentError, 'invalid aggregated signature mask'
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
raise ArgumentError, 'signers not sorted' unless @tx.aggregated['signers'].each_cons(2).all? { |a, b| a < b }
|
|
259
|
+
|
|
260
|
+
signers = @tx.aggregated['signers']
|
|
261
|
+
raise ArgumentError, 'too many aggregated signers' if signers.size > Transaction::MAX_ENCODE_INT
|
|
262
|
+
|
|
263
|
+
mask_bytes = signers.empty? ? 0 : (signers.last / 8) + 1
|
|
264
|
+
sparse = mask_type == Transaction::AGGREGATED_SIGNATURE_SPARSE_MASK.first
|
|
265
|
+
canonical = sparse == (mask_bytes > signers.size * 2) && (sparse || masks_size == mask_bytes)
|
|
266
|
+
raise ArgumentError, 'non-canonical aggregated signature mask' if @tx.safe_wire? && !canonical
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def decode_signatures(num)
|
|
270
|
+
@tx.signatures = []
|
|
271
|
+
num.times do
|
|
272
|
+
signature = {}
|
|
273
|
+
|
|
274
|
+
keys_size = @buf.read_uint16
|
|
275
|
+
previous_index = -1
|
|
276
|
+
|
|
277
|
+
keys_size.times do
|
|
278
|
+
index = @buf.read_uint16
|
|
279
|
+
raise ArgumentError, 'signature indices must be sorted and unique' if @tx.safe_wire? && index <= previous_index
|
|
280
|
+
|
|
281
|
+
signature[index] = @buf.read(64).unpack1('H*')
|
|
282
|
+
previous_index = index
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
@tx.signatures << signature
|
|
286
|
+
end
|
|
224
287
|
end
|
|
225
288
|
end
|
|
226
289
|
end
|