minter 0.2.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +208 -278
  3. data/lib/ffi/{transaction → sign}/compile.rb +5 -3
  4. data/lib/ffi/sign/go.mod +5 -0
  5. data/lib/ffi/sign/go.sum +520 -0
  6. data/lib/ffi/sign/sign-darwin-10.6-amd64.dylib +0 -0
  7. data/lib/ffi/sign/sign-darwin-10.6-amd64.h +78 -0
  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/tx_hash/tx-hash-darwin-10.6-amd64.h +100 -0
  17. data/lib/ffi/tx_hash/tx-hash-linux-amd64.h +100 -0
  18. data/lib/ffi/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 +5 -3
  22. data/lib/ffi/wallet/go.mod +5 -0
  23. data/lib/ffi/wallet/go.sum +525 -0
  24. data/lib/ffi/wallet/wallet-darwin-10.6-amd64.dylib +0 -0
  25. data/lib/ffi/wallet/wallet-darwin-10.6-amd64.h +86 -0
  26. data/lib/ffi/wallet/wallet-linux-amd64.h +86 -0
  27. data/lib/ffi/wallet/wallet-linux-amd64.so +0 -0
  28. data/lib/ffi/wallet/wallet.go +50 -0
  29. data/lib/ffi/wallet/wallet_ffi.rb +1 -1
  30. data/lib/minter.rb +2 -1
  31. data/lib/minter/api/client.rb +4 -1
  32. data/lib/minter/api/connection.rb +6 -0
  33. data/lib/minter/api/resources/address_resource.rb +2 -6
  34. data/lib/minter/api/resources/block_resource.rb +2 -3
  35. data/lib/minter/api/resources/candidate_resource.rb +2 -2
  36. data/lib/minter/api/resources/coin_resource.rb +2 -2
  37. data/lib/minter/api/resources/estimate_resource.rb +1 -1
  38. data/lib/minter/api/resources/events_resource.rb +2 -3
  39. data/lib/minter/api/resources/max_gas_resource.rb +1 -1
  40. data/lib/minter/api/resources/nonce_resource.rb +3 -4
  41. data/lib/minter/api/resources/send_transaction_resource.rb +2 -3
  42. data/lib/minter/api/resources/transactions_resource.rb +2 -3
  43. data/lib/minter/transactions/buy_coin_tx.rb +0 -1
  44. data/lib/minter/transactions/create_coin_tx.rb +0 -1
  45. data/lib/minter/transactions/create_multisig_address_tx.rb +38 -0
  46. data/lib/minter/transactions/declare_candidacy_tx.rb +0 -2
  47. data/lib/minter/transactions/delegate_tx.rb +0 -1
  48. data/lib/minter/transactions/edit_candidate_tx.rb +4 -3
  49. data/lib/minter/transactions/multi_send_tx.rb +2 -3
  50. data/lib/minter/transactions/redeem_check_tx.rb +0 -1
  51. data/lib/minter/transactions/sell_all_coin_tx.rb +0 -1
  52. data/lib/minter/transactions/sell_coin_tx.rb +0 -1
  53. data/lib/minter/transactions/send_coin_tx.rb +0 -2
  54. data/lib/minter/transactions/set_candidate_off_tx.rb +0 -1
  55. data/lib/minter/transactions/set_candidate_on_tx.rb +0 -1
  56. data/lib/minter/transactions/signed_tx.rb +3 -3
  57. data/lib/minter/transactions/transaction.rb +34 -10
  58. data/lib/minter/transactions/unbond_tx.rb +0 -1
  59. data/lib/minter/version.rb +1 -1
  60. metadata +32 -8
  61. data/lib/ffi/transaction/transaction_ffi.rb +0 -93
