Module: BTC
- Extended by:
- BTC
- Includes:
- Data, HashFunctions, Opcodes, Safety, ScriptErrors
- Included in:
- BTC
- Defined in:
- lib/btcruby/key.rb,
lib/btcruby/wif.rb,
lib/btcruby/data.rb,
lib/btcruby/ssss.rb,
lib/btcruby/block.rb,
lib/btcruby/base58.rb,
lib/btcruby/errors.rb,
lib/btcruby/safety.rb,
lib/btcruby/address.rb,
lib/btcruby/hash_id.rb,
lib/btcruby/network.rb,
lib/btcruby/openssl.rb,
lib/btcruby/version.rb,
lib/btcruby/keychain.rb,
lib/btcruby/mnemonic.rb,
lib/btcruby/outpoint.rb,
lib/btcruby/constants.rb,
lib/btcruby/secp256k1.rb,
lib/btcruby/big_number.rb,
lib/btcruby/extensions.rb,
lib/btcruby/validation.rb,
lib/btcruby/diagnostics.rb,
lib/btcruby/merkle_tree.rb,
lib/btcruby/transaction.rb,
lib/btcruby/wire_format.rb,
lib/btcruby/block_header.rb,
lib/btcruby/proof_of_work.rb,
lib/btcruby/script/opcode.rb,
lib/btcruby/script/script.rb,
lib/btcruby/hash_functions.rb,
lib/btcruby/open_assets/asset.rb,
lib/btcruby/transaction_input.rb,
lib/btcruby/currency_formatter.rb,
lib/btcruby/transaction_output.rb,
lib/btcruby/script/script_chunk.rb,
lib/btcruby/script/script_error.rb,
lib/btcruby/script/script_flags.rb,
lib/btcruby/transaction_builder.rb,
lib/btcruby/open_assets/asset_id.rb,
lib/btcruby/script/script_number.rb,
lib/btcruby/script/cltv_extension.rb,
lib/btcruby/script/p2sh_extension.rb,
lib/btcruby/script/script_version.rb,
lib/btcruby/open_assets/issuance_id.rb,
lib/btcruby/open_assets/asset_marker.rb,
lib/btcruby/script/signature_checker.rb,
lib/btcruby/open_assets/asset_address.rb,
lib/btcruby/script/script_interpreter.rb,
lib/btcruby/script/signature_hashtype.rb,
lib/btcruby/transaction_builder/errors.rb,
lib/btcruby/transaction_builder/result.rb,
lib/btcruby/transaction_builder/signer.rb,
lib/btcruby/open_assets/asset_processor.rb,
lib/btcruby/open_assets/asset_definition.rb,
lib/btcruby/transaction_builder/provider.rb,
lib/btcruby/open_assets/asset_transaction.rb,
lib/btcruby/script/test_signature_checker.rb,
lib/btcruby/open_assets/asset_transaction_input.rb,
lib/btcruby/script/script_interpreter_extension.rb,
lib/btcruby/open_assets/asset_transaction_output.rb,
lib/btcruby/script/transaction_signature_checker.rb,
lib/btcruby/open_assets/asset_transaction_builder.rb,
lib/btcruby/open_assets/asset_transaction_builder/errors.rb,
lib/btcruby/open_assets/asset_transaction_builder/result.rb,
lib/btcruby/open_assets/asset_transaction_builder/provider.rb
Overview
High-level Transaction Builder for OpenAssets protocol. https://github.com/OpenAssets/open-assets-protocol/blob/master/specification.mediawiki
Defined Under Namespace
Modules: AssetProcessorSource, Base58, Data, HashFunctions, Opcode, Opcodes, OpenSSL, ProofOfWork, Safety, ScriptErrors, ScriptFlags, ScriptInterpreterExtension, Secp256k1, SignatureChecker, StringExtensions, WireFormat Classes: Address, Asset, AssetAddress, AssetDefinition, AssetID, AssetMarker, AssetProcessor, AssetTransaction, AssetTransactionBuilder, AssetTransactionInput, AssetTransactionOutput, BTCError, BigNumber, BitcoinPaymentAddress, Block, BlockHeader, CLTVExtension, CurrencyFormatter, Diagnostics, FormatError, Hash160Address, IssuanceID, Key, Keychain, MathError, MerkleTree, Mnemonic, Network, Outpoint, P2SHExtension, PublicKeyAddress, Script, ScriptChunk, ScriptError, ScriptHashAddress, ScriptInterpreter, ScriptNumber, ScriptNumberError, ScriptVersion, SecretSharing, TestSignatureChecker, Transaction, TransactionBuilder, TransactionInput, TransactionOutput, TransactionSignatureChecker, Validation, ValidationState, WIF
Constant Summary collapse
- PrivateKeyAddress =
For compatibility
WIF- VERSION =
"1.8".freeze
- TransactionOutpoint =
For backwards compatibility keep the longer name.
Outpoint- SATOSHI =
Satoshi is the smallest unit representable in Bitcoin transactions.
1- COIN =
100 mln satoshis is one Bitcoin
100_000_000- BIT =
1 bit is 100 satoshis (1 millionth of a bitcoin)
100- MAX_BLOCK_SIZE =
The maximum allowed size for a serialized block, in bytes
1000000- MAX_BLOCK_SIGOPS =
The maximum allowed number of signature check operations in a block
MAX_BLOCK_SIZE/50
- MAX_MONEY =
No amount larger than this (in satoshis) is valid
21_000_000 * COIN
- COINBASE_MATURITY =
Coinbase transaction outputs can only be spent after this number of new blocks
100- LOCKTIME_THRESHOLD =
Threshold for BTC::Transaction#lock_time: below this value it is interpreted as a block number, otherwise as UNIX timestamp.
500000000- BIP16_TIMESTAMP =
P2SH BIP16 didn't become active until Apr 1 2012. All txs before this timestamp should not be verified with P2SH rule.
1333238400- MAX_SCRIPT_SIZE =
Scripts longer than 10000 bytes are invalid.
10000- MAX_SCRIPT_ELEMENT_SIZE =
Maximum number of bytes per "pushdata" operation
520- MAX_KEYS_FOR_CHECKMULTISIG =
Number of public keys allowed for OP_CHECKMULTISIG
20- MAX_OPS_PER_SCRIPT =
Maximum number of operations allowed per script (excluding pushdata operations and OP_
) Multisig op additionally increases count by a number of pubkeys. 201- MAX_INV_SZ =
The maximum number of entries in an 'inv' protocol message
50000- MAX_BLOCK_SIZE_GEN =
The maximum size for mined blocks
MAX_BLOCK_SIZE / 2
- MAX_STANDARD_TX_SIZE =
The maximum size for transactions we're willing to relay/mine
MAX_BLOCK_SIZE_GEN / 5
- REJECT_MALFORMED =
"reject" message codes
0x01- REJECT_INVALID =
0x10- REJECT_OBSOLETE =
0x11- REJECT_DUPLICATE =
0x12- REJECT_NONSTANDARD =
0x40- REJECT_DUST =
0x41- REJECT_INSUFFICIENTFEE =
0x42- REJECT_CHECKPOINT =
0x43- MAX_STACK_SIZE =
1000- SIGHASH_ALL =
Default. Signs all inputs and outputs. Other inputs have scripts and sequences zeroed out, current input has its script replaced by the previous transaction's output script (or, in case of P2SH, by the signatures and the redemption script). If (type & 0x1F) is not NONE or SINGLE, then this type is used.
1- SIGHASH_NONE =
All outputs are removed. "I don't care where it goes as long as others pay". Note: this is not safe when used with ANYONECANPAY, because then anyone who relays the transaction can pick your input and use in his own transaction. It's also not safe if all inputs are SIGHASH_NONE as well (or it's the only input).
2- SIGHASH_SINGLE =
Hash only the output with the same index as the current input. Preceding outputs are "nullified", other outputs are removed. Special case: if there is no matching output, hash is equal "0000000000000000000000000000000000000000000000000000000000000001" (32 bytes)
3- SIGHASH_OUTPUT_MASK =
This mask is used to determine one of the first types independently from ANYONECANPAY option: E.g. if (type & SIGHASH_OUTPUT_MASK == SIGHASH_NONE) { blank all outputs }
0x1F- SIGHASH_ANYONECANPAY =
Removes all inputs except for current txin before hashing. This allows to sign the transaction outputs without knowing who and how adds other inputs. E.g. a crowdfunding transaction with 100 BTC output can be signed independently by any number of people and will become valid only when someone combines all inputs in a single transaction to make it valid. Can be used together with any of the above types.
0x80
Constants included from ScriptErrors
ScriptErrors::SCRIPT_ERR_BAD_OPCODE, ScriptErrors::SCRIPT_ERR_CHECKMULTISIGVERIFY, ScriptErrors::SCRIPT_ERR_CHECKSIGVERIFY, ScriptErrors::SCRIPT_ERR_CLEANSTACK, ScriptErrors::SCRIPT_ERR_DISABLED_OPCODE, ScriptErrors::SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS, ScriptErrors::SCRIPT_ERR_EQUALVERIFY, ScriptErrors::SCRIPT_ERR_EVAL_FALSE, ScriptErrors::SCRIPT_ERR_INVALID_ALTSTACK_OPERATION, ScriptErrors::SCRIPT_ERR_INVALID_STACK_OPERATION, ScriptErrors::SCRIPT_ERR_MINIMALDATA, ScriptErrors::SCRIPT_ERR_NEGATIVE_LOCKTIME, ScriptErrors::SCRIPT_ERR_NUMEQUALVERIFY, ScriptErrors::SCRIPT_ERR_OK, ScriptErrors::SCRIPT_ERR_OP_COUNT, ScriptErrors::SCRIPT_ERR_OP_RETURN, ScriptErrors::SCRIPT_ERR_PUBKEYTYPE, ScriptErrors::SCRIPT_ERR_PUBKEY_COUNT, ScriptErrors::SCRIPT_ERR_PUSH_SIZE, ScriptErrors::SCRIPT_ERR_SCRIPT_SIZE, ScriptErrors::SCRIPT_ERR_SIG_COUNT, ScriptErrors::SCRIPT_ERR_SIG_DER, ScriptErrors::SCRIPT_ERR_SIG_HASHTYPE, ScriptErrors::SCRIPT_ERR_SIG_HIGH_S, ScriptErrors::SCRIPT_ERR_SIG_NULLDUMMY, ScriptErrors::SCRIPT_ERR_SIG_PUSHONLY, ScriptErrors::SCRIPT_ERR_STACK_SIZE, ScriptErrors::SCRIPT_ERR_UNBALANCED_CONDITIONAL, ScriptErrors::SCRIPT_ERR_UNKNOWN_ERROR, ScriptErrors::SCRIPT_ERR_UNSATISFIED_LOCKTIME, ScriptErrors::SCRIPT_ERR_VERIFY
Constants included from HashFunctions
HashFunctions::OPENSSL_DIGEST_NAME_SHA256, HashFunctions::OPENSSL_DIGEST_NAME_SHA512
Constants included from Opcodes
Opcodes::OPCODE_NAME_TO_VALUE, Opcodes::OPCODE_VALUE_TO_NAME, Opcodes::OP_0, Opcodes::OP_0NOTEQUAL, Opcodes::OP_1, Opcodes::OP_10, Opcodes::OP_11, Opcodes::OP_12, Opcodes::OP_13, Opcodes::OP_14, Opcodes::OP_15, Opcodes::OP_16, Opcodes::OP_1ADD, Opcodes::OP_1NEGATE, Opcodes::OP_1SUB, Opcodes::OP_2, Opcodes::OP_2DIV, Opcodes::OP_2DROP, Opcodes::OP_2DUP, Opcodes::OP_2MUL, Opcodes::OP_2OVER, Opcodes::OP_2ROT, Opcodes::OP_2SWAP, Opcodes::OP_3, Opcodes::OP_3DUP, Opcodes::OP_4, Opcodes::OP_5, Opcodes::OP_6, Opcodes::OP_7, Opcodes::OP_8, Opcodes::OP_9, Opcodes::OP_ABS, Opcodes::OP_ADD, Opcodes::OP_AND, Opcodes::OP_BOOLAND, Opcodes::OP_BOOLOR, Opcodes::OP_CAT, Opcodes::OP_CHECKLOCKTIMEVERIFY, Opcodes::OP_CHECKMULTISIG, Opcodes::OP_CHECKMULTISIGVERIFY, Opcodes::OP_CHECKSIG, Opcodes::OP_CHECKSIGVERIFY, Opcodes::OP_CODESEPARATOR, Opcodes::OP_DEPTH, Opcodes::OP_DIV, Opcodes::OP_DROP, Opcodes::OP_DUP, Opcodes::OP_ELSE, Opcodes::OP_ENDIF, Opcodes::OP_EQUAL, Opcodes::OP_EQUALVERIFY, Opcodes::OP_FALSE, Opcodes::OP_FROMALTSTACK, Opcodes::OP_GREATERTHAN, Opcodes::OP_GREATERTHANOREQUAL, Opcodes::OP_HASH160, Opcodes::OP_HASH256, Opcodes::OP_IF, Opcodes::OP_IFDUP, Opcodes::OP_INVALIDOPCODE, Opcodes::OP_INVERT, Opcodes::OP_LEFT, Opcodes::OP_LESSTHAN, Opcodes::OP_LESSTHANOREQUAL, Opcodes::OP_LSHIFT, Opcodes::OP_MAX, Opcodes::OP_MIN, Opcodes::OP_MOD, Opcodes::OP_MUL, Opcodes::OP_NEGATE, Opcodes::OP_NIP, Opcodes::OP_NOP, Opcodes::OP_NOP1, Opcodes::OP_NOP10, Opcodes::OP_NOP2, Opcodes::OP_NOP3, Opcodes::OP_NOP4, Opcodes::OP_NOP5, Opcodes::OP_NOP6, Opcodes::OP_NOP7, Opcodes::OP_NOP8, Opcodes::OP_NOP9, Opcodes::OP_NOT, Opcodes::OP_NOTIF, Opcodes::OP_NUMEQUAL, Opcodes::OP_NUMEQUALVERIFY, Opcodes::OP_NUMNOTEQUAL, Opcodes::OP_OR, Opcodes::OP_OVER, Opcodes::OP_PICK, Opcodes::OP_PUSHDATA1, Opcodes::OP_PUSHDATA2, Opcodes::OP_PUSHDATA4, Opcodes::OP_RESERVED, Opcodes::OP_RESERVED1, Opcodes::OP_RESERVED2, Opcodes::OP_RETURN, Opcodes::OP_RIGHT, Opcodes::OP_RIPEMD160, Opcodes::OP_ROLL, Opcodes::OP_ROT, Opcodes::OP_RSHIFT, Opcodes::OP_SHA1, Opcodes::OP_SHA256, Opcodes::OP_SIZE, Opcodes::OP_SUB, Opcodes::OP_SUBSTR, Opcodes::OP_SWAP, Opcodes::OP_TOALTSTACK, Opcodes::OP_TRUE, Opcodes::OP_TUCK, Opcodes::OP_VER, Opcodes::OP_VERIF, Opcodes::OP_VERIFY, Opcodes::OP_VERNOTIF, Opcodes::OP_WITHIN, Opcodes::OP_XOR
Constants included from Data
Data::BYTE_PACK_CODE, Data::HEX_PACK_CODE
Class Method Summary collapse
-
.hash_from_id(identifier) ⇒ Object
Converts string transaction or block ID into binary hash.
-
.id_from_hash(hash) ⇒ Object
Converts binary hash to hex identifier (as a big-endian 256-bit integer).
Methods included from HashFunctions
#hash160, #hash256, #hmac_sha256, #hmac_sha512, #ripemd160, #sha1, #sha256, #sha512
Methods included from Safety
#AssertType, #AssertTypeOrNil, #Invariant
Methods included from Data
#bytes_from_data, #data_from_bytes, #data_from_hex, #ensure_ascii_compatible_encoding, #ensure_binary_encoding, #from_hex, #hex_from_data, #random_data, #to_hex
Class Method Details
.hash_from_id(identifier) ⇒ Object
Converts string transaction or block ID into binary hash.
7 8 9 10 |
# File 'lib/btcruby/hash_id.rb', line 7 def self.hash_from_id(identifier) return nil if !identifier # so we can convert optional ID into optional hash without extra headache BTC.from_hex(identifier).reverse end |
.id_from_hash(hash) ⇒ Object
Converts binary hash to hex identifier (as a big-endian 256-bit integer).
13 14 15 16 |
# File 'lib/btcruby/hash_id.rb', line 13 def self.id_from_hash(hash) return nil if !hash # so we can convert optional hash into optional ID without extra headache BTC.to_hex(hash.reverse) end |