nem-ruby 0.0.1
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +119 -0
- data/.travis.yml +23 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/README.md +81 -0
- data/Rakefile +6 -0
- data/examples/apostille_audit.rb +22 -0
- data/examples/apostille_create.rb +31 -0
- data/examples/endpoint/account.rb +73 -0
- data/examples/endpoint/account_local.rb +21 -0
- data/examples/endpoint/block.rb +14 -0
- data/examples/endpoint/chain.rb +15 -0
- data/examples/endpoint/debug.rb +17 -0
- data/examples/endpoint/local.rb +17 -0
- data/examples/endpoint/mosaic.rb +9 -0
- data/examples/endpoint/namespace.rb +13 -0
- data/examples/endpoint/node.rb +24 -0
- data/examples/endpoint/timesync.rb +9 -0
- data/examples/endpoint/transaction.rb +42 -0
- data/examples/localnode.rb +0 -0
- data/examples/nis.rb +34 -0
- data/examples/node_pool.rb +23 -0
- data/examples/transaction/importance_transfer.rb +23 -0
- data/examples/transaction/mosaic_definition_creation.rb +52 -0
- data/examples/transaction/mosaic_supply_change.rb +25 -0
- data/examples/transaction/multisig_add_cosignatory.rb +31 -0
- data/examples/transaction/multisig_aggregate_modification.rb +29 -0
- data/examples/transaction/multisig_signature.rb +41 -0
- data/examples/transaction/multisig_transfer.rb +35 -0
- data/examples/transaction/provision_namespace.rb +20 -0
- data/examples/transaction/transfer.rb +32 -0
- data/examples/transaction/transfer_mosaic.rb +72 -0
- data/examples/transaction/transfer_with_encrypted_message.rb +40 -0
- data/examples/transaction/transfer_with_local.rb +34 -0
- data/lib/nem.rb +21 -0
- data/lib/nem/apostille.rb +104 -0
- data/lib/nem/apostille_audit.rb +47 -0
- data/lib/nem/client.rb +170 -0
- data/lib/nem/configuration.rb +29 -0
- data/lib/nem/endpoint.rb +4 -0
- data/lib/nem/endpoint/account.rb +264 -0
- data/lib/nem/endpoint/base.rb +45 -0
- data/lib/nem/endpoint/block.rb +15 -0
- data/lib/nem/endpoint/chain.rb +17 -0
- data/lib/nem/endpoint/debug.rb +54 -0
- data/lib/nem/endpoint/local/account.rb +54 -0
- data/lib/nem/endpoint/local/chain.rb +15 -0
- data/lib/nem/endpoint/mosaic.rb +13 -0
- data/lib/nem/endpoint/namespace.rb +37 -0
- data/lib/nem/endpoint/node.rb +83 -0
- data/lib/nem/endpoint/timesync.rb +9 -0
- data/lib/nem/endpoint/transaction.rb +34 -0
- data/lib/nem/error.rb +6 -0
- data/lib/nem/fee.rb +2 -0
- data/lib/nem/fee/importance_transfer.rb +24 -0
- data/lib/nem/fee/mosaic_definition_creation.rb +24 -0
- data/lib/nem/fee/mosaic_supply_change_transfer.rb +24 -0
- data/lib/nem/fee/multisig.rb +24 -0
- data/lib/nem/fee/multisig_aggregation_modification.rb +28 -0
- data/lib/nem/fee/provision_namespace.rb +34 -0
- data/lib/nem/fee/transfer.rb +66 -0
- data/lib/nem/keypair.rb +44 -0
- data/lib/nem/mixin.rb +2 -0
- data/lib/nem/mixin/assignable.rb +12 -0
- data/lib/nem/model.rb +3 -0
- data/lib/nem/model/account.rb +67 -0
- data/lib/nem/model/account_historical.rb +19 -0
- data/lib/nem/model/block.rb +33 -0
- data/lib/nem/model/chain.rb +14 -0
- data/lib/nem/model/connection.rb +23 -0
- data/lib/nem/model/experience.rb +20 -0
- data/lib/nem/model/explorer_block.rb +21 -0
- data/lib/nem/model/harvest.rb +23 -0
- data/lib/nem/model/heartbeat.rb +21 -0
- data/lib/nem/model/importance.rb +29 -0
- data/lib/nem/model/importance_transfer_transaction.rb +16 -0
- data/lib/nem/model/keypair.rb +19 -0
- data/lib/nem/model/message.rb +91 -0
- data/lib/nem/model/mosaic.rb +21 -0
- data/lib/nem/model/mosaic_attachment.rb +22 -0
- data/lib/nem/model/mosaic_definition.rb +65 -0
- data/lib/nem/model/mosaic_definition_creation_transaction.rb +18 -0
- data/lib/nem/model/mosaic_id.rb +27 -0
- data/lib/nem/model/mosaic_levy.rb +32 -0
- data/lib/nem/model/mosaic_owned.rb +22 -0
- data/lib/nem/model/mosaic_properties.rb +44 -0
- data/lib/nem/model/mosaic_supply.rb +21 -0
- data/lib/nem/model/mosaic_supply_change_transaction.rb +18 -0
- data/lib/nem/model/multisig_aggregate_modification_transaction.rb +21 -0
- data/lib/nem/model/multisig_info.rb +16 -0
- data/lib/nem/model/multisig_signature_transaction.rb +17 -0
- data/lib/nem/model/multisig_transaction.rb +21 -0
- data/lib/nem/model/namespace.rb +24 -0
- data/lib/nem/model/nem_announce_result.rb +19 -0
- data/lib/nem/model/network_time.rb +16 -0
- data/lib/nem/model/nis_node_info.rb +26 -0
- data/lib/nem/model/node.rb +41 -0
- data/lib/nem/model/provision_namespace_transaction.rb +18 -0
- data/lib/nem/model/status.rb +21 -0
- data/lib/nem/model/timer.rb +31 -0
- data/lib/nem/model/timesync.rb +19 -0
- data/lib/nem/model/transaction.rb +71 -0
- data/lib/nem/model/transfer_transaction.rb +24 -0
- data/lib/nem/model/unlocked_info.rb +24 -0
- data/lib/nem/mosaic.rb +2 -0
- data/lib/nem/mosaic/dim_coin.rb +21 -0
- data/lib/nem/mosaic/dim_token.rb +21 -0
- data/lib/nem/mosaic/ecobit_eco.rb +21 -0
- data/lib/nem/mosaic/xem.rb +21 -0
- data/lib/nem/node.rb +29 -0
- data/lib/nem/node_pool.rb +31 -0
- data/lib/nem/request.rb +2 -0
- data/lib/nem/request/announce.rb +76 -0
- data/lib/nem/transaction.rb +3 -0
- data/lib/nem/transaction/base.rb +45 -0
- data/lib/nem/transaction/importance_transfer.rb +42 -0
- data/lib/nem/transaction/mosaic_definition_creation.rb +45 -0
- data/lib/nem/transaction/mosaic_supply_change.rb +45 -0
- data/lib/nem/transaction/multisig.rb +29 -0
- data/lib/nem/transaction/multisig_aggregate_modification.rb +30 -0
- data/lib/nem/transaction/multisig_cosignatory_modification.rb +33 -0
- data/lib/nem/transaction/multisig_signature.rb +31 -0
- data/lib/nem/transaction/provision_namespace.rb +65 -0
- data/lib/nem/transaction/transfer.rb +63 -0
- data/lib/nem/util.rb +44 -0
- data/lib/nem/util/assignable.rb +51 -0
- data/lib/nem/util/convert.rb +112 -0
- data/lib/nem/util/deserializer.rb +158 -0
- data/lib/nem/util/ed25519.rb +316 -0
- data/lib/nem/util/serializer.rb +260 -0
- data/lib/nem/version.rb +3 -0
- data/nem-ruby.gemspec +46 -0
- metadata +350 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
module Nem
|
2
|
+
module Model
|
3
|
+
class NodeMetadata
|
4
|
+
include Nem::Mixin::Assignable
|
5
|
+
|
6
|
+
attr_reader :features,
|
7
|
+
:network,
|
8
|
+
:application,
|
9
|
+
:version,
|
10
|
+
:platform
|
11
|
+
end
|
12
|
+
|
13
|
+
class NodeEndpoint
|
14
|
+
include Nem::Mixin::Assignable
|
15
|
+
|
16
|
+
attr_reader :protocol, :port, :host
|
17
|
+
end
|
18
|
+
|
19
|
+
class NodeIdentity
|
20
|
+
include Nem::Mixin::Assignable
|
21
|
+
|
22
|
+
attr_reader :name, :public_key
|
23
|
+
end
|
24
|
+
|
25
|
+
class Node
|
26
|
+
include Nem::Mixin::Assignable
|
27
|
+
|
28
|
+
attr_reader :metadata,
|
29
|
+
:endpoint,
|
30
|
+
:identity
|
31
|
+
|
32
|
+
def self.new_from_node(hash)
|
33
|
+
new(
|
34
|
+
metadata: NodeMetadata.new(hash[:metaData]),
|
35
|
+
endpoint: NodeEndpoint.new(hash[:endpoint]),
|
36
|
+
identity: NodeIdentity.new(hash[:identity])
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Nem
|
2
|
+
module Model
|
3
|
+
class ProvisionNamespaceTransaction < Transaction
|
4
|
+
attr_reader :rental_fee, :rental_fee_sink, :parent, :new_part
|
5
|
+
|
6
|
+
def self.new_from_transaction_meta_data_pair(hash)
|
7
|
+
transaction = hash[:transaction]
|
8
|
+
attrs = common_part_meta_data_pair(hash).merge(
|
9
|
+
rental_fee: transaction[:rentalFee],
|
10
|
+
rental_fee_sink: transaction[:rentalFeeSink],
|
11
|
+
parent: transaction[:parent],
|
12
|
+
new_part: transaction[:newPart]
|
13
|
+
)
|
14
|
+
new(attrs)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Nem
|
2
|
+
module Model
|
3
|
+
class Status
|
4
|
+
include Nem::Mixin::Assignable
|
5
|
+
|
6
|
+
attr_reader :code,
|
7
|
+
:type,
|
8
|
+
:message
|
9
|
+
|
10
|
+
# 0: Unknown status.
|
11
|
+
# 1: NIS is stopped.
|
12
|
+
# 2: NIS is starting.
|
13
|
+
# 3: NIS is running.
|
14
|
+
# 4: NIS is booting the local node (implies NIS is running).
|
15
|
+
# 5: The local node is booted (implies NIS is running).
|
16
|
+
# 6: The local node is synchronized (implies NIS is running and the local node is booted).
|
17
|
+
# 7: NIS local node does not see any remote NIS node (implies running and booted).
|
18
|
+
# 8: NIS is currently loading the block chain from the database. In this state NIS cannot serve any requests.
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Nem
|
2
|
+
module Model
|
3
|
+
class Timer
|
4
|
+
include Nem::Mixin::Assignable
|
5
|
+
|
6
|
+
attr_reader :last_delay_time,
|
7
|
+
:executions,
|
8
|
+
:failures,
|
9
|
+
:successes,
|
10
|
+
:last_operation_start_time,
|
11
|
+
:is_executing,
|
12
|
+
:name,
|
13
|
+
:average_operation_time,
|
14
|
+
:operation_time
|
15
|
+
|
16
|
+
def self.new_from_timer(hash)
|
17
|
+
new(
|
18
|
+
last_delay_time: hash[:'last-delay-time'],
|
19
|
+
executions: hash[:executions],
|
20
|
+
failures: hash[:failures],
|
21
|
+
successes: hash[:successes],
|
22
|
+
last_operation_start_time: hash[:'last-operation-start-time'],
|
23
|
+
is_executing: hash[:'is-executing'],
|
24
|
+
name: hash[:name],
|
25
|
+
average_operation_time: hash[:'average-operation-time'],
|
26
|
+
operation_time: hash[:'operation-time']
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Nem
|
2
|
+
module Model
|
3
|
+
class Timesync
|
4
|
+
include Nem::Mixin::Assignable
|
5
|
+
|
6
|
+
attr_reader :datetime,
|
7
|
+
:current_time_offset,
|
8
|
+
:change
|
9
|
+
|
10
|
+
def self.new_from_timer(hash)
|
11
|
+
new(
|
12
|
+
datetime: hash[:datetime],
|
13
|
+
current_time_offset: hash[:current_time_offset],
|
14
|
+
change: hash[:change]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Nem
|
2
|
+
module Model
|
3
|
+
class Transaction
|
4
|
+
include Nem::Mixin::Assignable
|
5
|
+
|
6
|
+
attr_reader :timestamp,
|
7
|
+
:version,
|
8
|
+
:type,
|
9
|
+
:signer,
|
10
|
+
:fee,
|
11
|
+
:deadline,
|
12
|
+
:id,
|
13
|
+
:hash,
|
14
|
+
:height
|
15
|
+
|
16
|
+
def version?(num)
|
17
|
+
num == 1 ? true : false # TODO: version
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.new_from_account_transaction(hash)
|
21
|
+
new_from_account_transaction_meta_data_pair(
|
22
|
+
meta: { data: nil },
|
23
|
+
transaction: hash
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.new_from_account_transaction_meta_data_pair(hash)
|
28
|
+
type = hash[:transaction][:type]
|
29
|
+
klass = case type
|
30
|
+
when 0x0101 then TransferTransaction
|
31
|
+
when 0x0801 then ImportanceTransferTransaction
|
32
|
+
when 0x1001 then MultisigAggregateModificationTransaction
|
33
|
+
when 0x1002 then MultisigSignatureTransaction
|
34
|
+
when 0x1004 then MultisigTransaction
|
35
|
+
when 0x2001 then ProvisionNamespaceTransaction
|
36
|
+
when 0x4001 then MosaicDefinitionCreationTransaction
|
37
|
+
when 0x4002 then MosaicSupplyChangeTransaction
|
38
|
+
else raise "Undefined transaction type: #{type}"
|
39
|
+
end
|
40
|
+
klass.new_from_transaction_meta_data_pair(hash)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.common_part(hash)
|
44
|
+
{
|
45
|
+
timestamp: hash[:timeStamp],
|
46
|
+
version: hash[:version],
|
47
|
+
type: hash[:type],
|
48
|
+
signer: hash[:signer],
|
49
|
+
fee: hash[:fee],
|
50
|
+
deadline: hash[:deadline]
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.common_part_meta_data_pair(hash)
|
55
|
+
meta = hash[:meta]
|
56
|
+
transaction = hash[:transaction]
|
57
|
+
{
|
58
|
+
id: meta[:id],
|
59
|
+
hash: meta[:hash] ? meta[:hash][:data] : meta[:data],
|
60
|
+
height: meta[:height],
|
61
|
+
timestamp: transaction[:timeStamp],
|
62
|
+
version: transaction[:version],
|
63
|
+
type: transaction[:type],
|
64
|
+
signer: transaction[:signer],
|
65
|
+
fee: transaction[:fee],
|
66
|
+
deadline: transaction[:deadline]
|
67
|
+
}
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Nem
|
2
|
+
module Model
|
3
|
+
class TransferTransaction < Transaction
|
4
|
+
attr_reader :recipient, :amount, :message, :mosaics
|
5
|
+
|
6
|
+
def self.new_from_transaction_meta_data_pair(hash)
|
7
|
+
transaction = hash[:transaction]
|
8
|
+
attrs = common_part_meta_data_pair(hash).merge(
|
9
|
+
recipient: transaction[:recipient],
|
10
|
+
amount: transaction[:amount],
|
11
|
+
)
|
12
|
+
unless transaction[:message].empty?
|
13
|
+
attrs[:message] = Nem::Model::Message.new_from_message(transaction[:message])
|
14
|
+
end
|
15
|
+
if transaction[:mosaics]
|
16
|
+
attrs[:mosaics] = transaction[:mosaics].map do |mo|
|
17
|
+
Mosaic.new(mo)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
new(attrs)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Nem
|
2
|
+
module Model
|
3
|
+
class UnlockedInfo
|
4
|
+
include Nem::Mixin::Assignable
|
5
|
+
|
6
|
+
attr_reader :max_unlocked, :num_unlocked
|
7
|
+
|
8
|
+
def self.new_from_unlocked_info(hash)
|
9
|
+
new(
|
10
|
+
max_unlocked: hash[:'max-unlocked'],
|
11
|
+
num_unlocked: hash[:'num-unlocked']
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_freeslot?
|
16
|
+
! @max_unlocked == @num_unlocked
|
17
|
+
end
|
18
|
+
|
19
|
+
def freeslot
|
20
|
+
@max_unlocked - @num_unlocked
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/nem/mosaic.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Nem
|
2
|
+
module Mosaic
|
3
|
+
class DimCoin < Nem::Model::MosaicAttachment
|
4
|
+
def initialize(quantity)
|
5
|
+
mosaic_id = Nem::Model::MosaicId.new(
|
6
|
+
namespace_id: 'dim',
|
7
|
+
name: 'coin'
|
8
|
+
)
|
9
|
+
properties = Nem::Model::MosaicProperties.new(
|
10
|
+
divisibility: 6,
|
11
|
+
initial_supply: 900_000_000
|
12
|
+
)
|
13
|
+
super(
|
14
|
+
mosaic_id: mosaic_id,
|
15
|
+
properties: properties,
|
16
|
+
quantity: quantity
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Nem
|
2
|
+
module Mosaic
|
3
|
+
class DimToken < Nem::Model::MosaicAttachment
|
4
|
+
def initialize(quantity)
|
5
|
+
mosaic_id = Nem::Model::MosaicId.new(
|
6
|
+
namespace_id: 'dim',
|
7
|
+
name: 'token'
|
8
|
+
)
|
9
|
+
properties = Nem::Model::MosaicProperties.new(
|
10
|
+
divisibility: 6,
|
11
|
+
initial_supply: 1_000_000
|
12
|
+
)
|
13
|
+
super(
|
14
|
+
mosaic_id: mosaic_id,
|
15
|
+
properties: properties,
|
16
|
+
quantity: quantity
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Nem
|
2
|
+
module Mosaic
|
3
|
+
class EcobitEco < Nem::Model::MosaicAttachment
|
4
|
+
def initialize(quantity)
|
5
|
+
mosaic_id = Nem::Model::MosaicId.new(
|
6
|
+
namespace_id: 'ecobit',
|
7
|
+
name: 'eco'
|
8
|
+
)
|
9
|
+
properties = Nem::Model::MosaicProperties.new(
|
10
|
+
divisibility: 0,
|
11
|
+
initial_supply: 888_888_888
|
12
|
+
)
|
13
|
+
super(
|
14
|
+
mosaic_id: mosaic_id,
|
15
|
+
properties: properties,
|
16
|
+
quantity: quantity
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Nem
|
2
|
+
module Mosaic
|
3
|
+
class Xem < Nem::Model::MosaicAttachment
|
4
|
+
def initialize(quantity)
|
5
|
+
mosaic_id = Nem::Model::MosaicId.new(
|
6
|
+
namespace_id: 'nem',
|
7
|
+
name: 'xem'
|
8
|
+
)
|
9
|
+
properties = Nem::Model::MosaicProperties.new(
|
10
|
+
divisibility: 6,
|
11
|
+
initial_supply: 8_999_999_999
|
12
|
+
)
|
13
|
+
super(
|
14
|
+
mosaic_id: mosaic_id,
|
15
|
+
properties: properties,
|
16
|
+
quantity: quantity
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/nem/node.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Nem
|
2
|
+
class Node
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
def_delegators :@client, :request, :request!
|
6
|
+
|
7
|
+
# @param [hash] options HTTP Client connection information
|
8
|
+
# @option options [String] :url URL
|
9
|
+
# @option options [String] :scheme default http
|
10
|
+
# @option options [Symbol] :host default 127.0.0.1
|
11
|
+
# @option options [Integer] :port default 7890
|
12
|
+
# @option options [Integer] :timeout default 5
|
13
|
+
def initialize(options = {})
|
14
|
+
@client = Nem::Client.new(options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def heartbeat
|
18
|
+
Nem::Model::Heartbeat.new request!(:get, '/heartbeat')
|
19
|
+
end
|
20
|
+
|
21
|
+
def status
|
22
|
+
Nem::Model::Status.new request!(:get, '/status')
|
23
|
+
end
|
24
|
+
|
25
|
+
def shutdown
|
26
|
+
request!(:get, '/shutdown')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Nem
|
2
|
+
class NodePool
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
def_delegators :@nodes, :first, :last, :length
|
6
|
+
|
7
|
+
attr_reader :nodes, :failed
|
8
|
+
|
9
|
+
def self.from_hash(definitions)
|
10
|
+
new(definitions.map { |d| Nem::Node.new(d) })
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(nodes)
|
14
|
+
@nodes = nodes
|
15
|
+
@failed = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def current
|
19
|
+
@nodes.first
|
20
|
+
end
|
21
|
+
|
22
|
+
def next!
|
23
|
+
@failed << @nodes.shift
|
24
|
+
raise 'Exhausted node pool' if length.zero?
|
25
|
+
end
|
26
|
+
|
27
|
+
def <<(definitioin)
|
28
|
+
@nodes << Nem::Node.new(definitioin)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/nem/request.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
module Nem
|
2
|
+
module Request
|
3
|
+
# @attr [Nem::Struct::Transaction] transaction
|
4
|
+
# @attr [Nem::Keypair] keypair
|
5
|
+
# @attr [String] data
|
6
|
+
# @attr [String] signature
|
7
|
+
# @see https://nemproject.github.io/#requestAnnounce
|
8
|
+
# @see https://nemproject.github.io/#requestPrepareAnnounce
|
9
|
+
class Announce
|
10
|
+
attr_reader :transaction, :keypair, :data, :signature
|
11
|
+
|
12
|
+
def initialize(transaction, keypair)
|
13
|
+
@transaction = transaction
|
14
|
+
@keypair = keypair
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [Hash] Attribute and value pairs
|
18
|
+
def to_entity(state = nil)
|
19
|
+
entity = prepare_entity
|
20
|
+
if state == :prepare
|
21
|
+
{ transaction: entity,
|
22
|
+
privateKey: keypair.private }
|
23
|
+
else
|
24
|
+
serialized = serialize(entity)
|
25
|
+
hex_serialized = Nem::Util::Convert.ua2hex(serialized)
|
26
|
+
{ data: Nem::Util::Convert.ua2hex(serialized),
|
27
|
+
signature: signature(hex_serialized) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def prepare_entity
|
34
|
+
specify = if transaction.multisig?
|
35
|
+
prepare_multisig(transaction)
|
36
|
+
else
|
37
|
+
transaction.to_hash
|
38
|
+
end
|
39
|
+
set_common(specify)
|
40
|
+
end
|
41
|
+
|
42
|
+
def prepare_multisig(tx)
|
43
|
+
other_trans = tx.other_trans.to_hash.merge(
|
44
|
+
type: tx.other_trans.type,
|
45
|
+
fee: tx.other_trans.fee.to_i,
|
46
|
+
timeStamp: Nem::Util.timestamp,
|
47
|
+
deadline: Nem::Util.deadline(Nem.deadline),
|
48
|
+
signer: tx.signer,
|
49
|
+
version: tx.other_trans.version
|
50
|
+
)
|
51
|
+
tx.to_hash.merge(
|
52
|
+
otherTrans: other_trans
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_common(hash)
|
57
|
+
hash.merge(
|
58
|
+
type: transaction.type,
|
59
|
+
fee: transaction.fee.to_i,
|
60
|
+
timeStamp: Nem::Util.timestamp,
|
61
|
+
deadline: Nem::Util.deadline(Nem.deadline),
|
62
|
+
signer: keypair.public,
|
63
|
+
version: transaction.version
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def serialize(hash)
|
68
|
+
Nem::Util::Serializer.serialize_transaction(hash)
|
69
|
+
end
|
70
|
+
|
71
|
+
def signature(serialized)
|
72
|
+
keypair.sign(serialized)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|