Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/pinetwork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class PiNetwork
TX_RETRY_DELAY_SECONDS = 5

def initialize(api_key:, wallet_private_key:, faraday: Faraday.new, options: {})
validate_private_seed_format!(wallet_private_key)
validate_private_seed!(wallet_private_key)

@api_key = api_key
@account = load_account(wallet_private_key)
@base_url = options[:base_url] || BASE_URL
Expand Down Expand Up @@ -81,7 +82,7 @@ def submit_payment(payment_id)
@from_address = payment["from_address"]

transaction_data = {
amount: payment["amount"],
amount: BigDecimal(payment["amount"].to_s),
identifier: payment["identifier"],
recipient: payment["to_address"]
}
Expand Down Expand Up @@ -259,9 +260,12 @@ def validate_payment_data!(data, options = {})
raise ArgumentError.new("Missing recipient") if options[:recipient] && !data[:recipient].present?
end

def validate_private_seed_format!(seed)
raise StandardError.new("Private Seed should start with \"S\"") unless seed.upcase.start_with?("S")
raise StandardError.new("Private Seed should be 56 characters") unless seed.length == 56
def validate_private_seed!(seed)
begin
Stellar::Util::StrKey.check_decode(:seed, seed)
rescue StandardError
raise StandardError.new("Invalid Private Seed")
end
end

def extract_error_message(response_body, default_message)
Expand Down