minter 0.1.1 → 0.5.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.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +80 -8
  3. data/lib/ffi/{go → sign}/compile.rb +6 -4
  4. data/lib/ffi/sign/go.mod +5 -0
  5. data/lib/ffi/sign/go.sum +520 -0
  6. data/lib/ffi/{transaction-darwin-10.6-amd64.dylib → sign/sign-darwin-10.6-amd64.dylib} +0 -0
  7. data/lib/ffi/{wallet.h → sign/sign-darwin-10.6-amd64.h} +3 -11
  8. data/lib/ffi/sign/sign-linux-amd64.h +78 -0
  9. data/lib/ffi/sign/sign-linux-amd64.so +0 -0
  10. data/lib/ffi/sign/sign.go +84 -0
  11. data/lib/ffi/sign/sign_ffi.rb +12 -0
  12. data/lib/ffi/tx_hash/compile.rb +16 -0
  13. data/lib/ffi/tx_hash/go.mod +5 -0
  14. data/lib/ffi/tx_hash/go.sum +525 -0
  15. data/lib/ffi/tx_hash/tx-hash-darwin-10.6-amd64.dylib +0 -0
  16. data/lib/ffi/{transaction-linux-amd64.h → tx_hash/tx-hash-darwin-10.6-amd64.h} +13 -17
  17. data/lib/ffi/tx_hash/tx-hash-linux-amd64.h +100 -0
  18. data/lib/ffi/{transaction-linux-amd64.so → tx_hash/tx-hash-linux-amd64.so} +0 -0
  19. data/lib/ffi/tx_hash/tx_hash.go +618 -0
  20. data/lib/ffi/tx_hash/tx_hash_ffi.rb +25 -0
  21. data/lib/ffi/wallet/compile.rb +16 -0
  22. data/lib/ffi/wallet/go.mod +5 -0
  23. data/lib/ffi/wallet/go.sum +525 -0
  24. data/lib/ffi/{wallet-darwin-10.6-amd64.dylib → wallet/wallet-darwin-10.6-amd64.dylib} +0 -0
  25. data/lib/ffi/{wallet-darwin-10.6-amd64.h → wallet/wallet-darwin-10.6-amd64.h} +0 -0
  26. data/lib/ffi/{wallet-linux-amd64.h → wallet/wallet-linux-amd64.h} +0 -0
  27. data/lib/ffi/{wallet-linux-amd64.so → wallet/wallet-linux-amd64.so} +0 -0
  28. data/lib/ffi/wallet/wallet.go +50 -0
  29. data/lib/ffi/{wallet_ffi.rb → wallet/wallet_ffi.rb} +1 -1
  30. data/lib/minter.rb +4 -2
  31. data/lib/minter/api/resources/estimate_resource.rb +1 -1
  32. data/lib/minter/transactions/buy_coin_tx.rb +1 -8
  33. data/lib/minter/transactions/create_coin_tx.rb +1 -8
  34. data/lib/minter/transactions/create_multisig_address_tx.rb +38 -0
  35. data/lib/minter/transactions/declare_candidacy_tx.rb +1 -8
  36. data/lib/minter/transactions/delegate_tx.rb +1 -8
  37. data/lib/minter/transactions/edit_candidate_tx.rb +5 -10
  38. data/lib/minter/transactions/multi_send_tx.rb +29 -0
  39. data/lib/minter/transactions/redeem_check_tx.rb +1 -8
  40. data/lib/minter/transactions/sell_all_coin_tx.rb +1 -8
  41. data/lib/minter/transactions/sell_coin_tx.rb +1 -8
  42. data/lib/minter/transactions/send_coin_tx.rb +1 -8
  43. data/lib/minter/transactions/set_candidate_off_tx.rb +1 -8
  44. data/lib/minter/transactions/set_candidate_on_tx.rb +1 -8
  45. data/lib/minter/transactions/signed_tx.rb +3 -3
  46. data/lib/minter/transactions/transaction.rb +41 -0
  47. data/lib/minter/transactions/unbond_tx.rb +1 -8
  48. data/lib/minter/version.rb +1 -1
  49. data/lib/minter/wallet.rb +3 -2
  50. metadata +36 -18
  51. data/lib/ffi/transaction-darwin-10.6-amd64.h +0 -104
  52. data/lib/ffi/transaction_ffi.rb +0 -94
@@ -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.1.1"
4
+ VERSION = "0.5.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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Nikolaev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-18 00:00:00.000000000 Z
11
+ date: 2020-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv
@@ -131,7 +131,7 @@ dependencies:
131
131
  - !ruby/object:Gem::Version
