Browse Source

use kevaGroupFilter as tmp solution for #10

main
ghost 10 months ago
parent
commit
ab7c76abbd
  1. 2
      composer.json
  2. 85
      src/index.php

2
composer.json

@ -3,7 +3,7 @@
"description": "KVAZAR Index Crawler", "description": "KVAZAR Index Crawler",
"type": "project", "type": "project",
"require": { "require": {
"kevachat/kevacoin": "^1.6", "kevachat/kevacoin": "^1.10",
"kvazar/crypto": "dev-main", "kvazar/crypto": "dev-main",
"kvazar/index": "dev-main" "kvazar/index": "dev-main"
}, },

85
src/index.php

@ -273,50 +273,63 @@ for ($block = $state + 1; $block <= $blocks; $block++)
// Operation ID required to continue // Operation ID required to continue
if (empty($asm[0])) if (empty($asm[0]))
{ {
continue; exit(
sprintf(
_('Undefined operation of transaction "%s" in block "%d"!'),
$transaction,
$block
)
);
} }
// Detect key / value // Detect key / value
switch ($asm[0]) { switch ($asm[0]) {
case 'OP_KEVA_PUT': 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( $namespace = \Kvazar\Crypto\Base58::encode(
$asm[1], false, 0, false $asm[1],
false,
0,
false
); );
$key = \Kvazar\Crypto\Kevacoin::decode( // Find all data by namespace
$asm[2] foreach ((array) $kevacoin->kevaGroupFilter( // @TODO complete \Kvazar\Crypto\Kevacoin to decode tx faster
); $namespace
) as $record)
$value = \Kvazar\Crypto\Kevacoin::decode(
$asm[3]
);
break;
case 'OP_KEVA_NAMESPACE':
if (empty($asm[1]) || empty($asm[2]))
{ {
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; break;
// @TODO not in use at this moment // @TODO not in use at this moment
@ -326,33 +339,19 @@ for ($block = $state + 1; $block <= $blocks; $block++)
case 'OP_DUP': case 'OP_DUP':
case 'OP_NOP': case 'OP_NOP':
continue 2;
break; break;
default: default:
exit( exit(
sprintf( sprintf(
_('Undefined operation "%s" of transaction "%s" in block "%d"!'), _('Unknown operation "%s" of transaction "%s" in block "%d"!'),
$asm[0], $asm[0],
$transaction, $transaction,
$block $block
) )
); );
} }
// Add index record
$index->add(
$raw['time'],
$raw['size'],
$block,
$namespace,
$raw['txid'],
$asm[0],
$key,
$value
);
} }
} }

Loading…
Cancel
Save