Module: Stellar::DSL

Included in:
Stellar, LedgerKey, Operation
Defined in:
lib/stellar/dsl.rb

Class Method Summary collapse

Class Method Details

.Asset(subject = nil) ⇒ Stellar::Asset

Returns instance of the Stellar::Asset.

Parameters:

  • subject (Asset, String, nil) (defaults to: nil)

Returns:

Raises:

  • (TypeError)

    if subject cannot be converted to Stellar::Asset


33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/stellar/dsl.rb', line 33

def Asset(subject = nil)
  case subject
  when Asset
    subject
  when nil, /^(XLM[-:])?native$/
    Asset.native
  when /^([0-9A-Z]{1,4})[-:](G[A-Z0-9]{55})$/
    Asset.alphanum4($1, KeyPair($2))
  when /^([0-9A-Z]{5,12})[-:](G[A-Z0-9]{55})$/
    Asset.alphanum12($1, KeyPair($2))
  else
    raise TypeError, "Cannot convert #{subject.inspect} to Stellar::Asset"
  end
end

.Claimant(destination, &block) ⇒ Object


20
21
22
23
24
25
26
27
28
# File 'lib/stellar/dsl.rb', line 20

def Claimant(destination, &block)
  Claimant.new(
    ClaimantType.claimant_type_v0,
    Claimant::V0.new(
      destination: KeyPair(destination).,
      predicate: ClaimPredicate(&block)
    )
  )
end

.ClaimPredicate(&block) ⇒ Object

Constructs a new ClaimPredicate using DSL

Examples:

fulfilled during [T+5min, T+60min] period, where T refers to claimable balance entry creation time

Stellar::ClaimPredicate { before_relative_time(1.hour) & ~before_relative_time(5.minutes) }

not fulfilled starting from today midnight until tomorrow midnight,

Stellar::ClaimPredicate { before_absolute_time(Date.today.end_of_day) | ~before_absolute_time(Date.tomorrow.end_of_day) }

always fulfilled

Stellar::ClaimPredicate { }

15
16
17
18
# File 'lib/stellar/dsl.rb', line 15

def ClaimPredicate(&block)
  return ClaimPredicate.unconditional unless block
  ClaimPredicate.compose(&block)
end

.KeyPair(subject = nil) ⇒ Stellar::Keypair

Generates Stellar::Keypair from subject, use Stellar::Client.to_keypair as shortcut.

Parameters:

  • subject (String|Stellar::Account|Stellar::PublicKey|Stellar::SignerKey|Stellar::Keypair) (defaults to: nil)

    subject.

Returns:

  • (Stellar::Keypair)

    Stellar::Keypair instance.

Raises:

  • (TypeError)

    if subject cannot be converted to Stellar::KeyPair


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/stellar/dsl.rb', line 52

def KeyPair(subject = nil)
  case subject
  when ->(subj) { subj.respond_to?(:to_keypair) }
    subject.to_keypair
  when PublicKey
    KeyPair.from_public_key(subject.value)
  when SignerKey
    KeyPair.from_raw_seed(subject.value)
  when /^G[A-Z0-9]{55}$/
    KeyPair.from_address(subject.to_str)
  when /^S[A-Z0-9]{55}$/
    KeyPair.from_seed(subject.to_str)
  when /^.{32}$/
    KeyPair.from_raw_seed(subject.to_str)
  when nil
    KeyPair.random
  else
    raise TypeError, "cannot convert #{subject.inspect} to Stellar::KeyPair"
  end
end

.SignerKey(input = nil) ⇒ Stellar::SignerKey

Provides conversion from different input types into the SignerKey to use in ManageData operation.

Parameters:

  • input (String|zStellar::Account|Stellar::PublicKey|Stellar::SignerKey|Stellar::Keypair) (defaults to: nil)

    subject.

Returns:


76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/stellar/dsl.rb', line 76

def SignerKey(input = nil)
  case input
  when Transaction
    SignerKey.pre_auth_tx(input.hash)
  when /^[0-9A-Za-z+\/=]{44}$/
    SignerKey.hash_x(Stellar::Convert.from_base64(input))
  when /^[0-9a-f]{64}$/
    SignerKey.hash_x(Stellar::Convert.from_hex(input))
  when /^.{32}$/
    SignerKey.hash_x(input)
  else
    SignerKey.ed25519(KeyPair(input))
  end
end