132
132
  version: '3.9'
133
133
  description: This is a Ruby SDK based on Golang SDK for working with Minter blockchain
134
- email:
134
+ email:
135
135
  executables: []
136
136
  extensions: []
137
137
  extra_rdoc_files: []
@@ -141,18 +141,33 @@ files:
141
141
  - README.md
142
142
  - bin/console
143
143
  - bin/setup
144
- - lib/ffi/go/compile.rb
145
- - lib/ffi/transaction-darwin-10.6-amd64.dylib
146
- - lib/ffi/transaction-darwin-10.6-amd64.h
147
- - lib/ffi/transaction-linux-amd64.h
148
- - lib/ffi/transaction-linux-amd64.so
149
- - lib/ffi/transaction_ffi.rb
150
- - lib/ffi/wallet-darwin-10.6-amd64.dylib
151
- - lib/ffi/wallet-darwin-10.6-amd64.h
152
- - lib/ffi/wallet-linux-amd64.h
153
- - lib/ffi/wallet-linux-amd64.so
154
- - lib/ffi/wallet.h
155
- - lib/ffi/wallet_ffi.rb
144
+ - lib/ffi/sign/compile.rb
145
+ - lib/ffi/sign/go.mod
146
+ - lib/ffi/sign/go.sum
147
+ - lib/ffi/sign/sign-darwin-10.6-amd64.dylib
148
+ - lib/ffi/sign/sign-darwin-10.6-amd64.h
149
+ - lib/ffi/sign/sign-linux-amd64.h
150
+ - lib/ffi/sign/sign-linux-amd64.so
151
+ - lib/ffi/sign/sign.go
152
+ - lib/ffi/sign/sign_ffi.rb
153
+ - lib/ffi/tx_hash/compile.rb
154
+ - lib/ffi/tx_hash/go.mod
155
+ - lib/ffi/tx_hash/go.sum
156
+ - lib/ffi/tx_hash/tx-hash-darwin-10.6-amd64.dylib
157
+ - lib/ffi/tx_hash/tx-hash-darwin-10.6-amd64.h
158
+ - lib/ffi/tx_hash/tx-hash-linux-amd64.h
159
+ - lib/ffi/tx_hash/tx-hash-linux-amd64.so
160
+ - lib/ffi/tx_hash/tx_hash.go
161
+ - lib/ffi/tx_hash/tx_hash_ffi.rb
162
+ - lib/ffi/wallet/compile.rb
163
+ - lib/ffi/wallet/go.mod
164
+ - lib/ffi/wallet/go.sum
165
+ - lib/ffi/wallet/wallet-darwin-10.6-amd64.dylib
166
+ - lib/ffi/wallet/wallet-darwin-10.6-amd64.h
167
+ - lib/ffi/wallet/wallet-linux-amd64.h
168
+ - lib/ffi/wallet/wallet-linux-amd64.so
169
+ - lib/ffi/wallet/wallet.go
170
+ - lib/ffi/wallet/wallet_ffi.rb
156
171
  - lib/minter.rb
157
172
  - lib/minter/api/client.rb
158
173
  - lib/minter/api/connection.rb
@@ -175,9 +190,11 @@ files:
175
190
  - lib/minter/key.rb
176
191
  - lib/minter/transactions/buy_coin_tx.rb
177
192
  - lib/minter/transactions/create_coin_tx.rb
193
+ - lib/minter/transactions/create_multisig_address_tx.rb
178
194
  - lib/minter/transactions/declare_candidacy_tx.rb
179
195
  - lib/minter/transactions/delegate_tx.rb
180
196
  - lib/minter/transactions/edit_candidate_tx.rb
197
+ - lib/minter/transactions/multi_send_tx.rb
181
198
  - lib/minter/transactions/redeem_check_tx.rb
182
199
  - lib/minter/transactions/sell_all_coin_tx.rb
183
200
  - lib/minter/transactions/sell_coin_tx.rb
@@ -185,6 +202,7 @@ files:
185
202
  - lib/minter/transactions/set_candidate_off_tx.rb
186
203
  - lib/minter/transactions/set_candidate_on_tx.rb
187
204
  - lib/minter/transactions/signed_tx.rb
205
+ - lib/minter/transactions/transaction.rb
188
206
  - lib/minter/transactions/unbond_tx.rb
189
207
  - lib/minter/version.rb
190
208
  - lib/minter/wallet.rb
