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
-
1 or more inputs enough to afford transaction fee.
-
1 output which has op_return, application specific prefix, and sha256 hash of data.
-
1 output to send the change TPC back to the wallet.
Storing timestamp transaction to the blockchain enables everyone to verify that the data existed at that time and a user signed it.
Attributes
Public Class Methods
@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
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
# 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