nis-ruby 0.0.11.1 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/LICENSE +21 -0
- data/README.md +23 -43
- data/{samples/request_account.rb → examples/account.rb} +2 -10
- data/{samples/request_block.rb → examples/block.rb} +0 -0
- data/{samples/request_debug.rb → examples/debug.rb} +0 -8
- data/{samples/request_local.rb → examples/local.rb} +0 -5
- data/{samples/request_namespace.rb → examples/namespace.rb} +0 -3
- data/{samples/request_nis.rb → examples/nis.rb} +0 -0
- data/{samples/request_node.rb → examples/node.rb} +0 -9
- data/examples/shutdown.rb +6 -0
- data/examples/transactions/importance_transfer.rb +22 -0
- data/examples/transactions/mosaic_definition_creation.rb +50 -0
- data/examples/transactions/mosaic_supply_change.rb +24 -0
- data/examples/transactions/multisig.rb +26 -0
- data/examples/transactions/multisig_add_cosignatory.rb +31 -0
- data/examples/transactions/multisig_aggregate_modification.rb +28 -0
- data/examples/transactions/multisig_signature.rb +38 -0
- data/examples/transactions/provision_namespace.rb +19 -0
- data/examples/transactions/transfer.rb +22 -0
- data/lib/nis.rb +8 -4
- data/lib/nis/client.rb +2 -1
- data/lib/nis/endpoint/shutdown.rb +7 -0
- data/lib/nis/endpoint/transaction/announce.rb +1 -1
- data/lib/nis/endpoint/transaction/prepareAnnounce.rb +1 -1
- data/lib/nis/fee.rb +1 -0
- data/lib/nis/fee/importance_transfer.rb +22 -0
- data/lib/nis/fee/mosaic_definition_creation.rb +22 -0
- data/lib/nis/fee/mosaic_supply_change_transfer.rb +22 -0
- data/lib/nis/fee/multisig.rb +22 -0
- data/lib/nis/fee/multisig_aggregation_modification.rb +30 -0
- data/lib/nis/fee/provision_namespace.rb +32 -0
- data/lib/nis/fee/transfer.rb +51 -0
- data/lib/nis/keypair.rb +18 -0
- data/lib/nis/mixin/struct.rb +50 -0
- data/lib/nis/request.rb +1 -0
- data/lib/nis/request/announce.rb +10 -0
- data/lib/nis/request/prepare_announce.rb +48 -0
- data/lib/nis/struct/block.rb +1 -1
- data/lib/nis/struct/mosaic_properties.rb +2 -2
- data/lib/nis/transaction/importance_transfer.rb +25 -28
- data/lib/nis/transaction/mosaic_definition_creation.rb +33 -34
- data/lib/nis/transaction/mosaic_supply_change.rb +30 -30
- data/lib/nis/transaction/multisig.rb +17 -36
- data/lib/nis/transaction/multisig_aggregate_modification.rb +29 -31
- data/lib/nis/transaction/multisig_signature.rb +24 -23
- data/lib/nis/transaction/provision_namespace.rb +53 -33
- data/lib/nis/transaction/transfer.rb +22 -52
- data/lib/nis/util.rb +16 -13
- data/lib/nis/version.rb +1 -1
- data/nis.gemspec +2 -0
- metadata +62 -19
- data/lib/nis/mixin/network.rb +0 -20
- data/samples/request_importance_transfer_transaction.rb +0 -34
- data/samples/request_mosaic_definition_creation_transaction.rb +0 -62
- data/samples/request_mosaic_supply_change_transaction.rb +0 -35
- data/samples/request_multisig_add_cosignatory_transaction.rb +0 -58
- data/samples/request_multisig_aggregate_modification_transaction.rb +0 -45
- data/samples/request_multisig_signature_transaction.rb +0 -53
- data/samples/request_multisig_transaction.rb +0 -54
- data/samples/request_provision_namespace_transaction.rb +0 -31
- data/samples/request_transfer_transaction.rb +0 -47
@@ -0,0 +1,50 @@
|
|
1
|
+
class Nis
|
2
|
+
module Mixin
|
3
|
+
module Struct
|
4
|
+
# @param [Symbol, String] attr Attribute name
|
5
|
+
# @return [Any] Attribute value
|
6
|
+
def [](attr)
|
7
|
+
send(attr)
|
8
|
+
end
|
9
|
+
|
10
|
+
# @return [Hash] Attribute and value pairs
|
11
|
+
def to_hash
|
12
|
+
hashed_properties = instance_variables.each_with_object({}) do |var, hash|
|
13
|
+
hash[var.to_s.delete('@').to_sym] = instance_variable_get(var)
|
14
|
+
end
|
15
|
+
hashnize(hashed_properties)
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [String] JSON formatted structure
|
19
|
+
def to_json(state = nil)
|
20
|
+
to_hash.to_json(state)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def hashnize(obj)
|
26
|
+
case true
|
27
|
+
when obj.class.to_s.start_with?('Nis::Fee')
|
28
|
+
obj.to_i
|
29
|
+
when obj.class.to_s.start_with?('Nis::Unit')
|
30
|
+
obj.to_s
|
31
|
+
when obj.class.to_s.start_with?('Nis::Transaction')
|
32
|
+
obj.to_hash
|
33
|
+
when obj.class.to_s.start_with?('Nis::Struct')
|
34
|
+
obj.to_hash
|
35
|
+
when obj.class.to_s.start_with?('Nis::Keypair')
|
36
|
+
obj.to_hash
|
37
|
+
when obj.is_a?(Array)
|
38
|
+
obj.map { |el| hashnize(el) }
|
39
|
+
when obj.is_a?(Hash)
|
40
|
+
obj.inject({}) do |hash, (k, v)|
|
41
|
+
hash[k] = hashnize(v)
|
42
|
+
hash
|
43
|
+
end
|
44
|
+
else
|
45
|
+
obj
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/nis/request.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.expand_path('../request/*.rb', __FILE__)].each { |f| require f }
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Nis::Request
|
2
|
+
# @attr [Nis::Struct::Transaction] transaction
|
3
|
+
# @attr [Nis::Keypair] keypair
|
4
|
+
# @see http://bob.nem.ninja/docs/#requestPrepareAnnounce
|
5
|
+
class PrepareAnnounce
|
6
|
+
include Nis::Mixin::Struct
|
7
|
+
|
8
|
+
attr_accessor :transaction, :keypair
|
9
|
+
|
10
|
+
DEADLINE = 3600
|
11
|
+
|
12
|
+
def initialize(transaction, keypair)
|
13
|
+
@keypair = keypair
|
14
|
+
@transaction = transaction
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_hash
|
18
|
+
if @transaction.respond_to?(:other_trans)
|
19
|
+
other_trans(@transaction)
|
20
|
+
end
|
21
|
+
|
22
|
+
@transaction.tap do |tx|
|
23
|
+
tx.timeStamp = Nis::Util.timestamp
|
24
|
+
tx.deadline = Nis::Util.deadline(DEADLINE)
|
25
|
+
tx.version = Nis::Util.parse_version(tx.network, 1)
|
26
|
+
tx.signer = @keypair.public
|
27
|
+
end
|
28
|
+
|
29
|
+
{ transaction: @transaction.to_hash,
|
30
|
+
privateKey: @keypair.private }
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def other_trans(transaction)
|
36
|
+
transaction.other_trans.tap do |tx|
|
37
|
+
tx.timeStamp = Nis::Util.timestamp
|
38
|
+
tx.deadline = Nis::Util.deadline(DEADLINE)
|
39
|
+
tx.version = Nis::Util.parse_version(tx.network, 1)
|
40
|
+
|
41
|
+
# tx.signer = @keypair.public
|
42
|
+
|
43
|
+
# multisig transfer
|
44
|
+
tx.signer = transaction.signer
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/nis/struct/block.rb
CHANGED
@@ -18,7 +18,7 @@ class Nis::Struct
|
|
18
18
|
alias :prev_block_hash= :prevBlockHash=
|
19
19
|
|
20
20
|
def self.build(attrs)
|
21
|
-
attrs[:transactions] = attrs[:transactions].map {|tx| Transaction.build(tx) }
|
21
|
+
attrs[:transactions] = attrs[:transactions].map { |tx| Transaction.build(tx) }
|
22
22
|
new(attrs)
|
23
23
|
end
|
24
24
|
end
|
@@ -36,10 +36,10 @@ class Nis::Struct
|
|
36
36
|
value: initial_supply.to_s
|
37
37
|
}, {
|
38
38
|
name: 'supplyMutable',
|
39
|
-
value: supply_mutable
|
39
|
+
value: supply_mutable.to_s
|
40
40
|
}, {
|
41
41
|
name: 'transferable',
|
42
|
-
value: transferable
|
42
|
+
value: transferable.to_s
|
43
43
|
}]
|
44
44
|
end
|
45
45
|
end
|
@@ -1,52 +1,49 @@
|
|
1
1
|
class Nis::Transaction
|
2
|
-
# @attr [Integer] timeStamp
|
3
|
-
# @attr [String] signature
|
4
|
-
# @attr [Integer] fee
|
5
|
-
# @attr [Integer] mode
|
6
2
|
# @attr [String] remoteAccount
|
3
|
+
# @attr [Integer] mode
|
7
4
|
# @attr [Integer] type
|
5
|
+
# @attr [Integer] fee
|
8
6
|
# @attr [Integer] deadline
|
7
|
+
# @attr [Integer] timeStamp
|
9
8
|
# @attr [Integer] version
|
10
|
-
# @attr [String]
|
9
|
+
# @attr [String] signer
|
10
|
+
# @attr [String] signature
|
11
|
+
# @attr [Symbol] network
|
11
12
|
# @see http://bob.nem.ninja/docs/#importanceTransferTransaction
|
12
13
|
class ImportanceTransfer
|
13
|
-
include Nis::Mixin::
|
14
|
-
attr_writer :version, :fee
|
14
|
+
include Nis::Mixin::Struct
|
15
15
|
|
16
|
-
|
17
|
-
attr_accessor :
|
16
|
+
attr_reader :type, :fee
|
17
|
+
attr_accessor :mode, :remoteAccount,
|
18
|
+
:deadline, :timeStamp, :version, :signer, :signature,
|
19
|
+
:network
|
18
20
|
|
19
|
-
alias timestamp timeStamp
|
20
|
-
alias timestamp= timeStamp=
|
21
21
|
alias remote_account remoteAccount
|
22
22
|
alias remote_account= remoteAccount=
|
23
|
+
alias timestamp timeStamp
|
23
24
|
|
24
25
|
TYPE = 0x0801 # 2049 (importance transfer transaction)
|
25
|
-
FEE = 6_000_000
|
26
26
|
|
27
27
|
ACTIVATE = 0x0001
|
28
28
|
DEACTIVATE = 0x0002
|
29
29
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
# @return [Integer]
|
35
|
-
def type
|
36
|
-
@type ||= TYPE
|
37
|
-
end
|
30
|
+
def initialize(remote_account, mode, network: :testnet)
|
31
|
+
@type = TYPE
|
32
|
+
@network = network
|
38
33
|
|
39
|
-
|
40
|
-
|
41
|
-
@fee
|
34
|
+
@remoteAccount = remote_account
|
35
|
+
@mode = parse_mode(mode)
|
36
|
+
@fee = Nis::Fee::ImportanceTransfer.new(self)
|
42
37
|
end
|
43
38
|
|
44
|
-
|
39
|
+
private
|
45
40
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
def parse_mode(mode)
|
42
|
+
case mode
|
43
|
+
when :activate then ACTIVATE
|
44
|
+
when :deactivate then DEACTIVATE
|
45
|
+
else raise "Not implemented mode: #{mode}"
|
46
|
+
end
|
50
47
|
end
|
51
48
|
end
|
52
49
|
end
|
@@ -1,55 +1,54 @@
|
|
1
1
|
class Nis::Transaction
|
2
|
-
# @attr [
|
3
|
-
# @attr [Integer]
|
4
|
-
# @attr [Integer]
|
2
|
+
# @attr [Nis::Struct::MosaicDefinition] mosaic_definition
|
3
|
+
# @attr [Integer] creationFee
|
4
|
+
# @attr [Integer] creationFeeSink
|
5
5
|
# @attr [Integer] type
|
6
|
+
# @attr [Integer] fee
|
6
7
|
# @attr [Integer] deadline
|
8
|
+
# @attr [Integer] timeStamp
|
7
9
|
# @attr [Integer] version
|
8
10
|
# @attr [String] signer
|
9
|
-
# @attr [
|
10
|
-
# @attr [
|
11
|
+
# @attr [String] signature
|
12
|
+
# @attr [Symbol] network
|
11
13
|
# @attr [Nis::Struct::MosaicDefinition] mosaicDefinition
|
12
14
|
# @see http://bob.nem.ninja/docs/#mosaicDefinitionCreationTransaction
|
13
15
|
class MosaicDefinitionCreation
|
14
|
-
include Nis::Mixin::
|
15
|
-
attr_writer :version, :fee
|
16
|
+
include Nis::Mixin::Struct
|
16
17
|
|
17
|
-
|
18
|
-
attr_accessor :
|
19
|
-
:
|
18
|
+
attr_reader :type, :fee
|
19
|
+
attr_accessor :mosaicDefinition, :creationFee, :creationFeeSink,
|
20
|
+
:deadline, :timeStamp, :version, :signer, :signature,
|
21
|
+
:network
|
20
22
|
|
21
|
-
alias timestamp timeStamp
|
22
|
-
alias timestamp= timeStamp=
|
23
|
-
alias creation_fee creationFee
|
24
|
-
alias creation_fee= creationFee=
|
25
|
-
alias creation_feeSink creationFeeSink
|
26
|
-
alias creation_feeSink= creationFeeSink=
|
27
23
|
alias mosaic_definition mosaicDefinition
|
28
24
|
alias mosaic_definition= mosaicDefinition=
|
25
|
+
alias creation_fee creationFee
|
26
|
+
alias creation_fee_sink creationFeeSink
|
27
|
+
alias timestamp timeStamp
|
29
28
|
|
30
29
|
TYPE = 0x4001 # 16385 (mosaic definition creation transaction)
|
31
|
-
FEE = 20_000_000
|
32
30
|
|
33
|
-
def
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
# @return [Integer]
|
38
|
-
def type
|
39
|
-
@type ||= TYPE
|
40
|
-
end
|
31
|
+
def initialize(mosaic_definition, network: :testnet)
|
32
|
+
@type = TYPE
|
33
|
+
@network = network
|
41
34
|
|
42
|
-
|
43
|
-
|
44
|
-
@
|
35
|
+
@mosaicDefinition = mosaic_definition
|
36
|
+
@creationFee = creation[:fee]
|
37
|
+
@creationFeeSink = creation[:sink]
|
38
|
+
@fee = Nis::Fee::MosaicDefinitionCreation.new(self)
|
45
39
|
end
|
46
40
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
41
|
+
private
|
42
|
+
|
43
|
+
# @see http://www.nem.ninja/docs/#mosaics
|
44
|
+
def creation
|
45
|
+
if @network == :testnet
|
46
|
+
{ sink: 'TBMOSAICOD4F54EE5CDMR23CCBGOAM2XSJBR5OLC',
|
47
|
+
fee: 20 * 1_000_000 }
|
48
|
+
else
|
49
|
+
{ sink: 'NBMOSAICOD4F54EE5CDMR23CCBGOAM2XSIUX6TRS',
|
50
|
+
fee: 500 * 1_000_000 }
|
51
|
+
end
|
53
52
|
end
|
54
53
|
end
|
55
54
|
end
|
@@ -1,53 +1,53 @@
|
|
1
1
|
class Nis::Transaction
|
2
|
-
# @attr [
|
3
|
-
# @attr [
|
2
|
+
# @attr [Nis::Struct::MosaicId] mosaic_id
|
3
|
+
# @attr [Symbol] supplyType
|
4
|
+
# @attr [Integer] delta
|
4
5
|
# @attr [Integer] fee
|
5
6
|
# @attr [Integer] type
|
6
7
|
# @attr [Integer] deadline
|
8
|
+
# @attr [Integer] timeStamp
|
7
9
|
# @attr [Integer] version
|
8
10
|
# @attr [String] signer
|
11
|
+
# @attr [String] signature
|
12
|
+
# @attr [Symbol] network
|
9
13
|
# @see http://bob.nem.ninja/docs/#mosaicSupplyChangeTransaction
|
10
14
|
class MosaicSupplyChange
|
11
|
-
include Nis::Mixin::
|
12
|
-
attr_writer :version, :fee
|
15
|
+
include Nis::Mixin::Struct
|
13
16
|
|
14
|
-
|
15
|
-
attr_accessor :
|
16
|
-
|
17
|
+
attr_reader :type, :fee
|
18
|
+
attr_accessor :mosaicId, :supplyType, :delta,
|
19
|
+
:deadline, :timeStamp, :version, :signer, :signature,
|
20
|
+
:network
|
17
21
|
|
18
|
-
alias timestamp timeStamp
|
19
|
-
alias timestamp= timeStamp=
|
20
|
-
alias supply_type supplyType
|
21
|
-
alias supply_type= supplyType=
|
22
22
|
alias mosaid_id mosaicId
|
23
23
|
alias mosaid_id= mosaicId=
|
24
|
+
alias supply_type supplyType
|
25
|
+
alias supply_type= supplyType=
|
26
|
+
alias timestamp timeStamp
|
24
27
|
|
25
28
|
TYPE = 0x4002 # 16386 (mosaic supply change transaction)
|
26
|
-
FEE = 20_000_000
|
27
29
|
|
28
|
-
INCREASE =
|
29
|
-
DECREASE =
|
30
|
+
INCREASE = 0x0001
|
31
|
+
DECREASE = 0x0002
|
30
32
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# @return [Integer]
|
36
|
-
def type
|
37
|
-
@type ||= TYPE
|
38
|
-
end
|
33
|
+
def initialize(mosaic_id, type, delta, network: :testnet)
|
34
|
+
@type = TYPE
|
35
|
+
@network = network
|
39
36
|
|
40
|
-
|
41
|
-
|
42
|
-
@
|
37
|
+
@mosaicId = mosaic_id
|
38
|
+
@supplyType = parse_type(type)
|
39
|
+
@delta = delta
|
40
|
+
@fee = Nis::Fee::MosaicSupplyChangeTransfer.new(self)
|
43
41
|
end
|
44
42
|
|
45
|
-
|
43
|
+
private
|
46
44
|
|
47
|
-
def
|
48
|
-
type
|
49
|
-
|
50
|
-
|
45
|
+
def parse_type(type)
|
46
|
+
case type
|
47
|
+
when :increase then INCREASE
|
48
|
+
when :descrease then DECREASE
|
49
|
+
else raise "Not implemented type: #{type}"
|
50
|
+
end
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -1,52 +1,33 @@
|
|
1
1
|
class Nis::Transaction
|
2
|
-
# @attr [
|
3
|
-
# @attr [
|
2
|
+
# @attr [Nis::Transaction::*] otherTrans
|
3
|
+
# @attr [String] signer
|
4
4
|
# @attr [Integer] type
|
5
|
+
# @attr [Integer] fee
|
5
6
|
# @attr [Integer] deadline
|
7
|
+
# @attr [Integer] timeStamp
|
6
8
|
# @attr [Integer] version
|
7
|
-
# @attr [String] signer
|
8
|
-
# @attr [Nis::Struct::TransferTransaction] otherTrans
|
9
9
|
# @see http://bob.nem.ninja/docs/#multisigTransaction
|
10
10
|
class Multisig
|
11
|
-
include Nis::Mixin::
|
12
|
-
attr_writer :version, :fee
|
11
|
+
include Nis::Mixin::Struct
|
13
12
|
|
14
|
-
|
15
|
-
attr_accessor :
|
16
|
-
|
13
|
+
attr_reader :type, :fee
|
14
|
+
attr_accessor :otherTrans, :signer,
|
15
|
+
:deadline, :timeStamp, :version,
|
16
|
+
:network
|
17
17
|
|
18
|
-
alias timestamp timeStamp
|
19
|
-
alias timestamp= timeStamp=
|
20
18
|
alias other_trans otherTrans
|
21
19
|
alias other_trans= otherTrans=
|
20
|
+
alias timestamp timeStamp
|
22
21
|
|
23
|
-
TYPE = 0x1004 #
|
24
|
-
FEE = 6_000_000
|
25
|
-
|
26
|
-
def self.build(attrs)
|
27
|
-
new(attrs)
|
28
|
-
end
|
29
|
-
|
30
|
-
# @return [Integer]
|
31
|
-
def type
|
32
|
-
@type ||= TYPE
|
33
|
-
end
|
34
|
-
|
35
|
-
# @return [Integer]
|
36
|
-
def fee
|
37
|
-
@fee ||= FEE
|
38
|
-
end
|
39
|
-
|
40
|
-
def mosaics
|
41
|
-
@mosaics ||= []
|
42
|
-
end
|
22
|
+
TYPE = 0x1004 # 4100 (multisig transaction)
|
43
23
|
|
44
|
-
|
24
|
+
def initialize(tx, signer, network: :testnet)
|
25
|
+
@type = TYPE
|
26
|
+
@network = network
|
45
27
|
|
46
|
-
|
47
|
-
|
48
|
-
fee
|
49
|
-
to_hash_old
|
28
|
+
@otherTrans = tx
|
29
|
+
@signer = signer
|
30
|
+
@fee = Nis::Fee::Multisig.new(self)
|
50
31
|
end
|
51
32
|
end
|
52
33
|
end
|