@@ -195,7 +213,7 @@ metadata:
195
213
  homepage_uri: https://github.com/rubyroid-team/minter
196
214
  source_code_uri: https://github.com/rubyroid-team/minter
197
215
  changelog_uri: https://github.com/rubyroid-team/minter/blob/master/CHANGELOG.md
198
- post_install_message:
216
+ post_install_message:
199
217
  rdoc_options: []
200
218
  require_paths:
201
219
  - lib
@@ -211,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
229
  version: '0'
212
230
  requirements: []
213
231
  rubygems_version: 3.0.8
214
- signing_key:
232
+ signing_key:
215
233
  specification_version: 4
216
234
  summary: This is a Ruby SDK based on Golang SDK for working with Minter blockchain
217
235
  test_files: []
@@ -1,104 +0,0 @@
1
- /* Code generated by cmd/cgo; DO NOT EDIT. */
2
-
3
- /* package mod */
4
-
5
-
6
- #line 1 "cgo-builtin-export-prolog"
7
-
8
- #include <stddef.h> /* for ptrdiff_t below */
9
-
10
- #ifndef GO_CGO_EXPORT_PROLOGUE_H
11
- #define GO_CGO_EXPORT_PROLOGUE_H
12
-
13
- #ifndef GO_CGO_GOSTRING_TYPEDEF
14
- typedef struct { const char *p; ptrdiff_t n; } _GoString_;
15
- #endif
16
-
17
- #endif
18
-
19
- /* Start of preamble from import "C" comments. */
20
-
21
-
22
-
23
-
24
- /* End of preamble from import "C" comments. */
25
-
26
-
27
- /* Start of boilerplate cgo prologue. */
28
- #line 1 "cgo-gcc-export-header-prolog"
29
-
30
- #ifndef GO_CGO_PROLOGUE_H
31
- #define GO_CGO_PROLOGUE_H
32
-
33
- typedef signed char GoInt8;
34
- typedef unsigned char GoUint8;
35
- typedef short GoInt16;
36
- typedef unsigned short GoUint16;
37
- typedef int GoInt32;
38
- typedef unsigned int GoUint32;
39
- typedef long long GoInt64;
40
- typedef unsigned long long GoUint64;
41
- typedef GoInt64 GoInt;
42
- typedef GoUint64 GoUint;
43
- typedef __SIZE_TYPE__ GoUintptr;
44
- typedef float GoFloat32;
45
- typedef double GoFloat64;
46
- typedef float _Complex GoComplex64;
47
- typedef double _Complex GoComplex128;
48
-
49
- /*
50
- static assertion to make sure the file is being used on architecture
51
- at least with matching size of GoInt.
52
- */
53
- typedef char _check_for_64_bit_pointer_matching_GoInt[sizeof(void*)==64/8 ? 1:-1];
54
-
55
- #ifndef GO_CGO_GOSTRING_TYPEDEF
56
- typedef _GoString_ GoString;
57
- #endif
58
- typedef void *GoMap;
59
- typedef void *GoChan;
60
- typedef struct { void *t; void *v; } GoInterface;
61
- typedef struct { void *data; GoInt len; GoInt cap; } GoSlice;
62
-
63
- #endif
64
-
65
- /* End of boilerplate cgo prologue. */
66
-
67
- #ifdef __cplusplus
68
- extern "C" {
69
- #endif
70
-
71
-
72
- extern char* SignTransaction(char* p0);
73
-
74
- extern char* TransactionHash(char* p0);
75
-
76
- extern char* DecodeTransaction(char* p0);
77
-
78
- extern char* SignCreateCoinTransaction(char* p0);
79
-
80
- extern char* SignSellCoinTransaction(char* p0);
81
-
82
- extern char* SignBuyCoinTransaction(char* p0);
83
-
84
- extern char* SignSellAllCoinTransaction(char* p0);
85
-
86
- extern char* SignDeclareCandidacyTransaction(char* p0);
87
-
88
- extern char* SignDelegateTransaction(char* p0);
89
-
90
- extern char* SignUnbondTransaction(char* p0);
91
-
92
- extern char* SignSetCandidateOffTransaction(char* p0);
93
-
94
- extern char* SignSetCandidateOnTransaction(char* p0);
95
-
96
- extern char* SignRedeemCheckTransaction(char* p0);
97
-
98
- extern char* SignEditCandidateTransaction(char* p0);
99
-
100
- extern char* SignMultiSendTransaction(char* p0);
101
-
102
- #ifdef __cplusplus
103
- }
104
- #endif
@@ -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)