Class: Xpring::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/xpring/client.rb

Overview

Make GRPC network calls to XRP ledger

Constant Summary collapse

DEFAULT_DEADLINE_OFFSET =
60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(grpc_url, credentials: :this_channel_is_insecure, deadline_offset: DEFAULT_DEADLINE_OFFSET) ⇒ Client

Returns a new instance of Client.

Parameters:

  • grpc_url (#to_s)
  • credentials (GRPC::Core::ChannelCredentials, :this_channel_is_insecure) (defaults to: :this_channel_is_insecure)
  • deadline_offset (Integer) (defaults to: DEFAULT_DEADLINE_OFFSET)

    how many seconds each network call is allowed to take



29
30
31
32
33
34
35
36
37
# File 'lib/xpring/client.rb', line 29

def initialize(
  grpc_url,
  credentials: :this_channel_is_insecure,
  deadline_offset: DEFAULT_DEADLINE_OFFSET
)
  @grpc_url = grpc_url.to_s
  @credentials = credentials
  @deadline_offset = deadline_offset
end

Instance Attribute Details

#credentialsObject (readonly)

Returns the value of attribute credentials.



22
23
24
# File 'lib/xpring/client.rb', line 22

def credentials
  @credentials
end

#deadline_offsetObject (readonly)

Returns the value of attribute deadline_offset.



22
23
24
# File 'lib/xpring/client.rb', line 22

def deadline_offset
  @deadline_offset
end

#grpc_urlObject (readonly)

Returns the value of attribute grpc_url.



22
23
24
# File 'lib/xpring/client.rb', line 22

def grpc_url
  @grpc_url
end

Instance Method Details

#balance_of(address) ⇒ Integer?

Parameters:

  • address (#to_s)

    classic address

Returns:

  • (Integer, nil)


41
42
43
44
# File 'lib/xpring/client.rb', line 41

def balance_of(address)
  (address.to_s)&.
    &.balance&.value&.xrp_amount&.drops
end

#send_xrp(amount:, to:, from:) ⇒ Org::Xrpl::Rpc::V1::SubmitTransactionResponse?

Parameters:

Returns:

Raises:



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/xpring/client.rb', line 58

def send_xrp(amount:, to:, from:)
  classic_from_address, classic_to_address,  =
    validate_and_prepare_sending_xrp(to.to_s, from)
  transaction_hash = {
    Account: classic_from_address,
    Fee: minimum_fee.to_s, # ripple-binary-codec requires string
    LastLedgerSequence: next_sequence_for_transaction,
    Sequence: ..sequence.value,
    SigningPubKey: from.public_key,
    Amount: amount.to_s, # ripple-binary-codec requires string
    Destination: classic_to_address,
    TransactionType: "Payment",
  }
  submit_transaction(from_wallet: from, transaction_hash: transaction_hash)
end

#status_of(transaction) ⇒ Symbol?

Parameters:

  • transaction (#to_s)

Returns:

  • (Symbol, nil)


48
49
50
51
# File 'lib/xpring/client.rb', line 48

def status_of(transaction)
  transaction_data(transaction.to_s)&.meta
    &.transaction_result&.result_type
end