Skip to content

Commit

Permalink
Merge pull request #12 from jdogresorg/counterparty-classic
Browse files Browse the repository at this point in the history
Rollback `master` branch to `counterparty-classic`
  • Loading branch information
jdogresorg authored Oct 25, 2024
2 parents ea11281 + 184e423 commit a8c03b5
Show file tree
Hide file tree
Showing 17 changed files with 105 additions and 338 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ By default counterparty2mysql starts at the first block with a Counterparty tran

If no starting block is given, counterparty2mysql will try to resume parsing at the last successfully parsed block, or use the first block with a counterparty transaction.

Versions / Branches
---
- counterparty-classic - https://github.com/jdogresorg/counterparty2mysql/tree/counterparty-classic
- counterparty-2.0 - https://github.com/jdogresorg/counterparty2mysql/tree/counterparty-2.0
- dogeparty - https://github.com/jdogresorg/counterparty2mysql/tree/dogeparty
- unoparty - https://github.com/jdogresorg/counterparty2mysql/tree/unoparty

Database Customizations
---
Expand All @@ -30,8 +36,8 @@ cat sql/*.sql | mysql Counterparty_Testnet

Bootstrap Information
---
- [Counterparty.sql.gz](bootstrap/Counterparty.sql.gz) (Mainnet Block # 866,528)
- [Counterparty_Testnet.sql.gz](bootstrap/Counterparty_Testnet.sql.gz) (Testnet Block # 3,192,303)
- [Counterparty.sql.gz](bootstrap/Counterparty.sql.gz) (Mainnet Block # 821,957)
- [Counterparty_Testnet.sql.gz](bootstrap/Counterparty_Testnet.sql.gz) (Testnet Block # 2,543,400)

Command line arguments
---
Expand All @@ -48,7 +54,6 @@ Database Information
---
**Counterparty tables** (populated via 'messages')
- [addresses](sql/addresses.sql)
- [address_events](sql/address_events.sql)
- [bets](sql/bets.sql)
- [bet_expirations](sql/bet_expirations.sql)
- [bet_match_expirations](sql/bet_match_expirations.sql)
Expand All @@ -65,8 +70,6 @@ Database Information
- [dispenser_refills](sql/dispenser_refills.sql)
- [dispenses](sql/dispenses.sql)
- [dividends](sql/dividends.sql)
- [fairminters](sql/fairminters.sql)
- [fairmints](sql/fairmints.sql)
- [issuances](sql/issuances.sql)
- [order_expirations](sql/order_expirations.sql)
- [order_match_expirations](sql/order_match_expirations.sql)
Expand Down
4 changes: 2 additions & 2 deletions bootstrap/Counterparty.sql.gz
Git LFS file not shown
4 changes: 2 additions & 2 deletions bootstrap/Counterparty_Testnet.sql.gz
Git LFS file not shown
31 changes: 14 additions & 17 deletions counterparty2mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@
'dispenses',
'dividends',
'executions',
'fairminters',
'fairmints',
'issuances',
'index_tx',
'messages',
Expand Down Expand Up @@ -114,9 +112,9 @@
$current = $counterparty->status['last_block']['block_index'];

// Define array of fields that contain assets, addresses, transactions, and contracts
$fields_asset = array('asset', 'backward_asset', 'dividend_asset', 'forward_asset', 'get_asset', 'give_asset','asset_parent');
$fields_address = array('address', 'bet_hash', 'destination', 'feed_address', 'issuer', 'source', 'oracle_address', 'tx0_address', 'tx1_address', 'origin', 'last_status_tx_source');
$fields_transaction = array('event', 'move_random_hash', 'offer_hash', 'order_hash', 'rps_hash', 'tx_hash', 'tx0_hash', 'tx0_move_random_hash', 'tx1_hash', 'tx1_move_random_hash', 'dispenser_tx_hash', 'last_status_tx_hash', 'dispenser_tx_hash', 'block_hash', 'fairminter_tx_hash');
$fields_asset = array('asset', 'backward_asset', 'dividend_asset', 'forward_asset', 'get_asset', 'give_asset');
$fields_address = array('address', 'bet_hash', 'destination', 'feed_address', 'issuer', 'source', 'oracle_address', 'tx0_address', 'tx1_address', 'origin');
$fields_transaction = array('event', 'move_random_hash', 'offer_hash', 'order_hash', 'rps_hash', 'tx_hash', 'tx0_hash', 'tx0_move_random_hash', 'tx1_hash', 'tx1_move_random_hash', 'dispenser_tx_hash', 'last_status_tx_hash', 'dispenser_tx_hash');
$fields_contract = array('contract_id');

// Loop through the blocks until we are current
Expand Down Expand Up @@ -172,7 +170,7 @@
$contracts[$value] = createContract($value);
}
// Create record in tx_index (so we can map tx_index to tx_hash and table with data)
if(isset($obj->tx_index) && isset($obj->block_index) && isset($transactions[$obj->tx_hash]) && $msg->category!='transactions' && $msg->category!='transaction_outputs')
if(isset($obj->tx_index) && isset($obj->block_index) && isset($transactions[$obj->tx_hash]))
createTxIndex($obj->tx_index, $obj->block_index, $msg->category, $transactions[$obj->tx_hash]);
// Create record in the messages table (so we can review the CP messages as needed)
createMessage($message);
Expand All @@ -192,8 +190,8 @@
$bindings = json_decode($msg->bindings);
$command = $msg->command;

// v10.0.0 - Ignore certain messages for now as they conflict with our already existing tables and bloats database by not indexing addresses/hashes via id
if(in_array($table,array('assets', 'blocks', 'transaction_outputs')))
// v10.0.0 - Ignore certain messages for now
if(in_array($table,array('assets', 'blocks','transactions','transaction_outputs')))
continue;

// Build out array of fields and values
Expand Down Expand Up @@ -276,6 +274,9 @@
if(in_array($field,array('rowid','dispense_count')))
$ignore=true;
}
// v10.0.0 - Remap 'id' to 'order_match_id' for updates
if($table=='order_matches' && $field=='id' && $command=='update')
$field = 'order_match_id';
if($table=='dispenser_refills'){
if(in_array($field, array('dispenser_quantity','status')))
$ignore = true;
Expand Down Expand Up @@ -355,7 +356,7 @@
$sql = rtrim($sql, " AND");
$sqlUpdate = rtrim($sqlUpdate, " AND");

// print "{$sql}\n";
// print $sql;
$results = $mysqli->query($sql);
if($results){
//on duplicate key statement will update the row if exists already
Expand All @@ -376,7 +377,7 @@
$where = "";
foreach($fields as $index => $field){
// Update bets and orders records using tx_hash
if(in_array($table,array('orders','bets','dispensers','fairminters')) && $field=='tx_hash_id'){
if(in_array($table,array('orders','bets','dispensers')) && $field=='tx_hash_id'){
if($where!="")
$where .= " AND ";
$where .= " tx_hash_id='{$values[$index]}'";
Expand Down Expand Up @@ -404,9 +405,6 @@
} else {
$where = " source_id='{$fldmap['source_id']}' AND asset_id='{$fldmap['asset_id']}'";
}
// Skup updating the id field unnecessarily when updating an order match
} else if($table=='order_matches' && $field=='id'){
continue;
} else {
$sql .= " {$field}='{$values[$index]}',";
}
Expand All @@ -417,7 +415,6 @@
} else {
byeLog('Error - no WHERE criteria found');
}
// print "{$sql}\n";
$results = $mysqli->query($sql);
if(!$results)
byeLog('Error while trying to update record in ' . $table . ' : ' . $sql);
Expand Down Expand Up @@ -469,9 +466,9 @@
}

// Get list of transactions from the transactions table (used to track BTC paid and miners fee)
// $transactions = $counterparty->execute('get_transactions', array('filters' => array("field" => "block_index", "op" => "==", "value" => $block)));
// foreach($transactions as $transaction)
// createTransactionHistory($transaction);
$transactions = $counterparty->execute('get_transactions', array('filters' => array("field" => "block_index", "op" => "==", "value" => $block)));
foreach($transactions as $transaction)
createTransactionHistory($transaction);

// Report time to process block
$time = $timer->finish();
Expand Down
24 changes: 6 additions & 18 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,7 @@ function createBlock( $block_index=null ){
function createAsset( $asset=null, $block_index=null ){
global $mysqli, $counterparty;
// Get current information on this asset
// V1 API method (POST request - returns array)
// $info = $counterparty->execute('get_asset_info', array('assets' => array($asset)));
// V2 API method (GET request - returns object)
$json = json_decode(file_get_contents(CP_HOST . '/v2/assets/' . $asset));
$info = ($json && $json->result) ? [$json->result] : [];
$info = $counterparty->execute('get_asset_info', array('assets' => array($asset)));
// Create data object using asset info (if any)
$data = (count($info)) ? (object) $info[0] : (object) [];
// Replace 4-byte UTF-8 characters (fixes issue with breaking SQL queries)
Expand All @@ -193,15 +189,10 @@ function createAsset( $asset=null, $block_index=null ){
$data->supply = intval($data->supply);
$data->description = $mysqli->real_escape_string($description);
$data->asset_longname = $mysqli->real_escape_string($data->asset_longname);
// Set asset type (1=Named, 2=Numeric, 3=Subasset, 4=Failed issuance, 5=Numeric Subasset)
// Set asset type (1=Named, 2=Numeric, 3=Subasset, 4=Failed issuance)
$data->type = (substr($asset,0,1)=='A') ? 2 : 1;
// Named Subasset
if($data->type == 1 && $data->asset_longname!='')
if($data->asset_longname!='')
$data->type = 3;
// Numeric Subasset
if($data->type == 2 && $data->asset_longname!='')
$data->type = 5;
// Failed asset registration
if(count($info)==0)
$data->type = 4;
// Force numeric values for special assets
Expand Down Expand Up @@ -363,16 +354,13 @@ function createMessage( $message=null ){
$bindings = $mysqli->real_escape_string($msg->bindings);
$block_index = $mysqli->real_escape_string($msg->block_index);
$message_index = $mysqli->real_escape_string($msg->message_index);
$timestamp = ($msg->timestamp) ? $msg->timestamp : 'NULL';
$event = $mysqli->real_escape_string($msg->event);
$tx_hash = $mysqli->real_escape_string($msg->tx_hash);
$event_hash = $mysqli->real_escape_string($msg->event_hash);
$timestamp = $mysqli->real_escape_string($msg->timestamp);
$results = $mysqli->query("SELECT message_index FROM messages WHERE `message_index`='{$message_index}' LIMIT 1");
if($results){
if($results->num_rows==0){
$sql = "INSERT INTO messages (message_index, block_index, command, category, bindings, timestamp, event, tx_hash, event_hash) values ('{$message_index}','{$block_index}','{$command}','{$category}','{$bindings}', " . $timestamp . ",'{$event}','{$tx_hash}','{$event_hash}')";
$sql = "INSERT INTO messages (message_index, block_index, command, category, bindings, timestamp) values ('{$message_index}','{$block_index}','{$command}','{$category}','{$bindings}','{$timestamp}')";
} else {
$sql = "UPDATE messages SET block_index='{$block_index}', command='{$command}', category='{$category}', bindings='{$bindings}', timestamp=" . $timestamp . ", event='{$event}', tx_hash='{$tx_hash}', event_hash='{$event_hash}' WHERE message_index='{$message_index}'";
$sql = "UPDATE messages SET block_index='{$block_index}', command='{$command}', category='{$category}', bindings='{$bindings}', timestamp='{$timestamp}' WHERE message_index='{$message_index}'";
}
$results = $mysqli->query($sql);
if(!$results){
Expand Down
7 changes: 0 additions & 7 deletions sql/address_events.sql

This file was deleted.

22 changes: 10 additions & 12 deletions sql/debits.sql
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
DROP TABLE IF EXISTS debits;
CREATE TABLE debits (
tx_index INTEGER UNSIGNED,
block_index INTEGER UNSIGNED,
-- address TEXT,
address_id INTEGER UNSIGNED, -- id of record in index_addresses
-- asset TEXT,
asset_id INTEGER UNSIGNED, -- id of record in assets table
quantity BIGINT,
action TEXT,
-- event TEXT,
event_id INTEGER UNSIGNED -- id of record in index_transactions
utxo TEXT,
utxo_address TEXT
tx_index INTEGER UNSIGNED,
block_index INTEGER UNSIGNED,
-- address TEXT,
address_id INTEGER UNSIGNED, -- id of record in index_addresses
-- asset TEXT,
asset_id INTEGER UNSIGNED, -- id of record in assets table
quantity BIGINT,
action TEXT,
-- event TEXT,
event_id INTEGER UNSIGNED -- id of record in index_transactions
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE INDEX tx_index ON debits (tx_index);
Expand Down
54 changes: 25 additions & 29 deletions sql/dispensers.sql
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
DROP TABLE IF EXISTS dispensers;
CREATE TABLE dispensers (
tx_index INTEGER UNSIGNED,
-- tx_hash TEXT,
tx_hash_id INTEGER UNSIGNED, -- id of record in index_transactions
block_index INTEGER UNSIGNED,
-- source TEXT,
source_id INTEGER UNSIGNED, -- id of record in index_addresses
-- asset TEXT,
asset_id INTEGER UNSIGNED, -- id of record in assets table
give_quantity BIGINT, -- Tokens to vend per dispense
escrow_quantity BIGINT, -- Tokens to escrow in dispenser
satoshirate BIGINT, -- Bitcoin satoshis required per dispense
give_remaining BIGINT,
oracle_address_id INTEGER UNSIGNED, -- id of record in index_addresses table
last_status_tx_hash_id INTEGER UNSIGNED, -- id of record in index_transactions
origin_id INTEGER UNSIGNED, -- id of record in index_addresses
closing_reason TEXT,
status TEXT,
dispense_count INTEGER DEFAULT 0,
last_status_tx_source_id INTEGER UNSIGNED,
close_block_index INTEGER UNSIGNED
tx_index INTEGER UNSIGNED,
-- tx_hash TEXT,
tx_hash_id INTEGER UNSIGNED, -- id of record in index_transactions
block_index INTEGER UNSIGNED,
-- source TEXT,
source_id INTEGER UNSIGNED, -- id of record in index_addresses
-- asset TEXT,
asset_id INTEGER UNSIGNED, -- id of record in assets table
give_quantity BIGINT, -- Tokens to vend per dispense
escrow_quantity BIGINT, -- Tokens to escrow in dispenser
satoshirate BIGINT, -- Bitcoin satoshis required per dispense
give_remaining BIGINT,
oracle_address_id INTEGER UNSIGNED, -- id of record in index_addresses table
last_status_tx_hash_id INTEGER UNSIGNED, -- id of record in index_transactions
origin_id INTEGER UNSIGNED, -- id of record in index_addresses
closing_reason TEXT,
status TEXT
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE UNIQUE INDEX tx_index ON dispensers (tx_index);
CREATE INDEX tx_hash_id ON dispensers (tx_hash_id);
CREATE INDEX block_index ON dispensers (block_index);
CREATE INDEX source_id ON dispensers (source_id);
CREATE INDEX asset_id ON dispensers (asset_id);
CREATE INDEX oracle_address_id ON dispensers (oracle_address_id);
CREATE INDEX last_status_tx_hash_id ON dispensers (last_status_tx_hash_id);
CREATE INDEX origin_id ON dispensers (origin_id);
CREATE INDEX last_status_tx_source_id ON dispensers (last_status_tx_source_id);
CREATE UNIQUE INDEX tx_index ON dispensers (tx_index);
CREATE INDEX tx_hash_id ON dispensers (tx_hash_id);
CREATE INDEX block_index ON dispensers (block_index);
CREATE INDEX source_id ON dispensers (source_id);
CREATE INDEX asset_id ON dispensers (asset_id);
CREATE INDEX oracle_address_id ON dispensers (oracle_address_id);
CREATE INDEX last_status_tx_hash_id ON dispensers (last_status_tx_hash_id);
CREATE INDEX origin_id ON dispensers (origin_id);
3 changes: 1 addition & 2 deletions sql/dispenses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ CREATE TABLE dispenses (
asset_id INTEGER UNSIGNED, -- id of record in assets table
dispense_quantity BIGINT UNSIGNED,
-- dispenser_tx_hash TEXT
dispenser_tx_hash_id INTEGER UNSIGNED, -- id of record in index_transactions
btc_amount INTEGER UNSIGNED DEFAULT 0
dispenser_tx_hash_id INTEGER UNSIGNED -- id of record in index_transactions
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE INDEX block_index ON dispenses (block_index);
Expand Down
42 changes: 0 additions & 42 deletions sql/fairminters.sql

This file was deleted.

Loading

0 comments on commit a8c03b5

Please sign in to comment.