class Glueby::Contract::Timestamp

Timestamp feature allows users to send transaction with op_return output which has sha256 hash of arbitary data. Timestamp transaction has

Storing timestamp transaction to the blockchain enables everyone to verify that the data existed at that time and a user signed it.

Attributes

tx[R]
txid[R]

Public Class Methods

new( wallet:, content:, prefix: '', fee_estimator: Glueby::Contract::FixedFeeEstimator.new, digest: :sha256 ) click to toggle source

@param [String] content Data to be hashed and stored in blockchain. @param [String] prefix prefix of op_return data @param [Glueby::Contract::FeeEstimator] fee_estimator @param [Symbol] digest type which select of:

  • :sha256

  • :double_sha256

  • :none

@raise [Glueby::Contract::Errors::UnsupportedDigestType] if digest unsupport

# File lib/glueby/contract/timestamp.rb, line 61
def initialize(
  wallet:,
  content:,
  prefix: '',
  fee_estimator: Glueby::Contract::FixedFeeEstimator.new,
  digest: :sha256
)
  @wallet = wallet
  @content = content
  @prefix = prefix
  @fee_estimator = fee_estimator
  @digest = digest
end

Public Instance Methods

save!() click to toggle source

broadcast to Tapyrus Core @return [String] txid @raise [TxAlreadyBroadcasted] if tx has been broadcasted. @raise [InsufficientFunds] if result of listunspent is not enough to pay the specified amount

# File lib/glueby/contract/timestamp.rb, line 79
def save!
  raise Glueby::Contract::Errors::TxAlreadyBroadcasted if @txid

  @tx = create_tx(@wallet, @prefix, digest_content, @fee_estimator)
  @txid = @wallet.internal_wallet.broadcast(@tx)
end

Private Instance Methods

digest_content() click to toggle source
# File lib/glueby/contract/timestamp.rb, line 88
def digest_content
  case @digest&.downcase
  when :sha256
    Tapyrus.sha256(@content)
  when :double_sha256
    Tapyrus.double_sha256(@content)
  when :none
    @content
  else
    raise Glueby::Contract::Errors::UnsupportedDigestType
  end
end