Class: Glueby::Contract::Timestamp
- Inherits:
-
Object
- Object
- Glueby::Contract::Timestamp
- Defined in:
- lib/glueby/contract/timestamp.rb,
lib/glueby/contract/timestamp/syncer.rb,
lib/glueby/contract/timestamp/tx_builder.rb,
lib/glueby/contract/timestamp/tx_builder/simple.rb,
lib/glueby/contract/timestamp/tx_builder/trackable.rb,
lib/glueby/contract/timestamp/tx_builder/updating_trackable.rb
Overview
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.
Versioning Timestamp
The timestamp has an attribute called "version". Version indicates how the timestamp is recorded in the blockchain. Currently, only versions 1 and 2 are supported, and each is recorded in the following manner
- Version 1: The first version of the blockchain is used to record timestamps. treats the content and prefix received as parameters as a binary string
- Version 2:. treats the specified content and prefix as a hexadecimal string with the string set to prefix and content.
For example, when recording a simple type of timestamp, the difference between the content recorded by version 1 and version 2 is as follows Version 1:
Save the as follows:
Glueby::Contract::Timestamp.new( wallet: wallet, content: "1234", prefix: "071222", digest: :none, version: "1" )
The output script of the recorded transaction will include OP_RETURN and will look like this:
OP_RETURN 30373132323231323334
Note that prefix: "071222" and content: "1234" are interpreted as ASCII strings and their hexadecimal representation "3037313232323132323334" is recorded in the actual blockchain, respectively.
Version 2:
To save the timestamp in version 2, simply change the version of the previous example to "2".
Glueby::Contract::Timestamp.new( wallet: wallet, content: "1234", prefix: "071222", digest: :none, version: "2" )
The output script will look like this:
OP_RETURN 0712221234
In this case, prefix: "071222" and content: "1234" are treated as a hexadecimal string and recorded directly in the blockchain.
Defined Under Namespace
Modules: TxBuilder Classes: Syncer
Constant Summary collapse
- P2C_DEFAULT_VALUE =
1_000
Instance Attribute Summary collapse
-
#p2c_address ⇒ Object
readonly
p2c_address and payment_base is used in
trackabletype. -
#payment_base ⇒ Object
readonly
p2c_address and payment_base is used in
trackabletype. -
#tx ⇒ Object
readonly
Returns the value of attribute tx.
-
#txid ⇒ Object
readonly
Returns the value of attribute txid.
Instance Method Summary collapse
-
#initialize(wallet:, content:, prefix: '', fee_estimator: Glueby::Contract::FeeEstimator::Fixed.new, digest: :sha256, utxo_provider: nil, timestamp_type: :simple, prev_timestamp_id: nil, version:) ⇒ Timestamp
constructor
- :sha256 - :double_sha256 - :none - :simple - :trackable.
-
#save! ⇒ String
broadcast to Tapyrus Core.
Constructor Details
#initialize(wallet:, content:, prefix: '', fee_estimator: Glueby::Contract::FeeEstimator::Fixed.new, digest: :sha256, utxo_provider: nil, timestamp_type: :simple, prev_timestamp_id: nil, version:) ⇒ Timestamp
- :sha256
- :double_sha256
- :none
- :simple
- :trackable
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/glueby/contract/timestamp.rb', line 83 def initialize( wallet:, content:, prefix: '', fee_estimator: Glueby::Contract::FeeEstimator::Fixed.new, digest: :sha256, utxo_provider: nil, timestamp_type: :simple, prev_timestamp_id: nil, version: ) @wallet = wallet @content = content @prefix = prefix @fee_estimator = fee_estimator raise Glueby::Contract::Errors::UnsupportedDigestType, "#{digest} is invalid digest, supported digest are :sha256, :double_sha256, and :none." unless [:sha256, :double_sha256, :none].include?(digest) @digest = digest @utxo_provider = utxo_provider raise Glueby::Contract::Errors::InvalidTimestampType, "#{timestamp_type} is invalid type, supported types are :simple, and :trackable." unless [:simple, :trackable].include?() = = raise Glueby::Contract::Errors::UnsupportedTimestampVersion, "#{version} is unsupported, supported versions are '1' and '2'." unless ['1', '2'].include?(version) @version = version end |
Instance Attribute Details
#p2c_address ⇒ Object (readonly)
p2c_address and payment_base is used in trackable type
63 64 65 |
# File 'lib/glueby/contract/timestamp.rb', line 63 def p2c_address @p2c_address end |
#payment_base ⇒ Object (readonly)
p2c_address and payment_base is used in trackable type
63 64 65 |
# File 'lib/glueby/contract/timestamp.rb', line 63 def payment_base @payment_base end |
#tx ⇒ Object (readonly)
Returns the value of attribute tx.
61 62 63 |
# File 'lib/glueby/contract/timestamp.rb', line 61 def tx @tx end |
#txid ⇒ Object (readonly)
Returns the value of attribute txid.
61 62 63 |
# File 'lib/glueby/contract/timestamp.rb', line 61 def txid @txid end |
Instance Method Details
#save! ⇒ String
broadcast to Tapyrus Core
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/glueby/contract/timestamp.rb', line 112 def save! raise Glueby::Contract::Errors::TxAlreadyBroadcasted if @ar @ar = Glueby::Contract::AR::Timestamp.new( wallet_id: @wallet.id, prefix: @prefix, content: @content, timestamp_type: , digest: @digest, prev_id: , version: @version ) @ar.save_with_broadcast!(fee_estimator: @fee_estimator, utxo_provider: @utxo_provider) @ar.txid end |