@@ -0,0 +1,86 @@
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* NewMnemonic();
73
+
74
+ extern char* PrivateKeyFromMnemonic(char* p0);
75
+
76
+ extern char* PublicKeyFromPrivateKey(char* p0);
77
+
78
+ extern char* AddressFromMnemonic(char* p0);
79
+
80
+ extern char* AddressFromPrivateKey(char* p0);
81
+
82
+ extern char* AddressFromPublicKey(char* p0);
83
+
84
+ #ifdef __cplusplus
85
+ }
86
+ #endif
@@ -0,0 +1,86 @@
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* NewMnemonic();
73
+
74
+ extern char* PrivateKeyFromMnemonic(char* p0);
75
+
76
+ extern char* PublicKeyFromPrivateKey(char* p0);
77
+
78
+ extern char* AddressFromMnemonic(char* p0);
79
+
80
+ extern char* AddressFromPrivateKey(char* p0);
81
+
82
+ extern char* AddressFromPublicKey(char* p0);
83
+
84
+ #ifdef __cplusplus
85
+ }
86
+ #endif
@@ -0,0 +1,50 @@
1
+ package main
2
+
3
+ import (
4
+ "C"
5
+ "github.com/MinterTeam/minter-go-sdk/v2/wallet"
6
+
7
+ )
8
+
9
+ //export NewMnemonic
10
+ func NewMnemonic() *C.char {
11
+ mnemonic, _ := wallet.NewMnemonic()
12
+ return C.CString(mnemonic)
13
+ }
14
+
15
+ //export PrivateKeyFromMnemonic
16
+ func PrivateKeyFromMnemonic(mnemonic *C.char) *C.char {
17
+ seed, _ := wallet.Seed(C.GoString(mnemonic))
18
+ prKey, _ := wallet.PrivateKeyBySeed(seed)
19
+ return C.CString(prKey)
20
+ }
21
+
22
+ //export PublicKeyFromPrivateKey
23
+ func PublicKeyFromPrivateKey(prKey *C.char) *C.char {
24
+ pubKey, _ := wallet.PublicKeyByPrivateKey(C.GoString(prKey))
25
+ return C.CString(pubKey)
26
+ }
27
+
28
+ //export AddressFromMnemonic
29
+ func AddressFromMnemonic(mnemonic *C.char) *C.char {
30
+ seed, _ := wallet.Seed(C.GoString(mnemonic))
31
+ prKey, _ := wallet.PrivateKeyBySeed(seed)
32
+ pubKey, _ := wallet.PublicKeyByPrivateKey(prKey)
33
+ address, _ := wallet.AddressByPublicKey(pubKey)
34
+ return C.CString(address)
35
+ }
36
+
37
+ //export AddressFromPrivateKey
38
+ func AddressFromPrivateKey(prKey *C.char) *C.char {
39
+ pubKey, _ := wallet.PublicKeyByPrivateKey(C.GoString(prKey))
40
+ address, _ := wallet.AddressByPublicKey(pubKey)
41
+ return C.CString(address)
42
+ }
43
+
44
+ //export AddressFromPublicKey
45
+ func AddressFromPublicKey(mnemonic *C.char) *C.char {
46
+ address, _ := wallet.AddressByPublicKey(C.GoString(mnemonic))
47
+ return C.CString(address)
48
+ }
49
+
50
+ func main() {}
@@ -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
@@ -7,7 +7,8 @@ require "minter/version"
7
7
  require "minter/wallet.rb"
8
8
  require "minter/key.rb"
9
9
  require "ffi/wallet/wallet_ffi.rb"
10
- require "ffi/transaction/transaction_ffi.rb"
10
+ require "ffi/tx_hash/tx_hash_ffi.rb"
11
+ require "ffi/sign/sign_ffi.rb"
11
12
  require "minter/transactions/transaction.rb"
12
13
  Dir[File.dirname(__FILE__) + "/minter/transactions/*.rb"].each { |file| require_relative file }
13
14
 
@@ -8,6 +8,9 @@ require_relative "connection"
8
8
  module Minter
9
9
  module Api
10
10
  class Client
11
+
12
+ DEFAULT_NODE_URL = "https://node-api.testnet.minter.network/v2"
13
+
11
14
  attr_accessor :node_url, :authenticated_api_url, :api_version
12
15
  attr_accessor :proxy, :connect_timeout, :read_timeout, :write_timeout
13
16
 
@@ -31,7 +34,7 @@ module Minter
31
34
  API_VERSION = 2
32
35
 
33
36
  def initialize(args = {})
34
- self.node_url = ENV["NODE_URL"]
37
+ self.node_url = ENV["NODE_URL"] || DEFAULT_NODE_URL
35
38
  self.connect_timeout = args[:connect_timeout] || DEFAULT_TIMEOUT
36
39
  self.read_timeout = args[:read_timeout] || DEFAULT_TIMEOUT
37
40
  self.write_timeout = args[:write_timeout] || DEFAULT_TIMEOUT
@@ -26,6 +26,12 @@ module Minter
26
26
  Minter::Api::Result.new(response)
27
27
  end
28
28
 
29
+ def post(path, params = {})
30
+ response = connection.post(build_url(config[:node_url], path), params: params)
31
+
32
+ Minter::Api::Result.new(response)
33
+ end
34
+
29
35
  def connection
30
36
  @connection ||= new_connection
31
37
  end
@@ -4,18 +4,14 @@ module Minter
4
4
  module Api
5
5
  module AddressResource
6
6
  def address(address:, height: nil)
7
- params = { address: address, height: height }.compact
8
- path = "/address"
7
+ params = { height: height }.compact
8
+ path = "/address/#{address}"
9
9
 
10
10
  get(path, params)
