Skip to content

Commit

Permalink
use kevaGroupFilter as tmp solution for #10
Browse files Browse the repository at this point in the history
  • Loading branch information
ghost committed Feb 26, 2024
1 parent d6c6f0e commit ab7c76a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "KVAZAR Index Crawler",
"type": "project",
"require": {
"kevachat/kevacoin": "^1.6",
"kevachat/kevacoin": "^1.10",
"kvazar/crypto": "dev-main",
"kvazar/index": "dev-main"
},
Expand Down
85 changes: 42 additions & 43 deletions src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,50 +273,63 @@
// Operation ID required to continue
if (empty($asm[0]))
{
continue;
exit(
sprintf(
_('Undefined operation of transaction "%s" in block "%d"!'),
$transaction,
$block
)
);
}

// Detect key / value
switch ($asm[0]) {

case 'OP_KEVA_PUT':
case 'OP_KEVA_NAMESPACE':

if (empty($asm[1]) || empty($asm[2]) || empty($asm[3]))
// Namespace info required to continue
if (empty($asm[1]))
{
continue 2;
exit(
sprintf(
_('Undefined namespace of transaction "%s" in block "%d"!'),
$transaction,
$block
)
);
}

// Decode namespace
$namespace = \Kvazar\Crypto\Base58::encode(
$asm[1], false, 0, false
$asm[1],
false,
0,
false
);

$key = \Kvazar\Crypto\Kevacoin::decode(
$asm[2]
);

$value = \Kvazar\Crypto\Kevacoin::decode(
$asm[3]
);

break;

case 'OP_KEVA_NAMESPACE':

if (empty($asm[1]) || empty($asm[2]))
// Find all data by namespace
foreach ((array) $kevacoin->kevaGroupFilter( // @TODO complete \Kvazar\Crypto\Kevacoin to decode tx faster
$namespace
) as $record)
{
continue 2;
// Get current block transactions only
if ($record['height'] == $block)
{
// Register new transaction
$index->add(
$raw['time'],
$raw['size'],
$block,
$namespace,
$raw['txid'],
$asm[0],
$record['key'],
$record['value']
);
}
}

$namespace = \Kvazar\Crypto\Base58::encode(
$asm[1], false, 0, false
);

$key = '_KEVA_NS_';

$value = \Kvazar\Crypto\Kevacoin::decode(
$asm[2]
);

break;

// @TODO not in use at this moment
Expand All @@ -326,33 +339,19 @@
case 'OP_DUP':
case 'OP_NOP':

continue 2;

break;

default:

exit(
sprintf(
_('Undefined operation "%s" of transaction "%s" in block "%d"!'),
_('Unknown operation "%s" of transaction "%s" in block "%d"!'),
$asm[0],
$transaction,
$block
)
);
}

// Add index record
$index->add(
$raw['time'],
$raw['size'],
$block,
$namespace,
$raw['txid'],
$asm[0],
$key,
$value
);
}
}

Expand Down

0 comments on commit ab7c76a

Please sign in to comment.