Module: Stellar::DSL
- Included in:
- Stellar
- Defined in:
- lib/stellar/dsl.rb
Instance Method Summary collapse
- #Asset(subject = nil) ⇒ Object
- #Claimant(destination, &block) ⇒ Object
-
#ClaimPredicate(&block) ⇒ Object
Constructs a new ClaimPredicate using DSL.
-
#KeyPair(subject = nil) ⇒ Stellar::Keypair
Generates Stellar::Keypair from subject, use Stellar::Client.to_keypair as shortcut.
-
#SignerKey(input = nil) ⇒ Stellar::SignerKey
Provides conversion from different input types into the SignerKey to use in ManageData operation.
Instance Method Details
#Asset(subject = nil) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/stellar/dsl.rb', line 28 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
18 19 20 21 22 23 24 25 26 |
# File 'lib/stellar/dsl.rb', line 18 def Claimant(destination, &block) Claimant.new( ClaimantType.claimant_type_v0, Claimant::V0.new( destination: KeyPair(destination).account_id, predicate: ClaimPredicate(&block) ) ) end |
#ClaimPredicate(&block) ⇒ Object
Constructs a new ClaimPredicate using DSL
13 14 15 16 |
# File 'lib/stellar/dsl.rb', line 13 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.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/stellar/dsl.rb', line 46 def KeyPair(subject = nil) case subject when ->(subj) { subj.respond_to?(:to_keypair) } subject.to_keypair when /G[A-Z0-9]{55}/ KeyPair.from_address(subject) when /S[A-Z0-9]{55}/ KeyPair.from_seed(subject) when PublicKey KeyPair.from_public_key(subject.value) when SignerKey KeyPair.from_raw_seed(subject.value) 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.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/stellar/dsl.rb', line 68 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 |