11
11
  end
12
12
 
13
13
  alias balance address
14
14
 
15
- def addresses(_params = {})
16
- path = "/address"
17
- get(path)
18
- end
19
15
  end
20
16
  end
21
17
  end
@@ -4,10 +4,9 @@ module Minter
4
4
  module Api
5
5
  module BlockResource
6
6
  def block(height:)
7
- params = { height: height }
8
- path = "/block"
7
+ path = "/block/#{height}"
9
8
 
10
- get(path, params)
9
+ get(path)
11
10
  end
12
11
  end
13
12
  end
@@ -4,8 +4,8 @@ module Minter
4
4
  module Api
5
5
  module CandidateResource
6
6
  def candidate(public_key:, height: nil)
7
- path = "/candidate"
8
- params = { pub_key: public_key, height: height }.compact
7
+ path = "/candidate/#{public_key}"
8
+ params = { height: height }.compact
9
9
  get(path, params)
10
10
  end
11
11
 
@@ -4,8 +4,8 @@ module Minter
4
4
  module Api
5
5
  module CoinResource
6
6
  def coin_info(symbol:, height:)
7
- params = { symbol: symbol, height: height }
8
- path = "/coin_info"
7
+ params = { height: height }
8
+ path = "/coin_info/#{symbol}"
9
9
  get(path, params)
10
10
  end
11
11
  end
@@ -17,7 +17,7 @@ module Minter
17
17
 
18
18
  def estimate_coin_sell_all(coinToSell:, valueToSell:, coinToBuy:, gasPrice:, height: nil)
19
19
  path = "/estimate_coin_sell_all"
20
- params = { coinToSell: coinToSell, valueToSell: valueToBuy, coinToBuy: coinToBuy, gasPrice: gasPrice, height: height }.compact
20
+ params = { coinToSell: coinToSell, valueToSell: valueToSell, coinToBuy: coinToBuy, gasPrice: gasPrice, height: height }.compact
21
21
  get(path, params)
22
22
  end
23
23
 
@@ -5,9 +5,8 @@ module Minter
5
5
  module EventsResource
6
6
  def events(height: nil)
7
7
  height ||= 1
8
- params = { height: height }
9
- path = "/events"
10
- get(path, params)
8
+ path = "/events/#{height}"
9
+ get(path)
11
10
  end
12
11
  end
13
12
  end
@@ -4,7 +4,7 @@ module Minter
4
4
  module Api
5
5
  module MaxGasResource
6
6
  def max_gas
7
- path = "/max_gas"
7
+ path = "/max_gas_price"
8
8
  get(path)
9
9
  end
10
10
  end
@@ -4,10 +4,9 @@ module Minter
4
4
  module Api
5
5
  module NonceResource
6
6
  def nonce(address:)
7
- params = { address: address }.compact
8
- path = "/address"
9
- response = get(path, params)
10
- response.body["result"]["transaction_count"].to_i + 1
7
+ path = "/address/#{address}"
8
+ response = get(path)
9
+ response.body["transaction_count"].to_i + 1
11
10
  end
12
11
  end
13
12
  end
@@ -4,9 +4,8 @@ module Minter
4
4
  module Api
5
5
  module SendTransactionResource
6
6
  def send_transaction(transaction:)
7
- params = { tx: transaction }
8
- path = "/send_transaction"
9
- get(path, params)
7
+ path = "/send_transaction/#{transaction}"
8
+ get(path)
10
9
  end
11
10
  end
12
11
  end
@@ -4,9 +4,8 @@ module Minter
4
4
  module Api
5
5
  module TransactionsResource
6
6
  def transaction_info(transaction_hash:)
7
- params = { hash: transaction_hash }
8
- path = "/transaction"
9
- get(path, params)
7
+ path = "/transaction/#{transaction_hash}"
8
+ get(path)
10
9
  end
11
10
 
12
11
  def transactions(query:, page: 1, per_page: 10)
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Minter
4
4
  class BuyCoinTx < Transaction
5
- SIGN_METHOD = :SignBuyCoinTransaction
6
5
  attr_accessor :coin_to_buy, :value_to_buy, :coin_to_sell, :maximum_value_to_sell, :nonce, :chain_id, :gas_coin, :gas_price
7
6
 
8
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
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Minter
4
4
  class CreateCoinTx < Transaction
5
- SIGN_METHOD = :SignCreateCoinTransaction
6
5
  attr_accessor :name, :symbol, :initial_amount, :max_supply, :initial_reserve, :reserve_ratio, :nonce, :chain_id, :gas_coin, :gas_price
7
6
 
8
7
  def initialize(name:, symbol:, initial_amount:, max_supply:, initial_reserve:, reserve_ratio:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
@@ -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