Class: Cryptos::Output

Inherits:
Struct
  • Object
show all
Includes:
Utils::Hexas
Defined in:
lib/cryptos/output.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Hexas

#bignum_to_hex, #bin_to_hex, #byte_to_hex, #bytes_to_hex, #hex_size, #hex_to_little, #int_to_hex, #long_to_hex

Methods included from Utils::Bytes

#bignum_to_bytes, #bytes_to_bignum

Instance Attribute Details

#script_pubkeyObject

Returns the value of attribute script_pubkey

Returns:

  • (Object)

    the current value of script_pubkey



2
3
4
# File 'lib/cryptos/output.rb', line 2

def script_pubkey
  @script_pubkey
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



2
3
4
# File 'lib/cryptos/output.rb', line 2

def value
  @value
end

Class Method Details

.atomic_swap(secret_hash, to_address, locktime, from_address, amount) ⇒ Object



20
21
22
23
# File 'lib/cryptos/output.rb', line 20

def self.atomic_swap(secret_hash, to_address, locktime, from_address, amount)
  swap_script = Cryptos::Script.swap secret_hash, to_address, locktime, from_address
  Output.new amount, Cryptos::Script.p2sh(swap_script)
end

.multisig(a1, a2, amount) ⇒ Object



10
11
12
13
# File 'lib/cryptos/output.rb', line 10

def self.multisig(a1, a2, amount)
  redeem_script = Cryptos::Script.multisig a1, a2
  Output.new amount, Cryptos::Script.p2sh(redeem_script)
end

.p2pkh(address, amount) ⇒ Object



5
6
7
8
# File 'lib/cryptos/output.rb', line 5

def self.p2pkh(address, amount)
  output_script = Cryptos::Script.p2pkh address
  Output.new amount, output_script
end

.p2pkh_change(address, input, output, fee = 10_000) ⇒ Object



15
16
17
18
# File 'lib/cryptos/output.rb', line 15

def self.p2pkh_change(address, input, output, fee = 10_000)
  change_value = input.value - output.value - fee
  Output.p2pkh address, change_value
end

Instance Method Details

#serializeObject



25
26
27
28
# File 'lib/cryptos/output.rb', line 25

def serialize
  script_hex = script_pubkey.to_hex
  long_to_hex(value) + byte_to_hex(hex_size(script_hex)) + script_hex
end