minter 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +925 -6
- data/bin/console +6 -5
- data/lib/ffi/go/compile.rb +14 -0
- data/lib/ffi/transaction_ffi.rb +94 -0
- data/lib/ffi/wallet_ffi.rb +16 -0
- data/lib/minter.rb +11 -4
- data/lib/minter/api/client.rb +53 -0
- data/lib/minter/api/connection.rb +50 -0
- data/lib/minter/api/errors.rb +18 -0
- data/lib/minter/api/resources/address_resource.rb +21 -0
- data/lib/minter/api/resources/block_resource.rb +14 -0
- data/lib/minter/api/resources/candidate_resource.rb +19 -0
- data/lib/minter/api/resources/coin_resource.rb +13 -0
- data/lib/minter/api/resources/estimate_resource.rb +31 -0
- data/lib/minter/api/resources/events_resource.rb +14 -0
- data/lib/minter/api/resources/max_gas_resource.rb +12 -0
- data/lib/minter/api/resources/min_gas_price_resource.rb +12 -0
- data/lib/minter/api/resources/missed_blocks_resource.rb +13 -0
- data/lib/minter/api/resources/nonce_resource.rb +14 -0
- data/lib/minter/api/resources/send_transaction_resource.rb +13 -0
- data/lib/minter/api/resources/status_resource.rb +12 -0
- data/lib/minter/api/resources/transactions_resource.rb +25 -0
- data/lib/minter/api/resources/validators_resource.rb +13 -0
- data/lib/minter/api/result.rb +54 -0
- data/lib/minter/key.rb +29 -0
- data/lib/minter/transactions/buy_coin_tx.rb +36 -0
- data/lib/minter/transactions/create_coin_tx.rb +40 -0
- data/lib/minter/transactions/declare_candidacy_tx.rb +38 -0
- data/lib/minter/transactions/delegate_tx.rb +34 -0
- data/lib/minter/transactions/edit_candidate_tx.rb +34 -0
- data/lib/minter/transactions/redeem_check_tx.rb +32 -0
- data/lib/minter/transactions/sell_all_coin_tx.rb +34 -0
- data/lib/minter/transactions/sell_coin_tx.rb +36 -0
- data/lib/minter/transactions/send_coin_tx.rb +34 -0
- data/lib/minter/transactions/set_candidate_off_tx.rb +30 -0
- data/lib/minter/transactions/set_candidate_on_tx.rb +30 -0
- data/lib/minter/transactions/signed_tx.rb +16 -0
- data/lib/minter/transactions/unbond_tx.rb +34 -0
- data/lib/minter/version.rb +2 -2
- data/lib/minter/wallet.rb +13 -0
- metadata +129 -9
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
module Api
|
5
|
+
module MissedBlocksResource
|
6
|
+
def missed_blocks(publicKey:, height: 1)
|
7
|
+
params = { publicKey: publicKey, height: height }.compact
|
8
|
+
path = "/missed_blocks"
|
9
|
+
get(path, params)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
module Api
|
5
|
+
module NonceResource
|
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
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
module Api
|
5
|
+
module TransactionsResource
|
6
|
+
def transaction_info(transaction_hash:)
|
7
|
+
params = { hash: transaction_hash }
|
8
|
+
path = "/transaction"
|
9
|
+
get(path, params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def transactions(query:, page: 1, per_page: 10)
|
13
|
+
params = { query: query, page: page, per_page: per_page }
|
14
|
+
path = "/transactions"
|
15
|
+
get(path, params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def unconfirmed_transactions(limit: 1)
|
19
|
+
params = { limit: limit }
|
20
|
+
path = "/unconfirmed_txs"
|
21
|
+
get(path, params)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
module Api
|
5
|
+
class Result
|
6
|
+
attr_reader :headers, :body, :status
|
7
|
+
|
8
|
+
def initialize(response, **options)
|
9
|
+
handle_error_response(response) if !response.status.success? && !options[:suppress_errors]
|
10
|
+
|
11
|
+
@headers = response.headers
|
12
|
+
@body = JSON.parse(response.body)
|
13
|
+
@status = response.status
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_h
|
17
|
+
{
|
18
|
+
headers: @headers.to_h,
|
19
|
+
body: @body,
|
20
|
+
status: @status.code
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
to_h.slice(:body, :status).to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def handle_error_response(response)
|
31
|
+
response_body = JSON.parse(response.body)
|
32
|
+
|
33
|
+
case response.status.code
|
34
|
+
when 400
|
35
|
+
raise BadRequestError, response_body
|
36
|
+
when 401
|
37
|
+
raise UnauthorizedError, response_body
|
38
|
+
when 403
|
39
|
+
raise ForbiddenError, response_body
|
40
|
+
when 404
|
41
|
+
raise NotFoundError, response.uri.to_s
|
42
|
+
when 412
|
43
|
+
raise PreconditionFailedError, response_body["error"]
|
44
|
+
when 429
|
45
|
+
raise RateLimitError, response_body
|
46
|
+
when 500
|
47
|
+
raise InternalServerError, response_body
|
48
|
+
else
|
49
|
+
raise UnknownError, response_body
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/minter/key.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
module Key
|
5
|
+
def self.new_mnemonic
|
6
|
+
Minter::WalletFfi.NewMnemonic
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.private_key_from_mnemonic(mnemonic)
|
10
|
+
Minter::WalletFfi.PrivateKeyFromMnemonic(mnemonic)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.public_key_from_private_key(private_key)
|
14
|
+
Minter::WalletFfi.PublicKeyFromPrivateKey(private_key)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.address_from_mnemonic(mnemonic)
|
18
|
+
Minter::WalletFfi.AddressFromMnemonic(mnemonic)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.address_from_private_key(private_key)
|
22
|
+
Minter::WalletFfi.AddressFromPrivateKey(private_key)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.address_from_public_key(public_key)
|
26
|
+
Minter::WalletFfi.AddressFromPublicKey(public_key)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
class BuyCoinTx
|
5
|
+
attr_accessor :coin_to_buy, :value_to_buy, :coin_to_sell, :maximum_value_to_sell, :nonce, :chain_id, :gas_coin, :gas_price
|
6
|
+
|
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
|
8
|
+
@coin_to_buy = coin_to_buy
|
9
|
+
@value_to_buy = value_to_buy
|
10
|
+
@coin_to_sell = coin_to_sell
|
11
|
+
@maximum_value_to_sell = maximum_value_to_sell
|
12
|
+
@nonce = nonce
|
13
|
+
@chain_id = chain_id
|
14
|
+
@gas_coin = gas_coin
|
15
|
+
@gas_price = gas_price
|
16
|
+
end
|
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
|
+
def to_params
|
26
|
+
{ CoinToBuy: coin_to_buy,
|
27
|
+
ValueToBuy: value_to_buy,
|
28
|
+
CoinToSell: coin_to_sell,
|
29
|
+
MaximumValueToSell: maximum_value_to_sell,
|
30
|
+
Nonce: nonce,
|
31
|
+
ChainId: chain_id,
|
32
|
+
GasCoin: gas_coin,
|
33
|
+
GasPrice: gas_price }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
class CreateCoinTx
|
5
|
+
attr_accessor :name, :symbol, :initial_amount, :max_supply, :initial_reserve, :reserve_ratio, :nonce, :chain_id, :gas_coin, :gas_price
|
6
|
+
|
7
|
+
def initialize(name:, symbol:, initial_amount:, max_supply:, initial_reserve:, reserve_ratio:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
|
8
|
+
@name = name
|
9
|
+
@symbol = symbol
|
10
|
+
@max_supply = max_supply
|
11
|
+
@initial_amount = initial_amount
|
12
|
+
@initial_reserve = initial_reserve
|
13
|
+
@reserve_ratio = reserve_ratio
|
14
|
+
@nonce = nonce
|
15
|
+
@chain_id = chain_id
|
16
|
+
@gas_coin = gas_coin
|
17
|
+
@gas_price = gas_price
|
18
|
+
end
|
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
|
+
def to_params
|
28
|
+
{ Name: name,
|
29
|
+
Symbol: symbol,
|
30
|
+
InitialAmount: initial_amount,
|
31
|
+
MaxSupply: max_supply,
|
32
|
+
InitialReserve: initial_reserve,
|
33
|
+
ReserveRation: reserve_ratio, # TODO: rename ReserveRation to ReserveRatio
|
34
|
+
Nonce: nonce,
|
35
|
+
ChainId: chain_id,
|
36
|
+
GasCoin: gas_coin,
|
37
|
+
GasPrice: gas_price }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
class DeclareCandidacyTx
|
5
|
+
attr_accessor :address, :pubkey, :commission, :coin, :stake, :nonce, :chain_id, :gas_coin, :gas_price
|
6
|
+
|
7
|
+
def initialize(address:, pubkey:, commission:, coin:, stake:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
|
8
|
+
@address = address
|
9
|
+
@pubkey = pubkey
|
10
|
+
@commission = commission
|
11
|
+
@coin = coin
|
12
|
+
@stake = stake
|
13
|
+
@nonce = nonce
|
14
|
+
@chain_id = chain_id
|
15
|
+
@gas_coin = gas_coin
|
16
|
+
@gas_price = gas_price
|
17
|
+
end
|
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
|
+
def to_params
|
27
|
+
{ Address: address,
|
28
|
+
PubKey: pubkey,
|
29
|
+
Commission: commission,
|
30
|
+
Coin: coin,
|
31
|
+
Stake: stake,
|
32
|
+
Nonce: nonce,
|
33
|
+
ChainId: chain_id,
|
34
|
+
GasCoin: gas_coin,
|
35
|
+
GasPrice: gas_price }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
class DelegateTx
|
5
|
+
attr_accessor :pubkey, :coin, :value, :nonce, :chain_id, :gas_coin, :gas_price
|
6
|
+
|
7
|
+
def initialize(pubkey:, coin:, value:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
|
8
|
+
@pubkey = pubkey
|
9
|
+
@coin = coin
|
10
|
+
@value = value
|
11
|
+
@nonce = nonce
|
12
|
+
@chain_id = chain_id
|
13
|
+
@gas_coin = gas_coin
|
14
|
+
@gas_price = gas_price
|
15
|
+
end
|
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
|
+
def to_params
|
25
|
+
{ PubKey: pubkey,
|
26
|
+
Coin: coin,
|
27
|
+
Value: value,
|
28
|
+
Nonce: nonce,
|
29
|
+
ChainId: chain_id,
|
30
|
+
GasCoin: gas_coin,
|
31
|
+
GasPrice: gas_price }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
class EditCandidateTx
|
5
|
+
attr_accessor :pubkey, :reward_address, :owner_address, :nonce, :chain_id, :gas_coin, :gas_price
|
6
|
+
|
7
|
+
def initialize(pubkey:, reward_address:, owner_address:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
|
8
|
+
@pubkey = pubkey
|
9
|
+
@reward_address = reward_address
|
10
|
+
@owner_address = owner_address
|
11
|
+
@nonce = nonce
|
12
|
+
@chain_id = chain_id
|
13
|
+
@gas_coin = gas_coin
|
14
|
+
@gas_price = gas_price
|
15
|
+
end
|
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
|
+
def to_params
|
25
|
+
{ PubKey: pubkey,
|
26
|
+
RewardAddress: reward_address,
|
27
|
+
OwnerAddress: owner_address,
|
28
|
+
Nonce: nonce,
|
29
|
+
ChainId: chain_id,
|
30
|
+
GasCoin: gas_coin,
|
31
|
+
GasPrice: gas_price }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
class RedeemCheckTx
|
5
|
+
attr_accessor :check, :proof, :nonce, :chain_id, :gas_coin, :gas_price
|
6
|
+
|
7
|
+
def initialize(check:, proof:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
|
8
|
+
@check = check
|
9
|
+
@proof = proof
|
10
|
+
@nonce = nonce
|
11
|
+
@chain_id = chain_id
|
12
|
+
@gas_coin = gas_coin
|
13
|
+
@gas_price = gas_price
|
14
|
+
end
|
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
|
+
def to_params
|
24
|
+
{ Check: check,
|
25
|
+
Proof: proof,
|
26
|
+
Nonce: nonce,
|
27
|
+
ChainId: chain_id,
|
28
|
+
GasCoin: gas_coin,
|
29
|
+
GasPrice: gas_price }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Minter
|
4
|
+
class SellAllCoinTx
|
5
|
+
attr_accessor :coin_to_sell, :coin_to_buy, :minimum_value_to_buy, :nonce, :chain_id, :gas_coin, :gas_price
|
6
|
+
|
7
|
+
def initialize(coin_to_sell:, coin_to_buy:, minimum_value_to_buy:, nonce:, chain_id:, gas_coin:, gas_price:) # rubocop:disable Metrics/ParameterLists
|
8
|
+
@coin_to_sell = coin_to_sell
|
9
|
+
@coin_to_buy = coin_to_buy
|
10
|
+
@minimum_value_to_buy = minimum_value_to_buy
|
11
|
+
@nonce = nonce
|
12
|
+
@chain_id = chain_id
|
13
|
+
@gas_coin = gas_coin
|
14
|
+
@gas_price = gas_price
|
15
|
+
end
|
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
|
+
def to_params
|
25
|
+
{ CoinToSell: coin_to_sell,
|
26
|
+
CoinToBuy: coin_to_buy,
|
27
|
+
MinimumValueToBuy: minimum_value_to_buy,
|
28
|
+
Nonce: nonce,
|
29
|
+
ChainId: chain_id,
|
30
|
+
GasCoin: gas_coin,
|
31
|
+
GasPrice: gas_price }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|