nem-ruby 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/docs/examples/define_mosaic_attachment.md +2 -1
- data/docs/examples/transactions.md +2 -1
- data/docs/examples/util.md +4 -4
- data/docs/mosaic.md +2 -1
- data/examples/endpoint/local.rb +7 -4
- data/examples/offline/announce_offline_transfer.rb +5 -2
- data/examples/offline/future_timestamp.rb +32 -0
- data/examples/transaction/transfer_mosaic.rb +2 -1
- data/examples/util/deserialize.rb +11 -5
- data/lib/nem/endpoint/local/account.rb +12 -12
- data/lib/nem/mixin/mosaic_attachable.rb +63 -0
- data/lib/nem/mixin/{mosaic.rb → mosaic_definition.rb} +0 -0
- data/lib/nem/model/mosaic_collection.rb +2 -2
- data/lib/nem/model/transaction.rb +8 -9
- data/lib/nem/mosaic/comsa_cms.rb +11 -0
- data/lib/nem/mosaic/dim_coin.rb +2 -1
- data/lib/nem/mosaic/dim_token.rb +2 -1
- data/lib/nem/mosaic/ecobit_eco.rb +2 -1
- data/lib/nem/mosaic/xem.rb +2 -1
- data/lib/nem/request/announce.rb +8 -4
- data/lib/nem/transaction/base.rb +2 -3
- data/lib/nem/transaction/importance_transfer.rb +3 -1
- data/lib/nem/transaction/mosaic_definition_creation.rb +3 -1
- data/lib/nem/transaction/mosaic_supply_change.rb +3 -1
- data/lib/nem/transaction/multisig.rb +3 -1
- data/lib/nem/transaction/multisig_aggregate_modification.rb +3 -1
- data/lib/nem/transaction/multisig_signature.rb +3 -1
- data/lib/nem/transaction/provision_namespace.rb +3 -1
- data/lib/nem/transaction/transfer.rb +5 -3
- data/lib/nem/unit/time.rb +39 -0
- data/lib/nem/unit/version.rb +50 -0
- data/lib/nem/version.rb +1 -1
- metadata +8 -4
- data/lib/nem/mosaic/base.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cda64b6f121acde42a6bfa87e5b511e5b1724745501c6f870fb7e117633c3a0
|
4
|
+
data.tar.gz: 8adbe26b6f262f6c6aad3481d94d5eb1c83732c3a011ac811ebc7816cd7a66e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3b070d76441e1b7ce75fcf33c0a1b25b8aa73bf81c065ba62bab645d36f41344eac4a9395b3bdf6e0820da79b2c5e663dd46324bf376fe707bd2c03b8ef9cb6
|
7
|
+
data.tar.gz: 8379caf982918d94d683070ee350d85eb1e8fe3ec1ec18da39e5bb33c3320d2db65bb1e4426acd7225264db43a9fde32a1ab299881b087379ddd9103742fa608
|
data/README.md
CHANGED
@@ -7,12 +7,10 @@
|
|
7
7
|
|
8
8
|
<img src="https://cloud.githubusercontent.com/assets/370508/24320282/a332d238-1175-11e7-96dc-75bc30e562d2.png" width="280" height="280" alt="nem" align="right" />
|
9
9
|
|
10
|
-
Ruby gem for communicating with the
|
10
|
+
Ruby gem for communicating with nem network through the NIS API.
|
11
11
|
|
12
12
|
*The gem is under development. Incompatible changes can be made.*
|
13
13
|
|
14
|
-
*Not recommended for production use because of lack of testing, needed more improvement.*
|
15
|
-
|
16
14
|
For further development of nem with ruby, [feel free to send me your feedback!](#feedback-and-contact)
|
17
15
|
|
18
16
|
* [NEM \- Distributed Ledger Technology \(Blockchain\)](https://www.nem.io/)
|
@@ -27,7 +27,8 @@ pp "TransactionHash: #{res.transaction_hash}"
|
|
27
27
|
tx = Nem::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
|
28
28
|
|
29
29
|
# define custom mosaic attachment if you already know mosaic definition
|
30
|
-
class KonHeart
|
30
|
+
class KonHeart
|
31
|
+
include Nem::Mixin::MosaicAttachable
|
31
32
|
namespace_id 'kon'
|
32
33
|
name 'heart'
|
33
34
|
divisibility 3
|
data/docs/examples/util.md
CHANGED
@@ -13,12 +13,12 @@ B_ADDRESS = 'TAWKJTUP4DWKLDKKS534TYP6G324CBNMXKBA4X7B'
|
|
13
13
|
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
14
14
|
tx = Nem::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
|
15
15
|
req = Nem::Request::Announce.new(tx, kp)
|
16
|
-
|
17
|
-
entity = req.to_entity
|
16
|
+
data = req.to_entity[:data]
|
18
17
|
|
19
18
|
# You can also announce to nem Network later.
|
20
|
-
pp
|
19
|
+
pp data
|
21
20
|
|
22
21
|
# deserialize data into hash
|
23
|
-
|
22
|
+
hash = Nem::Util::Deserializer.deserialize_transaction(data)
|
23
|
+
pp Nem::Model::Transaction.new_from_account_transaction(hash)
|
24
24
|
```
|
data/docs/mosaic.md
CHANGED
data/examples/endpoint/local.rb
CHANGED
@@ -4,6 +4,13 @@ require 'nem'
|
|
4
4
|
node = Nem::Node.new
|
5
5
|
|
6
6
|
# new Local Endpoint Object
|
7
|
+
|
8
|
+
## Local Chain
|
9
|
+
lchain_endpoint = Nem::Endpoint::Local::Chain.new(node)
|
10
|
+
|
11
|
+
pp lchain_endpoint.blocks_after(1_223_559)
|
12
|
+
|
13
|
+
## Local Account
|
7
14
|
laccount_endpoint = Nem::Endpoint::Local::Account.new(node)
|
8
15
|
|
9
16
|
pp laccount_endpoint.transfers('00b4a68d16dc505302e9631b860664ba43a8183f0903bc5782a2403b2f9eb3c8a1', dir: :in)
|
@@ -11,7 +18,3 @@ pp laccount_endpoint.transfers('00b4a68d16dc505302e9631b860664ba43a8183f0903bc57
|
|
11
18
|
pp laccount_endpoint.transfers('00b4a68d16dc505302e9631b860664ba43a8183f0903bc5782a2403b2f9eb3c8a1', dir: :out)
|
12
19
|
|
13
20
|
pp laccount_endpoint.transfers('00b4a68d16dc505302e9631b860664ba43a8183f0903bc5782a2403b2f9eb3c8a1', dir: :all)
|
14
|
-
|
15
|
-
lchain_endpoint = Nem::Endpoint::Local::Chain.new(node)
|
16
|
-
|
17
|
-
pp lchain_endpoint.blocks_after(1_223_559)
|
@@ -1,11 +1,14 @@
|
|
1
1
|
require 'pp'
|
2
2
|
require 'nem'
|
3
3
|
|
4
|
+
req = JSON.parse(File.read('tx.json'), symbolize_names: true)
|
5
|
+
hash = Nem::Util::Deserializer.deserialize_transaction(req[:data])
|
6
|
+
pp Nem::Model::Transaction.new_from_account_transaction(hash)
|
7
|
+
|
4
8
|
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
5
9
|
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
6
10
|
|
7
|
-
|
8
|
-
res = tx_endpoint.announce(JSON.parse(req))
|
11
|
+
res = tx_endpoint.announce(req)
|
9
12
|
|
10
13
|
pp res
|
11
14
|
pp "Message: #{res.message}"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'nem'
|
3
|
+
|
4
|
+
Nem.logger.level = Logger::DEBUG
|
5
|
+
|
6
|
+
# sender
|
7
|
+
A_PRIVATE_KEY = '4ce5c8f9fce571db0d9ac1adf00b8d3ba0f078ed40835fd3d730a2f24b834214'
|
8
|
+
|
9
|
+
# recipient
|
10
|
+
B_ADDRESS = 'TA4TX6U5HG2MROAESH2JE5524T4ZOY2EQKQ6ELHF'
|
11
|
+
|
12
|
+
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
13
|
+
node = Nem::Node.new(host: 'bigalice2.nem.ninja')
|
14
|
+
tx_endpoint = Nem::Endpoint::Transaction.new(node)
|
15
|
+
|
16
|
+
# with future timestamp
|
17
|
+
tx = Nem::Transaction::Transfer.new(B_ADDRESS, 0, 'Good luck! Set future timestamp',
|
18
|
+
timestamp: Time.now + 300,
|
19
|
+
deadline: Time.now + 3900
|
20
|
+
)
|
21
|
+
|
22
|
+
req = Nem::Request::Announce.new(tx, kp)
|
23
|
+
res = tx_endpoint.announce(req)
|
24
|
+
|
25
|
+
# # It occurs "FAILURE_TIMESTAMP_TOO_FAR_IN_FUTURE"
|
26
|
+
pp "Message: #{res.message}"
|
27
|
+
pp "TransactionHash: #{res.transaction_hash}"
|
28
|
+
|
29
|
+
# Save signed transaction for announcing after 5 mins.
|
30
|
+
pp data = req.to_entity
|
31
|
+
pp 'save as tx.json'
|
32
|
+
File.write 'tx.json', data.to_json
|
@@ -28,7 +28,8 @@ moa = Nem::Model::MosaicAttachment.new(
|
|
28
28
|
tx.mosaics << moa
|
29
29
|
|
30
30
|
# define custom mosaic attachment if you already know definition.
|
31
|
-
class KonHeart
|
31
|
+
class KonHeart
|
32
|
+
include Nem::Mixin::MosaicAttachable
|
32
33
|
namespace_id 'kon'
|
33
34
|
name 'heart'
|
34
35
|
divisibility 3
|
@@ -9,12 +9,18 @@ B_ADDRESS = 'TAWKJTUP4DWKLDKKS534TYP6G324CBNMXKBA4X7B'
|
|
9
9
|
|
10
10
|
kp = Nem::Keypair.new(A_PRIVATE_KEY)
|
11
11
|
tx = Nem::Transaction::Transfer.new(B_ADDRESS, 1, 'Good luck!')
|
12
|
-
req = Nem::Request::Announce.new(tx, kp)
|
13
12
|
|
14
|
-
|
13
|
+
tx.mosaics << Nem::Mosaic::Xem.new(1_000)
|
14
|
+
tx.mosaics << Nem::Mosaic::DimCoin.new(100)
|
15
|
+
tx.mosaics << Nem::Mosaic::DimToken.new(10)
|
16
|
+
tx.mosaics << Nem::Mosaic::EcobitEco.new(10_000)
|
17
|
+
|
18
|
+
req = Nem::Request::Announce.new(tx, kp)
|
19
|
+
data = req.to_entity[:data]
|
15
20
|
|
16
|
-
#
|
17
|
-
pp
|
21
|
+
# serialized transaction data
|
22
|
+
pp data
|
18
23
|
|
19
24
|
# deserialize data into hash
|
20
|
-
|
25
|
+
hash = Nem::Util::Deserializer.deserialize_transaction(data)
|
26
|
+
pp Nem::Model::Transaction.new_from_account_transaction(hash)
|
@@ -4,12 +4,12 @@ module Nem
|
|
4
4
|
class Account < Nem::Endpoint::Base
|
5
5
|
# @see https://nemproject.github.io/#transaction-data-with-decoded-messages
|
6
6
|
def transfers_incoming(value, hash: nil, id: nil, page_size: nil)
|
7
|
-
|
7
|
+
page = {
|
8
8
|
value: value,
|
9
9
|
hash: hash,
|
10
|
-
id: id
|
11
|
-
|
12
|
-
) do |res|
|
10
|
+
id: id
|
11
|
+
}
|
12
|
+
request!(:post, '/local/account/transfers/incoming', page) do |res|
|
13
13
|
res[:data].map do |tx|
|
14
14
|
Nem::Model::Transaction.new_from_account_transaction_meta_data_pair(tx)
|
15
15
|
end
|
@@ -18,12 +18,12 @@ module Nem
|
|
18
18
|
|
19
19
|
# @see https://nemproject.github.io/#transaction-data-with-decoded-messages
|
20
20
|
def transfers_outgoing(value, hash: nil, id: nil, page_size: nil)
|
21
|
-
|
21
|
+
page = {
|
22
22
|
value: value,
|
23
23
|
hash: hash,
|
24
|
-
id: id
|
25
|
-
|
26
|
-
) do |res|
|
24
|
+
id: id
|
25
|
+
}
|
26
|
+
request!(:post, '/local/account/transfers/outgoing', page) do |res|
|
27
27
|
res[:data].map do |tx|
|
28
28
|
Nem::Model::Transaction.new_from_account_transaction_meta_data_pair(tx)
|
29
29
|
end
|
@@ -32,12 +32,12 @@ module Nem
|
|
32
32
|
|
33
33
|
# @see https://nemproject.github.io/#transaction-data-with-decoded-messages
|
34
34
|
def transfers_all(value, hash: nil, id: nil, page_size: nil)
|
35
|
-
|
35
|
+
page = {
|
36
36
|
value: value,
|
37
37
|
hash: hash,
|
38
|
-
id: id
|
39
|
-
|
40
|
-
) do |res|
|
38
|
+
id: id
|
39
|
+
}
|
40
|
+
request!(:post, '/local/account/transfers/all', page) do |res|
|
41
41
|
res[:data].map do |tx|
|
42
42
|
Nem::Model::Transaction.new_from_account_transaction_meta_data_pair(tx)
|
43
43
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Nem
|
2
|
+
module Mixin
|
3
|
+
module MosaicAttachable
|
4
|
+
extend Forwardable
|
5
|
+
def_delegators :@mosaic_id, :fqn
|
6
|
+
def_delegators :@properties,
|
7
|
+
:divisibility,
|
8
|
+
:initial_supply,
|
9
|
+
:supply_mutable,
|
10
|
+
:transferable
|
11
|
+
|
12
|
+
attr_reader :mosaic_id, :quantity, :properties
|
13
|
+
|
14
|
+
def initialize(quantity)
|
15
|
+
mosaic_id = Nem::Model::MosaicId.new(
|
16
|
+
namespace_id: namespace_id,
|
17
|
+
name: name
|
18
|
+
)
|
19
|
+
properties = Nem::Model::MosaicProperties.new(
|
20
|
+
divisibility: divisibility,
|
21
|
+
initial_supply: initial_supply
|
22
|
+
)
|
23
|
+
@mosaic_id = mosaic_id
|
24
|
+
@properties = properties
|
25
|
+
@quantity = quantity
|
26
|
+
end
|
27
|
+
|
28
|
+
def amount
|
29
|
+
return quantity * (10**properties.divisibility)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.included(base)
|
33
|
+
base.send :prepend, self
|
34
|
+
|
35
|
+
base.class_eval do
|
36
|
+
def self.namespace_id(value)
|
37
|
+
define_method "#{__method__}" do
|
38
|
+
value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.name(value)
|
43
|
+
define_method "#{__method__}" do
|
44
|
+
value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.divisibility(value)
|
49
|
+
define_method "#{__method__}" do
|
50
|
+
value
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.initial_supply(value)
|
55
|
+
define_method "#{__method__}" do
|
56
|
+
value
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
File without changes
|
@@ -16,7 +16,7 @@ module Nem
|
|
16
16
|
# @param [String] fqn
|
17
17
|
# @return [Nem::Model::MosaicAttachment]
|
18
18
|
def find_by_fqn(fqn)
|
19
|
-
attachments.find {|a| a.fqn == fqn }
|
19
|
+
attachments.find { |a| a.fqn == fqn }
|
20
20
|
end
|
21
21
|
|
22
22
|
alias :[] :find_by_fqn
|
@@ -24,7 +24,7 @@ module Nem
|
|
24
24
|
# @param [String] namespace_id
|
25
25
|
# @return [Nem::Model::MosaicCollection]
|
26
26
|
def find_by_namespace_id(namespace_id)
|
27
|
-
self.class.new(attachments.select {|a| a.namespace_id == namespace_id })
|
27
|
+
self.class.new(attachments.select { |a| a.namespace_id == namespace_id })
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -3,6 +3,9 @@ module Nem
|
|
3
3
|
class Transaction
|
4
4
|
include Nem::Mixin::Assignable
|
5
5
|
|
6
|
+
extend Forwardable
|
7
|
+
def_delegators :@version, :version, :network
|
8
|
+
|
6
9
|
attr_reader :timestamp,
|
7
10
|
:version,
|
8
11
|
:type,
|
@@ -13,10 +16,6 @@ module Nem
|
|
13
16
|
:hash,
|
14
17
|
:height
|
15
18
|
|
16
|
-
def version?(num)
|
17
|
-
version & 0x00000003 == num ? true : false
|
18
|
-
end
|
19
|
-
|
20
19
|
def self.new_from_account_transaction(hash)
|
21
20
|
new_from_account_transaction_meta_data_pair(
|
22
21
|
meta: { data: nil },
|
@@ -44,12 +43,12 @@ module Nem
|
|
44
43
|
|
45
44
|
def self.common_part(hash)
|
46
45
|
{
|
47
|
-
timestamp: hash[:timeStamp],
|
48
|
-
|
49
|
-
type: hash[:type],
|
50
|
-
signer: hash[:signer],
|
46
|
+
timestamp: Nem::Unit::Time.new_from_nemtime(hash[:timeStamp]),
|
47
|
+
deadline: Nem::Unit::Time.new_from_nemtime(hash[:deadline]),
|
51
48
|
fee: hash[:fee],
|
52
|
-
|
49
|
+
type: hash[:type],
|
50
|
+
version: Nem::Unit::Version.new(hash[:version]),
|
51
|
+
signer: hash[:signer]
|
53
52
|
}
|
54
53
|
end
|
55
54
|
|
data/lib/nem/mosaic/dim_coin.rb
CHANGED
data/lib/nem/mosaic/dim_token.rb
CHANGED
data/lib/nem/mosaic/xem.rb
CHANGED
data/lib/nem/request/announce.rb
CHANGED
@@ -41,11 +41,13 @@ module Nem
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def prepare_multisig(tx)
|
44
|
+
timestamp = Nem::Unit::Time.new(tx.other_trans.timestamp)
|
45
|
+
deadline = Nem::Unit::Time.new(tx.other_trans.deadline)
|
44
46
|
other_trans = tx.other_trans.to_hash.merge(
|
45
47
|
type: tx.other_trans.type,
|
46
48
|
fee: tx.other_trans.fee.to_i,
|
47
|
-
timeStamp:
|
48
|
-
deadline:
|
49
|
+
timeStamp: timestamp.to_i,
|
50
|
+
deadline: deadline.to_i,
|
49
51
|
signer: tx.signer,
|
50
52
|
version: tx.other_trans.version
|
51
53
|
)
|
@@ -55,11 +57,13 @@ module Nem
|
|
55
57
|
end
|
56
58
|
|
57
59
|
def set_common(hash)
|
60
|
+
timestamp = Nem::Unit::Time.new(transaction.timestamp)
|
61
|
+
deadline = Nem::Unit::Time.new(transaction.deadline)
|
58
62
|
hash.merge(
|
59
63
|
type: transaction.type,
|
60
64
|
fee: transaction.fee.to_i,
|
61
|
-
timeStamp:
|
62
|
-
deadline:
|
65
|
+
timeStamp: timestamp.to_i,
|
66
|
+
deadline: deadline.to_i,
|
63
67
|
signer: keypair.public,
|
64
68
|
version: transaction.version
|
65
69
|
)
|
data/lib/nem/transaction/base.rb
CHANGED
@@ -7,9 +7,8 @@ module Nem
|
|
7
7
|
# @attr [String] signer
|
8
8
|
# @attr [String] signature
|
9
9
|
class Base
|
10
|
-
attr_reader :type, :fee,
|
11
|
-
:
|
12
|
-
# :version, :network
|
10
|
+
attr_reader :type, :fee, :timestamp, :deadline,
|
11
|
+
:signer, :signature
|
13
12
|
|
14
13
|
{
|
15
14
|
transfer: 0x0101,
|
@@ -11,13 +11,15 @@ module Nem
|
|
11
11
|
|
12
12
|
attr_reader :mode, :remote_account
|
13
13
|
|
14
|
-
def initialize(remote_account, mode, network: nil)
|
14
|
+
def initialize(remote_account, mode, timestamp: nil, deadline: nil, network: nil)
|
15
15
|
@remote_account = remote_account
|
16
16
|
@mode = mode
|
17
17
|
|
18
18
|
@network = network || Nem.default_network
|
19
19
|
@type = TYPE
|
20
20
|
@fee = Nem::Fee::ImportanceTransfer.new(self)
|
21
|
+
@timestamp = timestamp || Time.now
|
22
|
+
@deadline = deadline || Time.now + Nem.default_deadline
|
21
23
|
end
|
22
24
|
|
23
25
|
# attributes must be CAMEL CASE for NIS params
|
@@ -9,7 +9,7 @@ module Nem
|
|
9
9
|
|
10
10
|
attr_reader :mosaic_definition, :creation_fee, :creation_fee_sink
|
11
11
|
|
12
|
-
def initialize(mosaic_definition, network: nil)
|
12
|
+
def initialize(mosaic_definition, timestamp: nil, deadline: nil, network: nil)
|
13
13
|
@mosaic_definition = mosaic_definition
|
14
14
|
@creation_fee = creation[:fee]
|
15
15
|
@creation_fee_sink = creation[:sink]
|
@@ -17,6 +17,8 @@ module Nem
|
|
17
17
|
@network = network || Nem.default_network
|
18
18
|
@type = TYPE
|
19
19
|
@fee = Nem::Fee::MosaicDefinitionCreation.new(self)
|
20
|
+
@timestamp = timestamp || Time.now
|
21
|
+
@deadline = deadline || Time.now + Nem.default_deadline
|
20
22
|
end
|
21
23
|
|
22
24
|
# attributes must be CAMEL CASE for NIS params
|
@@ -12,7 +12,7 @@ module Nem
|
|
12
12
|
|
13
13
|
attr_accessor :mosaic_id, :supply_type, :delta
|
14
14
|
|
15
|
-
def initialize(mosaic_id, type, delta, network: nil)
|
15
|
+
def initialize(mosaic_id, type, delta, timestamp: nil, deadline: nil, network: nil)
|
16
16
|
@mosaic_id = mosaic_id
|
17
17
|
@supply_type = type
|
18
18
|
@delta = delta
|
@@ -20,6 +20,8 @@ module Nem
|
|
20
20
|
@network = network || Nem.default_network
|
21
21
|
@type = TYPE
|
22
22
|
@fee = Nem::Fee::MosaicSupplyChangeTransfer.new(self)
|
23
|
+
@timestamp = timestamp || Time.now
|
24
|
+
@deadline = deadline || Time.now + Nem.default_deadline
|
23
25
|
end
|
24
26
|
|
25
27
|
# attributes must be CAMEL CASE for NIS params
|
@@ -8,13 +8,15 @@ module Nem
|
|
8
8
|
|
9
9
|
attr_reader :other_trans, :signer
|
10
10
|
|
11
|
-
def initialize(trans, signer, network: nil)
|
11
|
+
def initialize(trans, signer, timestamp: nil, deadline: nil, network: nil)
|
12
12
|
@other_trans = trans
|
13
13
|
@signer = signer
|
14
14
|
|
15
15
|
@network = network || Nem.default_network
|
16
16
|
@type = TYPE
|
17
17
|
@fee = Nem::Fee::Multisig.new(self)
|
18
|
+
@timestamp = timestamp || Time.now
|
19
|
+
@deadline = deadline || Time.now + Nem.default_deadline
|
18
20
|
end
|
19
21
|
|
20
22
|
# attributes must be CAMEL CASE for NIS params
|
@@ -8,13 +8,15 @@ module Nem
|
|
8
8
|
|
9
9
|
attr_reader :modifications, :relative_change, :min_cosignatories
|
10
10
|
|
11
|
-
def initialize(modifications, relative_change, network: nil)
|
11
|
+
def initialize(modifications, relative_change, timestamp: nil, deadline: nil, network: nil)
|
12
12
|
@modifications = modifications
|
13
13
|
@relative_change = relative_change
|
14
14
|
|
15
15
|
@network = network || Nem.default_network
|
16
16
|
@type = TYPE
|
17
17
|
@fee = Nem::Fee::MultisigAggregateModification.new(self)
|
18
|
+
@timestamp = timestamp || Time.now
|
19
|
+
@deadline = deadline || Time.now + Nem.default_deadline
|
18
20
|
end
|
19
21
|
|
20
22
|
# attributes must be CAMEL CASE for NIS params
|
@@ -8,7 +8,7 @@ module Nem
|
|
8
8
|
|
9
9
|
attr_reader :other_hash, :other_account, :signer
|
10
10
|
|
11
|
-
def initialize(other_hash, other_account, signer, network: nil)
|
11
|
+
def initialize(other_hash, other_account, signer, timestamp: nil, deadline: nil, network: nil)
|
12
12
|
@other_hash = other_hash
|
13
13
|
@other_account = other_account
|
14
14
|
@signer = signer
|
@@ -16,6 +16,8 @@ module Nem
|
|
16
16
|
@network = network || Nem.default_network
|
17
17
|
@type = TYPE
|
18
18
|
@fee = Nem::Fee::Multisig.new(self)
|
19
|
+
@timestamp = timestamp || Time.now
|
20
|
+
@deadline = deadline || Time.now + Nem.default_deadline
|
19
21
|
end
|
20
22
|
|
21
23
|
# attributes must be CAMEL CASE for NIS params
|
@@ -9,7 +9,7 @@ module Nem
|
|
9
9
|
|
10
10
|
attr_reader :new_part, :parent, :rental_fee_sink, :rental_fee
|
11
11
|
|
12
|
-
def initialize(new_part, parent = nil, network: nil)
|
12
|
+
def initialize(new_part, parent = nil, timestamp: nil, deadline: nil, network: nil)
|
13
13
|
@new_part = new_part
|
14
14
|
@parent = parent
|
15
15
|
@rental_fee = rental[:fee]
|
@@ -18,6 +18,8 @@ module Nem
|
|
18
18
|
@network = network || Nem.default_network
|
19
19
|
@type = TYPE
|
20
20
|
@fee = Nem::Fee::ProvisionNamespace.new(self)
|
21
|
+
@timestamp = timestamp || Time.now
|
22
|
+
@deadline = deadline || Time.now + Nem.default_deadline
|
21
23
|
end
|
22
24
|
|
23
25
|
# @return [Boolean]
|
@@ -13,7 +13,7 @@ module Nem
|
|
13
13
|
|
14
14
|
attr_reader :amount, :recipient, :message, :mosaics
|
15
15
|
|
16
|
-
def initialize(recipient, amount, message = '', mosaics: [], network: nil)
|
16
|
+
def initialize(recipient, amount, message = '', mosaics: [], timestamp: nil, deadline: nil, network: nil)
|
17
17
|
@amount = amount
|
18
18
|
@recipient = recipient
|
19
19
|
@message = message.is_a?(Nem::Model::Message) ?
|
@@ -24,16 +24,18 @@ module Nem
|
|
24
24
|
@network = network || Nem.default_network
|
25
25
|
@type = TYPE
|
26
26
|
@fee = Nem::Fee::Transfer.new(self)
|
27
|
+
@timestamp = timestamp || Time.now
|
28
|
+
@deadline = deadline || Time.now + Nem.default_deadline
|
27
29
|
end
|
28
30
|
|
29
31
|
# @return [Boolean]
|
30
32
|
def has_message?
|
31
|
-
|
33
|
+
message.bytesize > 0
|
32
34
|
end
|
33
35
|
|
34
36
|
# @return [Boolean]
|
35
37
|
def has_mosaics?
|
36
|
-
|
38
|
+
mosaics.size > 0
|
37
39
|
end
|
38
40
|
|
39
41
|
def version
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Nem
|
2
|
+
module Unit
|
3
|
+
class Time
|
4
|
+
NEM_EPOCH = ::Time.utc(2015, 3, 29, 0, 6, 25, 0)
|
5
|
+
|
6
|
+
def initialize(value)
|
7
|
+
@value = value
|
8
|
+
end
|
9
|
+
|
10
|
+
def +(other)
|
11
|
+
self.class.new(@value + other)
|
12
|
+
end
|
13
|
+
|
14
|
+
def -(other)
|
15
|
+
self.class.new(@value - other)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_i
|
19
|
+
(@value - NEM_EPOCH).to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_time
|
23
|
+
@value.to_time
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.parse(datetime)
|
27
|
+
new(::Time.parse(datetime))
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.now
|
31
|
+
new(::Time.now.utc)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.new_from_nemtime(nemtime)
|
35
|
+
new(NEM_EPOCH + nemtime)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Nem
|
2
|
+
module Unit
|
3
|
+
# @attr [String] value
|
4
|
+
class Version
|
5
|
+
TESTNET = 0x98 << 24 # -1744830464
|
6
|
+
MAINNET = 0x68 << 24 # 1744830464
|
7
|
+
MIJIN = 0x60 << 24
|
8
|
+
|
9
|
+
MASK_VERSION = 0x00000003
|
10
|
+
MASK_NETWORK = 0xfffffffc
|
11
|
+
|
12
|
+
attr_accessor :value
|
13
|
+
|
14
|
+
def initialize(value)
|
15
|
+
@value = value
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [Integer]
|
19
|
+
def version
|
20
|
+
@version ||= value & MASK_VERSION
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Integer]
|
24
|
+
def network
|
25
|
+
@network ||= value & MASK_NETWORK
|
26
|
+
end
|
27
|
+
|
28
|
+
%w[testnet mainnet mijin].each do |k|
|
29
|
+
# @return [Boolean]
|
30
|
+
define_method("#{k}?") {
|
31
|
+
network == self.class.const_get(k.upcase) }
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [String]
|
35
|
+
def to_s
|
36
|
+
to_i.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
# @return [Integer]
|
40
|
+
def to_i
|
41
|
+
value.to_i
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Boolean]
|
45
|
+
def ==(other)
|
46
|
+
version == other
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/nem/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nem-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshiyuki Ieyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -234,6 +234,7 @@ files:
|
|
234
234
|
- examples/node_pool.rb
|
235
235
|
- examples/offline/announce_offline_transfer.rb
|
236
236
|
- examples/offline/create_offline_transfer.rb
|
237
|
+
- examples/offline/future_timestamp.rb
|
237
238
|
- examples/transaction/importance_transfer.rb
|
238
239
|
- examples/transaction/mosaic_definition_creation.rb
|
239
240
|
- examples/transaction/mosaic_supply_change.rb
|
@@ -277,7 +278,8 @@ files:
|
|
277
278
|
- lib/nem/keypair.rb
|
278
279
|
- lib/nem/mixin.rb
|
279
280
|
- lib/nem/mixin/assignable.rb
|
280
|
-
- lib/nem/mixin/
|
281
|
+
- lib/nem/mixin/mosaic_attachable.rb
|
282
|
+
- lib/nem/mixin/mosaic_definition.rb
|
281
283
|
- lib/nem/model.rb
|
282
284
|
- lib/nem/model/account.rb
|
283
285
|
- lib/nem/model/account_historical.rb
|
@@ -320,7 +322,7 @@ files:
|
|
320
322
|
- lib/nem/model/transfer_transaction.rb
|
321
323
|
- lib/nem/model/unlocked_info.rb
|
322
324
|
- lib/nem/mosaic.rb
|
323
|
-
- lib/nem/mosaic/
|
325
|
+
- lib/nem/mosaic/comsa_cms.rb
|
324
326
|
- lib/nem/mosaic/dim_coin.rb
|
325
327
|
- lib/nem/mosaic/dim_token.rb
|
326
328
|
- lib/nem/mosaic/ecobit_eco.rb
|
@@ -342,6 +344,8 @@ files:
|
|
342
344
|
- lib/nem/transaction/transfer.rb
|
343
345
|
- lib/nem/unit.rb
|
344
346
|
- lib/nem/unit/address.rb
|
347
|
+
- lib/nem/unit/time.rb
|
348
|
+
- lib/nem/unit/version.rb
|
345
349
|
- lib/nem/util.rb
|
346
350
|
- lib/nem/util/convert.rb
|
347
351
|
- lib/nem/util/deserializer.rb
|
data/lib/nem/mosaic/base.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module Nem
|
2
|
-
module Mosaic
|
3
|
-
class Base < Nem::Model::MosaicAttachment
|
4
|
-
extend Nem::Mixin::MosaicDefinition
|
5
|
-
|
6
|
-
def initialize(quantity)
|
7
|
-
mosaic_id = Nem::Model::MosaicId.new(
|
8
|
-
namespace_id: namespace_id,
|
9
|
-
name: name
|
10
|
-
)
|
11
|
-
properties = Nem::Model::MosaicProperties.new(
|
12
|
-
divisibility: divisibility,
|
13
|
-
initial_supply: initial_supply
|
14
|
-
)
|
15
|
-
super(
|
16
|
-
mosaic_id: mosaic_id,
|
17
|
-
properties: properties,
|
18
|
-
quantity: quantity
|
19
|
-
)
|
20
|
-
end
|
21
|
-
|
22
|
-
def namespace_id
|
23
|
-
raise NotImplementedError, "#{self.class}##{__method__} must be implemented."
|
24
|
-
end
|
25
|
-
|
26
|
-
def name
|
27
|
-
raise NotImplementedError, "#{self.class}##{__method__} must be implemented."
|
28
|
-
end
|
29
|
-
|
30
|
-
def divisibility
|
31
|
-
raise NotImplementedError, "#{self.class}##{__method__} must be implemented."
|
32
|
-
end
|
33
|
-
|
34
|
-
def initial_supply
|
35
|
-
raise NotImplementedError, "#{self.class}##{__method__} must be implemented."
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|