Skip to content

Commit

Permalink
Merge pull request #15 from jdogresorg/counterparty-2.0
Browse files Browse the repository at this point in the history
counterparty 2.0 updates
  • Loading branch information
jdogresorg authored Nov 8, 2024
2 parents 10d3052 + b509bbe commit d09cc23
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 175 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ cat sql/*.sql | mysql Counterparty_Testnet

Bootstrap Information
---
- [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)
- [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)

Command line arguments
---
Expand All @@ -54,6 +54,7 @@ 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 @@ -70,6 +71,8 @@ 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: 17 additions & 14 deletions counterparty2mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
'dispenses',
'dividends',
'executions',
'fairminters',
'fairmints',
'issuances',
'index_tx',
'messages',
Expand Down Expand Up @@ -107,9 +109,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');
$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_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_contract = array('contract_id');

// Loop through the blocks until we are current
Expand Down Expand Up @@ -165,7 +167,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]))
if(isset($obj->tx_index) && isset($obj->block_index) && isset($transactions[$obj->tx_hash]) && $msg->category!='transactions' && $msg->category!='transaction_outputs')
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 @@ -185,8 +187,8 @@
$bindings = json_decode($msg->bindings);
$command = $msg->command;

// v10.0.0 - Ignore certain messages for now
if(in_array($table,array('assets', 'blocks','transactions','transaction_outputs')))
// 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')))
continue;

// Build out array of fields and values
Expand Down Expand Up @@ -269,9 +271,6 @@
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 @@ -351,7 +350,7 @@
$sql = rtrim($sql, " AND");
$sqlUpdate = rtrim($sqlUpdate, " AND");

// print $sql;
// print "{$sql}\n";
$results = $mysqli->query($sql);
if($results){
//on duplicate key statement will update the row if exists already
Expand All @@ -372,7 +371,7 @@
$where = "";
foreach($fields as $index => $field){
// Update bets and orders records using tx_hash
if(in_array($table,array('orders','bets','dispensers')) && $field=='tx_hash_id'){
if(in_array($table,array('orders','bets','dispensers','fairminters')) && $field=='tx_hash_id'){
if($where!="")
$where .= " AND ";
$where .= " tx_hash_id='{$values[$index]}'";
Expand Down Expand Up @@ -400,6 +399,9 @@
} 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 @@ -410,6 +412,7 @@
} 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 @@ -461,9 +464,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
82 changes: 0 additions & 82 deletions misc/fix/fix_block_hashes.php

This file was deleted.

7 changes: 7 additions & 0 deletions sql/address_events.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DROP TABLE IF EXISTS address_events;
CREATE TABLE address_events (
address_id INTEGER UNSIGNED, -- id from index_addresses table
event_index INTEGER UNSIGNED
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE UNIQUE INDEX address_id ON addresses (address_id);
22 changes: 12 additions & 10 deletions sql/debits.sql
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
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
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
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE INDEX tx_index ON debits (tx_index);
Expand Down
54 changes: 29 additions & 25 deletions sql/dispensers.sql
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
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
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
) 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 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);
3 changes: 2 additions & 1 deletion sql/dispenses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ 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
dispenser_tx_hash_id INTEGER UNSIGNED, -- id of record in index_transactions
btc_amount INTEGER UNSIGNED DEFAULT 0
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE INDEX block_index ON dispenses (block_index);
Expand Down
42 changes: 42 additions & 0 deletions sql/fairminters.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
DROP TABLE IF EXISTS fairminters;
CREATE TABLE fairminters (
-- tx_hash TEXT,
tx_hash_id INTEGER UNSIGNED,
tx_index INTEGER UNSIGNED,
block_index INTEGER UNSIGNED,
-- source TEXT,
source_id INTEGER UNSIGNED, -- id of record in index_addresses table
-- asset TEXT,
asset_id INTEGER UNSIGNED, -- id of record in assets table
-- asset_parent TEXT,
asset_parent_id INTEGER UNSIGNED, -- id of record in assets table
asset_longname VARCHAR(255),
description VARCHAR(10000),
price INTEGER UNSIGNED,
quantity_by_price INTEGER UNSIGNED,
hard_cap VARCHAR(250),
burn_payment VARCHAR(250),
max_mint_per_tx VARCHAR(250),
premint_quantity VARCHAR(250),,
start_block INTEGER UNSIGNED,
end_block INTEGER UNSIGNED,
minted_asset_commission_int VARCHAR(250),
soft_cap VARCHAR(250),
soft_cap_deadline_block INTEGER UNSIGNED,
lock_description VARCHAR(250),
lock_quantity VARCHAR(250),
divisible VARCHAR(250),
pre_minted VARCHAR(250),
status VARCHAR(250),
earned_quantity VARCHAR(250),
commission VARCHAR(250),
paid_quantity VARCHAR(250)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE INDEX tx_hash_id ON fairminters (tx_hash_id);
CREATE INDEX block_index ON fairminters (block_index);
CREATE INDEX source_id ON fairminters (source_id);
CREATE INDEX asset_id ON fairminters (asset_id);
CREATE INDEX asset_parent_id ON fairminters (asset_parent_id);
CREATE INDEX asset_longname ON fairminters (asset_longname);
CREATE INDEX status ON fairminters (status);
24 changes: 24 additions & 0 deletions sql/fairmints.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
DROP TABLE IF EXISTS fairmints;
CREATE TABLE fairmints (
-- tx_hash TEXT,
tx_hash_id INTEGER UNSIGNED,
tx_index INTEGER UNSIGNED,
block_index INTEGER UNSIGNED,
-- source TEXT,
source_id INTEGER UNSIGNED, -- id of record in index_addresses table
-- fairminter_tx_hash TEXT,
fairminter_tx_hash_id INTEGER UNSIGNED,
-- asset TEXT,
asset_id INTEGER UNSIGNED, -- id of record in assets table
earn_quantity VARCHAR(250),
paid_quantity VARCHAR(250),
commission VARCHAR(250),
status VARCHAR(250)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

CREATE INDEX tx_hash_id ON fairmints (tx_hash_id);
CREATE INDEX block_index ON fairmints (block_index);
CREATE INDEX source_id ON fairmints (source_id);
CREATE INDEX fairminter_tx_hash_id ON fairmints (fairminter_tx_hash_id);
CREATE INDEX asset_id ON fairmints (asset_id);
CREATE INDEX status ON fairmints (status);
Loading

0 comments on commit d09cc23

Please sign in to comment.