minter 0.0.3 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d075be7e9155a7dfd8a0ecd57b8ea46d4e6dd85527f9e1c2ab7144542a6bd3fc
4
- data.tar.gz: d1ab0b0a1c16cc7153f4e033609ada0ab3069e78c18572a53b9fda098b39c7a3
3
+ metadata.gz: e2d85833d44cf775519ae1b0df6bc8ccf534385bee66987f12faa99df0d29374
4
+ data.tar.gz: 7fc304397e7cc9079e81512ae722148c8f1d6397e23851d0098297ea5138e35b
5
5
  SHA512:
6
- metadata.gz: 5face07e9d58aa1e7ed849e2453a0cfc81626c0277848a7c5ea892400c09978f1af8e3b15d6284a7ef1992bbe6a86f87cf7aefa21cf3c72a3337ee9f799fda5b
7
- data.tar.gz: 9776d8a6e964dbb1fc4df8e44f395df35ee15986dd7dfb3bed529059ec7c8b9ecc335146d4b360e954d74a54a45709bf9b85afd0bf970962e9c252d325d4f2d6
6
+ metadata.gz: 35c26150780d7efc77481e8ce8647f4cbe2344ffbd84329c9e2a081fb467ff198c8466f4d315dcba062870553d76c8d94c73917036f9d31e2b8cf362fcf43ff4
7
+ data.tar.gz: a30987140a968126e241bf2dc8005d811e2ac71eda91685c49037b4250b19238549b69837af41c833faf258332bac057d5aaf75a612c06a58a960dad45e408da
data/README.md CHANGED
@@ -62,6 +62,7 @@ Or install it yourself as:
62
62
  - [Unbond](#unbond-transaction)
63
63
  - [Multisend](#multisend-transaction)
64
64
  - [EditCandidate](#edit-candidate-transaction)
65
+ - [CreateMultisigAddress](#create-multisig-address)
65
66
  - [Sign transaction](#sign-transaction)
66
67
  - [Single signature](#single-signature)
67
68
  - [Multi signature](#multi-signatures)
@@ -544,14 +545,31 @@ transaction = Minter::SendCoinTx.new(
544
545
  gas_price: 10
545
546
  )
546
547
 
547
- signed_tx = sign(private_key)
548
+ signed_tx = transaction.sign(private_key)
548
549
  signed_tx.tx_hash
549
550
  #=> "0xf88501020a8a4d4e540000000000000001abea8a4d4e540000000000000094e7812ab98ac5ac37e2ab20da3136ad91bb22d49789014d1120d7b1600000808001b845f8431ba07fde3c0e8d9ffb5fd7025099c9f3672deffab0b784787f5d45ea8f27b0ffe989a02f7cd63ac0d75e559f540d8b33464b11da4605e623d62a5b2ddce5adf70c35cb"
550
551
  ```
551
552
 
552
553
  #### Multi signatures
553
554
  ```ruby
554
- # IN PROGRESS
555
+ multisig_address = "Mxeda4bb5456f5eb8a19f57c8c6ec844d05feae879"
556
+ private_key1 = "4de029ca7b95c163f88c66e6351f2a986a48834b4681ec1e43eed5d120227103"
557
+ private_key2 = "49e48cd0f81e7aabfc840301c66f00318f50b25c79664c3f337d7ad4f919638e"
558
+ transaction = Minter::SendCoinTx.new(
559
+ address_to: "Mxe7812ab98ac5ac37e2ab20da3136ad91bb22d497",
560
+ value: 4_000_000_000_000_000_000,
561
+ coin: "MNT",
562
+ nonce: 2,
563
+ chain_id: 2,
564
+ gas_coin: "MNT",
565
+ gas_price: 10
566
+ )
567
+ signed_tx = transaction.multisign(multisig_address, private_key1, private_key2)
568
+ #=> #<Minter::SignedTx:0x00007fe340120090
569
+ # @transaction=
570
+ # #<Minter::SendCoinTx:0x00007fe3411da908 @address_to="Mxe7812ab98ac5ac37e2ab20da3136ad91bb22d497", @chain_id=2, @coin="MNT", @gas_coin="MNT", @gas_price=10, @nonce=2, @value=4000000000000000000>,
571
+ # @tx_hash=
572
+ # "0xf8e202020a8a4d4e540000000000000001aae98a4d4e540000000000000094e7812ab98ac5ac37e2ab20da3136ad91bb22d497883782dace9d900000808002b8a3f8a194eda4bb5456f5eb8a19f57c8c6ec844d05feae879f88af8431ba0287dd3956acae624abc25e6ba60018f60a80e144f5678ceb35c35613fcd363bfa01886706c7ffa0e6ccfc7c3dda186d3e8beea5214c30502ad9a24d8a29ced685af8431ba0302a560b420ed0da95f4f8425ac605a2462d35449e44557f152c4308845e1710a04cd1b834752e3a26b0fd543a20e3ef99ca233b049e064146c6a8cdf19d895552">
555
573
  ```
556
574
 
557
575
  ### Create transaction
@@ -822,22 +840,66 @@ Minter::EditCandidateTx.new(
822
840
  Transaction for creating multisignature address.
823
841
 
824
842
  ```ruby
825
- # IN PROGRESS
843
+ address1 = "Mx08d920c5d93dbf23038fe1a54bbb34f41f77677c"
844
+ address2 = "Mx9c7f68ff71b5819c41e8f87cc99bdf6359da3d75"
845
+ address3 = "Mx9c7f68ff71b5819c41e8f87cc99bdf6359da3d75"
846
+ private_key = "ae089b32e4e0976ca6888cb1023148bd1a9f1cc28c5d442e52e586754ff48d63"
847
+
848
+ transaction = Minter::CreateMultisigAddressTx.new(
849
+ threshold: 7,
850
+ nonce: 11,
851
+ chain_id: 2,
852
+ gas_coin: "MNT",
853
+ gas_price: 1
854
+ )
855
+
856
+ transaction.add_address(address: address1, weight: 1)
857
+ transaction.add_address(address: address2, weight: 3)
858
+ transaction.add_address(address: address3, weight: 5)
859
+
860
+ transaction.multisig_address
861
+ => "Mxc0edeaee8750330d01bcefcbd34198b2ef7b1167"
826
862
  ```
827
863
  #### Multisend transaction
828
864
 
829
865
  Transaction for sending coins to multiple addresses.
830
866
 
831
- ##### Example
832
-
833
867
  ```ruby
834
- # IN PROGRESS
868
+ transaction = Minter::MultiSendTx.new(
869
+ nonce: 1,
870
+ chain_id: 2,
871
+ gas_coin: "MNT",
872
+ gas_price: 1
873
+ )
874
+
875
+ transaction.add_item(
876
+ symbol: "MNT",
877
+ address_to: "Mxfe60014a6e9ac91618f5d1cab3fd58cded61ee99",
878
+ value: 100_000_000_000_000_000
879
+ )
880
+
881
+ transaction.add_item(
882
+ symbol: "MNT",
883
+ address_to: "Mxddab6281766ad86497741ff91b6b48fe85012e3c",
884
+ value: 200_000_000_000_000_000
885
+ )
835
886
  ```
836
887
  ### Get fee of transaction
837
888
  ```ruby
838
- # IN PROGRESS
839
- ```
889
+ transaction = Minter::SendCoinTx.new(
890
+ address_to: "Mxe7812ab98ac5ac37e2ab20da3136ad91bb22d497",
891
+ value: 24_000_000_000_000_000_000,
892
+ coin: "MNT",
893
+ nonce: 65,
894
+ chain_id: 2,
895
+ gas_coin: "MNT",
896
+ gas_price: 10
897
+ )
898
+
899
+ transaction.fee
900
+ #=> ""
840
901
 
902
+ ```
841
903
  ### Decode Transaction
842
904
 
843
905
  ```ruby
@@ -895,6 +957,16 @@ wallet = Minter::Wallet.new
895
957
  # "Mp961589ae817659c6bb323587faa9a92a91b5e8481dd3b73ad0dc680464dac5adbc2d498064598bc36e158436fb1861245ef909a1776e5cb50221db718c82a483">
896
958
  ```
897
959
 
960
+ #### Build wallet from mnemonic
961
+ ```ruby
962
+ mnemonic = "hurt orient quarter item can into zebra west either ship team pattern"
963
+ wallet = Minter::Wallet.new(mnemonic)
964
+ => #<Minter::Wallet:0x00007fb7019cdaf0
965
+ @address="Mx3f865a277ef9e901280d0e607294be9a654860ea",
966
+ @mnemonic="hurt orient quarter item can into zebra west either ship team pattern",
967
+ @private_key="0ce363580a20351d995dbafc8942f61c0094f38d0d4f837d1f0c37a9f3c3c7ca",
968
+ @public_key="Mp7084eec27577ffd4151b54bf7d8ed500a514629fea4e5992bb94a704011d89225be0543fd0a27069b7855c0d260aa21011380843d03d18aabc2bb1e4d4c80e15">
969
+ ```
898
970
 
899
971
  ### Minter Key
900
972
  #### Generate mnemonic.
@@ -1,9 +1,11 @@
1
- out_path = './goext'
1
+ # frozen_string_literal: true
2
+
3
+ out_path = "./sign"
2
4
  arg_string = ""
3
5
  {
4
6
  out: out_path,
5
- targets: ['linux/amd64', 'darwin/amd64'],
6
- buildmode: 'c-shared',
7
+ targets: ["linux/amd64", "darwin/amd64"],
8
+ buildmode: "c-shared"
7
9
  }.each_pair do |name, args|
8
10
  arg_string += "-#{name}"
9
11
  arg_string += "=#{[args].flatten.join(',')}" unless args.nil?
@@ -11,4 +13,4 @@ arg_string = ""
11
13
  end
12
14
 
13
15
  puts "xgo #{arg_string.strip} ./"
14
- system("xgo #{arg_string.strip} ./")
16
+ system("xgo #{arg_string.strip} ./")
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ffi"
4
+ module Minter
5
+ module SignFfi
6
+ extend FFI::Library
7
+ filename = RUBY_PLATFORM.match("darwin") ? "/sign-darwin-10.6-amd64.dylib" : "/sign-linux-amd64.so"
8
+ ffi_lib File.join(File.dirname(__FILE__), filename)
9
+ attach_function :Sign, [:string], :string
10
+ attach_function :MultiSign, [:string], :string
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ out_path = "./tx-hash"
4
+ arg_string = ""
5
+ {
6
+ out: out_path,
7
+ targets: ["linux/amd64", "darwin/amd64"],
8
+ buildmode: "c-shared"
9
+ }.each_pair do |name, args|
10
+ arg_string += "-#{name}"
11
+ arg_string += "=#{[args].flatten.join(',')}" unless args.nil?
12
+ arg_string += " "
13
+ end
14
+
15
+ puts "xgo #{arg_string.strip} ./"
16
+ system("xgo #{arg_string.strip} ./")
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ffi"
4
+ module Minter
5
+ module TxHashFfi
6
+ extend FFI::Library
7
+ filename = RUBY_PLATFORM.match("darwin") ? "/tx-hash-darwin-10.6-amd64.dylib" : "/tx-hash-linux-amd64.so"
8
+ ffi_lib File.join(File.dirname(__FILE__), filename)
9
+ attach_function :BuyCoinTx, [:string], :string
10
+ attach_function :CreateCoinTx, [:string], :string
11
+ attach_function :CreateMultisigAddressTx, [:string], :string
12
+ attach_function :GetMultisigAddress, [:string], :string
13
+ attach_function :DeclareCandidacyTx, [:string], :string
14
+ attach_function :DelegateTx, [:string], :string
15
+ attach_function :EditCandidateTx, [:string], :string
16
+ attach_function :MultiSendTx, [:string], :string
17
+ attach_function :RedeemCheckTx, [:string], :string
18
+ attach_function :SellAllCoinTx, [:string], :string
19
+ attach_function :SellCoinTx, [:string], :string
20
+ attach_function :SendCoinTx, [:string], :string
21
+ attach_function :SetCandidateOffTx, [:string], :string
22
+ attach_function :SetCandidateOnTx, [:string], :string
23
+ attach_function :UnbondTx, [:string], :string
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ out_path = "./wallet"
4
+ arg_string = ""
5
+ {
6
+ out: out_path,
7
+ targets: ["linux/amd64", "darwin/amd64"],
8
+ buildmode: "c-shared"
9
+ }.each_pair do |name, args|
10
+ arg_string += "-#{name}"
11
+ arg_string += "=#{[args].flatten.join(',')}" unless args.nil?
12
+ arg_string += " "
13
+ end
14
+
15
+ puts "xgo #{arg_string.strip} ./"
16
+ system("xgo #{arg_string.strip} ./")
@@ -4,7 +4,7 @@ require "ffi"
4
4
  module Minter
5
5
  module WalletFfi
6
6
  extend FFI::Library
7
- filename = RUBY_PLATFORM.match('darwin') ? "/wallet-darwin-10.6-amd64.dylib" : "/wallet-linux-amd64.so"
7
+ filename = RUBY_PLATFORM.match("darwin") ? "/wallet-darwin-10.6-amd64.dylib" : "/wallet-linux-amd64.so"
8
8
  ffi_lib File.join(File.dirname(__FILE__), filename)
9
9
  attach_function :NewMnemonic, [], :string
10
10
  attach_function :PrivateKeyFromMnemonic, [:string], :string
@@ -6,8 +6,10 @@ require "minter/api/client"
6
6
  require "minter/version"
7
7
  require "minter/wallet.rb"
8
8
  require "minter/key.rb"
9
- require "ffi/wallet_ffi.rb"
10
- require "ffi/transaction_ffi.rb"
9
+ require "ffi/wallet/wallet_ffi.rb"
10
+ require "ffi/tx_hash/tx_hash_ffi.rb"
11
+ require "ffi/sign/sign_ffi.rb"
12
+ require "minter/transactions/transaction.rb"
11
13
  Dir[File.dirname(__FILE__) + "/minter/transactions/*.rb"].each { |file| require_relative file }
12
14
 
13
15
  module Minter
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class BuyCoinTx
4
+ class BuyCoinTx < Transaction
5
5
  attr_accessor :coin_to_buy, :value_to_buy, :coin_to_sell, :maximum_value_to_sell, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(coin_to_buy:, value_to_buy:, coin_to_sell:, maximum_value_to_sell:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
@@ -15,13 +15,6 @@ module Minter
15
15
  @gas_price = gas_price
16
16
  end
17
17
 
18
- def sign(private_key)
19
- params = to_params
20
- params[:PrivateKey] = private_key
21
- tx_hash = Minter::TransactionFfi.SignBuyCoinTransaction(params.to_json)
22
- SignedTx.new(tx_hash)
23
- end
24
-
25
18
  def to_params
26
19
  { CoinToBuy: coin_to_buy,
27
20
  ValueToBuy: value_to_buy,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class CreateCoinTx
4
+ class CreateCoinTx < Transaction
5
5
  attr_accessor :name, :symbol, :initial_amount, :max_supply, :initial_reserve, :reserve_ratio, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(name:, symbol:, initial_amount:, max_supply:, initial_reserve:, reserve_ratio:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
@@ -17,13 +17,6 @@ module Minter
17
17
  @gas_price = gas_price
18
18
  end
19
19
 
20
- def sign(private_key)
21
- params = to_params
22
- params[:PrivateKey] = private_key
23
- tx_hash = Minter::TransactionFfi.SignCreateCoinTransaction(params.to_json)
24
- SignedTx.new(tx_hash)
25
- end
26
-
27
20
  def to_params
28
21
  { Name: name,
29
22
  Symbol: symbol,
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minter
4
+ class CreateMultisigAddressTx < Transaction
5
+ attr_accessor :addresses, :threshold, :nonce, :chain_id, :gas_coin, :gas_price
6
+
7
+ def initialize(threshold:, nonce:, chain_id:, gas_coin:, gas_price:)
8
+ @threshold = threshold
9
+ @nonce = nonce
10
+ @chain_id = chain_id
11
+ @gas_coin = gas_coin
12
+ @gas_price = gas_price
13
+ @addresses = []
14
+ end
15
+
16
+ def add_address(address:, weight:)
17
+ @addresses << { Address: address, Weight: weight }
18
+ end
19
+
20
+ def to_params
21
+ {
22
+ Threshold: threshold,
23
+ Nonce: nonce,
24
+ ChainId: chain_id,
25
+ GasCoin: gas_coin,
26
+ GasPrice: gas_price,
27
+ Addresses: addresses
28
+ }
29
+ end
30
+
31
+ def multisig_address
32
+ result = JSON.parse(Minter::TxHashFfi.GetMultisigAddress(to_params.to_json))
33
+ raise TransactionError, result["error"] unless result["success"] == "true"
34
+
35
+ result["multisig_address"]
36
+ end
37
+ end
38
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class DeclareCandidacyTx
4
+ class DeclareCandidacyTx < Transaction
5
5
  attr_accessor :address, :pubkey, :commission, :coin, :stake, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(address:, pubkey:, commission:, coin:, stake:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
@@ -16,13 +16,6 @@ module Minter
16
16
  @gas_price = gas_price
17
17
  end
18
18
 
19
- def sign(private_key)
20
- params = to_params
21
- params[:PrivateKey] = private_key
22
- tx_hash = Minter::TransactionFfi.SignDeclareCandidacyTransaction(params.to_json)
23
- SignedTx.new(tx_hash)
24
- end
25
-
26
19
  def to_params
27
20
  { Address: address,
28
21
  PubKey: pubkey,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class DelegateTx
4
+ class DelegateTx < Transaction
5
5
  attr_accessor :pubkey, :coin, :value, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(pubkey:, coin:, value:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
@@ -14,13 +14,6 @@ module Minter
14
14
  @gas_price = gas_price
15
15
  end
16
16
 
17
- def sign(private_key)
18
- params = to_params
19
- params[:PrivateKey] = private_key
20
- tx_hash = Minter::TransactionFfi.SignDelegateTransaction(params.to_json)
21
- SignedTx.new(tx_hash)
22
- end
23
-
24
17
  def to_params
25
18
  { PubKey: pubkey,
26
19
  Coin: coin,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class EditCandidateTx
4
+ class EditCandidateTx < Transaction
5
5
  attr_accessor :pubkey, :reward_address, :owner_address, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(pubkey:, reward_address:, owner_address:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
@@ -14,13 +14,6 @@ module Minter
14
14
  @gas_price = gas_price
15
15
  end
16
16
 
17
- def sign(private_key)
18
- params = to_params
19
- params[:PrivateKey] = private_key
20
- tx_hash = Minter::TransactionFfi.SignEditCandidateTransaction(params.to_json)
21
- SignedTx.new(tx_hash)
22
- end
23
-
24
17
  def to_params
25
18
  { PubKey: pubkey,
26
19
  RewardAddress: reward_address,
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minter
4
+ class MultiSendTx < Transaction
5
+ attr_accessor :items, :coin, :nonce, :chain_id, :gas_coin, :gas_price
6
+
7
+ def initialize(nonce:, chain_id:, gas_coin:, gas_price:)
8
+ @nonce = nonce
9
+ @chain_id = chain_id
10
+ @gas_coin = gas_coin
11
+ @gas_price = gas_price
12
+ @items = []
13
+ end
14
+
15
+ def add_item(symbol:, value:, address_to:)
16
+ @items << { Symbol: symbol, Value: value, AddressTo: address_to }
17
+ end
18
+
19
+ def to_params
20
+ {
21
+ Nonce: nonce,
22
+ ChainId: chain_id,
23
+ GasCoin: gas_coin,
24
+ GasPrice: gas_price,
25
+ Items: items
26
+ }
27
+ end
28
+ end
29
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class RedeemCheckTx
4
+ class RedeemCheckTx < Transaction
5
5
  attr_accessor :check, :proof, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(check:, proof:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
@@ -13,13 +13,6 @@ module Minter
13
13
  @gas_price = gas_price
14
14
  end
15
15
 
16
- def sign(private_key)
17
- params = to_params
18
- params[:PrivateKey] = private_key
19
- tx_hash = Minter::TransactionFfi.SignRedeemCheckTransaction(params.to_json)
20
- SignedTx.new(tx_hash)
21
- end
22
-
23
16
  def to_params
24
17
  { Check: check,
25
18
  Proof: proof,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class SellAllCoinTx
4
+ class SellAllCoinTx < Transaction
5
5
  attr_accessor :coin_to_sell, :coin_to_buy, :minimum_value_to_buy, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(coin_to_sell:, coin_to_buy:, minimum_value_to_buy:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
@@ -14,13 +14,6 @@ module Minter
14
14
  @gas_price = gas_price
15
15
  end
16
16
 
17
- def sign(private_key)
18
- params = to_params
19
- params[:PrivateKey] = private_key
20
- tx_hash = Minter::TransactionFfi.SignSellAllCoinTransaction(params.to_json)
21
- SignedTx.new(tx_hash)
22
- end
23
-
24
17
  def to_params
25
18
  { CoinToSell: coin_to_sell,
26
19
  CoinToBuy: coin_to_buy,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class SellCoinTx
4
+ class SellCoinTx < Transaction
5
5
  attr_accessor :coin_to_sell, :value_to_sell, :coin_to_buy, :minimum_value_to_buy, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(coin_to_sell:, value_to_sell:, coin_to_buy:, minimum_value_to_buy:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
@@ -15,13 +15,6 @@ module Minter
15
15
  @gas_price = gas_price
16
16
  end
17
17
 
18
- def sign(private_key)
19
- params = to_params
20
- params[:PrivateKey] = private_key
21
- tx_hash = Minter::TransactionFfi.SignSellCoinTransaction(params.to_json)
22
- SignedTx.new(tx_hash)
23
- end
24
-
25
18
  def to_params
26
19
  { CoinToSell: coin_to_sell,
27
20
  ValueToSell: value_to_sell,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class SendCoinTx
4
+ class SendCoinTx < Transaction
5
5
  attr_accessor :type, :address_to, :value, :coin, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(address_to:, value:, coin:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
@@ -14,13 +14,6 @@ module Minter
14
14
  @gas_price = gas_price
15
15
  end
16
16
 
17
- def sign(private_key)
18
- params = to_params
19
- params[:PrivateKey] = private_key
20
- tx_hash = Minter::TransactionFfi.SignTransaction(params.to_json)
21
- SignedTx.new(tx_hash)
22
- end
23
-
24
17
  def to_params
25
18
  { AddressTo: address_to,
26
19
  Value: value,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class SetCandidateOffTx
4
+ class SetCandidateOffTx < Transaction
5
5
  attr_accessor :pubkey, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(pubkey:, nonce:, chain_id:, gas_coin:, gas_price:)
@@ -12,13 +12,6 @@ module Minter
12
12
  @gas_price = gas_price
13
13
  end
14
14
 
15
- def sign(private_key)
16
- params = to_params
17
- params[:PrivateKey] = private_key
18
- tx_hash = Minter::TransactionFfi.SignSetCandidateOffTransaction(params.to_json)
19
- SignedTx.new(tx_hash)
20
- end
21
-
22
15
  def to_params
23
16
  { PubKey: pubkey,
24
17
  Nonce: nonce,
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class SetCandidateOnTx
4
+ class SetCandidateOnTx < Transaction
5
5
  attr_accessor :pubkey, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(pubkey:, nonce:, chain_id:, gas_coin:, gas_price:)
@@ -12,13 +12,6 @@ module Minter
12
12
  @gas_price = gas_price
13
13
  end
14
14
 
15
- def sign(private_key)
16
- params = to_params
17
- params[:PrivateKey] = private_key
18
- tx_hash = Minter::TransactionFfi.SignSetCandidateOnTransaction(params.to_json)
19
- SignedTx.new(tx_hash)
20
- end
21
-
22
15
  def to_params
23
16
  { PubKey: pubkey,
24
17
  Nonce: nonce,
@@ -2,14 +2,14 @@
2
2
 
3
3
  module Minter
4
4
  class SignedTx
5
- attr_reader :tx_hash
5
+ attr_reader :tx_hash, :transaction
6
6
 
7
- def initialize(tx_hash)
7
+ def initialize(tx_hash: nil, transaction: nil)
8
8
  @tx_hash = tx_hash
9
+ @transaction = transaction
9
10
  end
10
11
 
11
12
  def send
12
- # TODO: maybe create client one time
13
13
  Minter::Api::Client.new.send_transaction(transaction: tx_hash)
14
14
  end
15
15
  end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Minter
4
+ class TransactionError < StandardError; end
5
+ class SignError < StandardError; end
6
+
7
+ class Transaction
8
+ def sign(private_key)
9
+ sign_params = {}
10
+ sign_params[:PrivateKey] = private_key
11
+ sign_params[:TxHash] = tx_hash
12
+
13
+ result = JSON.parse(Minter::SignFfi.Sign(sign_params.to_json))
14
+ raise SignError, result["error"] unless result["success"] == "true"
15
+
16
+ SignedTx.new(tx_hash: result["tx_hash"], transaction: self)
17
+ end
18
+
19
+ def multisign(multisig_address, *private_keys)
20
+ multisign_params = {}
21
+ multisign_params[:PrivateKeys] = private_keys
22
+ multisign_params[:TxHash] = tx_hash(multisign: true)
23
+ multisign_params[:MultiSigAddress] = multisig_address
24
+
25
+ result = JSON.parse(Minter::SignFfi.MultiSign(multisign_params.to_json))
26
+ raise SignError, result["error"] unless result["success"] == "true"
27
+
28
+ SignedTx.new(tx_hash: result["tx_hash"], transaction: self)
29
+ end
30
+
31
+ def tx_hash(multisign: false)
32
+ transaction_params = to_params
33
+ transaction_params[:SignatureType] = multisign ? 2 : 1
34
+
35
+ result = JSON.parse(Minter::TxHashFfi.send(self.class.to_s.split("::")[1], transaction_params.to_json))
36
+ raise TransactionError, result["error"] unless result["success"] == "true"
37
+
38
+ result["tx_hash"]
39
+ end
40
+ end
41
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- class UnbondTx
4
+ class UnbondTx < Transaction
5
5
  attr_accessor :pubkey, :coin, :value, :nonce, :chain_id, :gas_coin, :gas_price
6
6
 
7
7
  def initialize(pubkey:, coin:, value:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
@@ -14,13 +14,6 @@ module Minter
14
14
  @gas_price = gas_price
15
15
  end
16
16
 
17
- def sign(private_key)
18
- params = to_params
19
- params[:PrivateKey] = private_key
20
- tx_hash = Minter::TransactionFfi.SignUnbondTransaction(params.to_json)
21
- SignedTx.new(tx_hash)
22
- end
23
-
24
17
  def to_params
25
18
  { PubKey: pubkey,
26
19
  Coin: coin,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Minter
4
- VERSION = "0.0.3"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -3,8 +3,9 @@
3
3
  module Minter
4
4
  class Wallet
5
5
  attr_reader :seed, :private_key, :public_key, :mnemonic, :address
6
- def initialize(_options = {})
7
- @mnemonic = Minter::WalletFfi.NewMnemonic
6
+ def initialize(mnemonic = nil)
7
+ @mnemonic = mnemonic
8
+ @mnemonic ||= Minter::WalletFfi.NewMnemonic
8
9
  @private_key = Minter::WalletFfi.PrivateKeyFromMnemonic(@mnemonic)
9
10
  @public_key = Minter::WalletFfi.PublicKeyFromPrivateKey(@private_key)
10
11
  @address = Minter::WalletFfi.AddressFromMnemonic(@mnemonic)
metadata CHANGED
@@ -1,99 +1,135 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Nikolaev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-18 00:00:00.000000000 Z
11
+ date: 2020-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.7'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
- version: '0'
22
+ version: 2.7.5
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.7'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: '0'
32
+ version: 2.7.5
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: ffi
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.12'
31
40
  - - ">="
32
41
  - !ruby/object:Gem::Version
33
- version: '0'
42
+ version: 1.12.2
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.12'
38
50
  - - ">="
39
51
  - !ruby/object:Gem::Version
40
- version: '0'
52
+ version: 1.12.2
41
53
  - !ruby/object:Gem::Dependency
42
54
  name: http
43
55
  requirement: !ruby/object:Gem::Requirement
44
56
  requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '4.4'
45
60
  - - ">="
46
61
  - !ruby/object:Gem::Version
47
- version: '0'
62
+ version: 4.4.1
48
63
  type: :runtime
49
64
  prerelease: false
50
65
  version_requirements: !ruby/object:Gem::Requirement
51
66
  requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '4.4'
52
70
  - - ">="
53
71
  - !ruby/object:Gem::Version
54
- version: '0'
72
+ version: 4.4.1
55
73
  - !ruby/object:Gem::Dependency
56
74
  name: json
57
75
  requirement: !ruby/object:Gem::Requirement
58
76
  requirements:
59
77
  - - ">="
60
78
  - !ruby/object:Gem::Version
61
- version: '0'
79
+ version: 2.3.0
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.3'
62
83
  type: :runtime
63
84
  prerelease: false
64
85
  version_requirements: !ruby/object:Gem::Requirement
65
86
  requirements:
66
87
  - - ">="
67
88
  - !ruby/object:Gem::Version
68
- version: '0'
89
+ version: 2.3.0
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '2.3'
69
93
  - !ruby/object:Gem::Dependency
70
94
  name: rake
71
95
  requirement: !ruby/object:Gem::Requirement
72
96
  requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '12.3'
73
100
  - - ">="
74
101
  - !ruby/object:Gem::Version
75
- version: '0'
102
+ version: 12.3.3
76
103
  type: :runtime
77
104
  prerelease: false
78
105
  version_requirements: !ruby/object:Gem::Requirement
79
106
  requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '12.3'
80
110
  - - ">="
81
111
  - !ruby/object:Gem::Version
82
- version: '0'
112
+ version: 12.3.3
83
113
  - !ruby/object:Gem::Dependency
84
114
  name: rspec
85
115
  requirement: !ruby/object:Gem::Requirement
86
116
  requirements:
87
117
  - - ">="
88
118
  - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :runtime
119
+ version: 3.9.0
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '3.9'
123
+ type: :development
91
124
  prerelease: false
92
125
  version_requirements: !ruby/object:Gem::Requirement
93
126
  requirements:
94
127
  - - ">="
95
128
  - !ruby/object:Gem::Version
96
- version: '0'
129
+ version: 3.9.0
130
+ - - "~>"
131
+ - !ruby/object:Gem::Version
132
+ version: '3.9'
97
133
  description: This is a Ruby SDK based on Golang SDK for working with Minter blockchain
98
134
  email:
99
135
  executables: []
@@ -105,9 +141,12 @@ files:
105
141
  - README.md
106
142
  - bin/console
107
143
  - bin/setup
108
- - lib/ffi/go/compile.rb
109
- - lib/ffi/transaction_ffi.rb
110
- - lib/ffi/wallet_ffi.rb
144
+ - lib/ffi/sign/compile.rb
145
+ - lib/ffi/sign/sign_ffi.rb
146
+ - lib/ffi/tx_hash/compile.rb
147
+ - lib/ffi/tx_hash/tx_hash_ffi.rb
148
+ - lib/ffi/wallet/compile.rb
149
+ - lib/ffi/wallet/wallet_ffi.rb
111
150
  - lib/minter.rb
112
151
  - lib/minter/api/client.rb
113
152
  - lib/minter/api/connection.rb
@@ -130,9 +169,11 @@ files:
130
169
  - lib/minter/key.rb
131
170
  - lib/minter/transactions/buy_coin_tx.rb
132
171
  - lib/minter/transactions/create_coin_tx.rb
172
+ - lib/minter/transactions/create_multisig_address_tx.rb
133
173
  - lib/minter/transactions/declare_candidacy_tx.rb
134
174
  - lib/minter/transactions/delegate_tx.rb
135
175
  - lib/minter/transactions/edit_candidate_tx.rb
176
+ - lib/minter/transactions/multi_send_tx.rb
136
177
  - lib/minter/transactions/redeem_check_tx.rb
137
178
  - lib/minter/transactions/sell_all_coin_tx.rb
138
179
  - lib/minter/transactions/sell_coin_tx.rb
@@ -140,6 +181,7 @@ files:
140
181
  - lib/minter/transactions/set_candidate_off_tx.rb
141
182
  - lib/minter/transactions/set_candidate_on_tx.rb
142
183
  - lib/minter/transactions/signed_tx.rb
184
+ - lib/minter/transactions/transaction.rb
143
185
  - lib/minter/transactions/unbond_tx.rb
144
186
  - lib/minter/version.rb
145
187
  - lib/minter/wallet.rb
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "ffi"
4
- module Minter
5
- module TransactionFfi
6
- extend FFI::Library
7
- filename = RUBY_PLATFORM.match('darwin') ? "/transaction-darwin-10.6-amd64.dylib" : "/transaction-linux-amd64.so"
8
- ffi_lib File.join(File.dirname(__FILE__), filename)
9
- attach_function :SignTransaction, [:string], :string
10
- attach_function :TransactionHash, [:string], :string
11
- attach_function :DecodeTransaction, [:string], :string
12
- attach_function :SignCreateCoinTransaction, [:string], :string
13
- attach_function :SignSellCoinTransaction, [:string], :string
14
- attach_function :SignBuyCoinTransaction, [:string], :string
15
- attach_function :SignSellAllCoinTransaction, [:string], :string
16
- attach_function :SignDeclareCandidacyTransaction, [:string], :string
17
- attach_function :SignDelegateTransaction, [:string], :string
18
- attach_function :SignUnbondTransaction, [:string], :string
19
- attach_function :SignSetCandidateOffTransaction, [:string], :string
20
- attach_function :SignSetCandidateOnTransaction, [:string], :string
21
- attach_function :SignRedeemCheckTransaction, [:string], :string
22
- attach_function :SignEditCandidateTransaction, [:string], :string
23
- # attach_function :SignMultisendTransaction, [:string], :string
24
- end
25
- end
26
-
27
- # Examples of USAGE FFI
28
- # ===SEND MNT===
29
- # tx_params = {
30
- # Nonce: 27,
31
- # ChainId: 2,
32
- # Type: 1,
33
- # AddressTo: "Mx7633980c000139dd3bd24a3f54e06474fa941e16",
34
- # Value: 24_000_000_000_000_000_000,
35
- # Coin: "MNT",
36
- # GasCoin: "MNT",
37
- # GasPrice: 10,
38
- # PrivateKey: "290cd647206bea71ec06d8dfacce30c872aea3fb1ea333b7f475b70467250ca0"
39
- # }
40
- # tx = Minter::TransactionFfi.SignTransaction(tx_params.to_json)
41
- # Minter::Api::Client.new.send_transaction(transaction: tx)
42
-
43
- # ==CREATE COIN==
44
- # tx_params = {
45
- # Name: "DEVTWO",
46
- # Symbol: "DEVTWO",
47
- # InitialAmount: 1000000000000000000,
48
- # MaxSupply: 10000000000000000000,
49
- # InitialReserve: 10000,
50
- # ReserveRation: 10,
51
- #
52
- # Nonce: 29,
53
- # ChainId: 2,
54
- # GasCoin: "MNT",
55
- # GasPrice: 1,
56
- # PrivateKey: "290cd647206bea71ec06d8dfacce30c872aea3fb1ea333b7f475b70467250ca0"
57
- # }
58
- #
59
- # tx = Minter::TransactionFfi.SignCreateCoinTransaction(tx_params.to_json)
60
- # Minter::Api::Client.new.send_transaction(transaction: tx)
61
-
62
- # ===SELL_COIN===
63
- # tx_params = {
64
- # CoinToSell: "DEVDEV",
65
- # ValueToSell: 1000,
66
- # CoinToBuy: "MNT",
67
- # MinimumValueToBuy: 100000000,
68
- #
69
- # Nonce: 31,
70
- # ChainId: 2,
71
- # GasCoin: "MNT",
72
- # GasPrice: 1,
73
- # PrivateKey: "290cd647206bea71ec06d8dfacce30c872aea3fb1ea333b7f475b70467250ca0"
74
- # }
75
- #
76
- # tx = Minter::TransactionFfi.SignSellCoinTransaction(tx_params.to_json)
77
- # Minter::Api::Client.new.send_transaction(transaction: tx)
78
-
79
- # ===BUY_COIN===
80
- # tx_params = {
81
- # CoinToBuy: "DEVDEV",
82
- # ValueToBuy: 1000,
83
- # CoinToSell: "MNT",
84
- # MaximumValueToSell: 100000000,
85
- #
86
- # Nonce: 31,
87
- # ChainId: 2,
88
- # GasCoin: "MNT",
89
- # GasPrice: 1,
90
- # PrivateKey: "290cd647206bea71ec06d8dfacce30c872aea3fb1ea333b7f475b70467250ca0"
91
- # }
92
- #
93
- # tx = Minter::TransactionFfi.SignBuyCoinTransaction(tx_params.to_json)
94
- # Minter::Api::Client.new.send_transaction(transaction: tx)