phpkevacoinblockchainkevacoin-apicliblockchain-fsdistributed-storagedecentralized-storageblockchain-storagecli-appclitor-phpclitor
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
154 lines
2.4 KiB
154 lines
2.4 KiB
12 months ago
|
<?php
|
||
|
|
||
|
// Init helper
|
||
|
function _exec(
|
||
|
string $processor,
|
||
|
string $command
|
||
|
): mixed
|
||
|
{
|
||
|
if (false !== exec(sprintf('%s %s', $processor, $command), $output))
|
||
|
{
|
||
|
$rows = [];
|
||
|
|
||
|
foreach($output as $row)
|
||
|
{
|
||
|
$rows[] = $row;
|
||
|
}
|
||
|
|
||
|
if ($result = @json_decode(implode(PHP_EOL, $rows)))
|
||
|
{
|
||
|
return $result;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
12 months ago
|
// Get clitoris
|
||
|
$clitoris = _exec(
|
||
12 months ago
|
$argv[1],
|
||
|
sprintf(
|
||
12 months ago
|
'%s %s "_CLITOR_IS_"',
|
||
|
'keva_get',
|
||
12 months ago
|
$argv[2]
|
||
|
)
|
||
|
);
|
||
|
|
||
12 months ago
|
print_r(
|
||
|
$clitoris
|
||
|
);
|
||
12 months ago
|
|
||
12 months ago
|
if (empty($clitoris->value))
|
||
12 months ago
|
{
|
||
12 months ago
|
exit(
|
||
|
sprintf(
|
||
|
'%s does not contain _CLITOR_IS_' . PHP_EOL,
|
||
|
$argv[2]
|
||
|
)
|
||
|
);
|
||
12 months ago
|
}
|
||
|
|
||
12 months ago
|
if (!$clitoris = @json_decode(
|
||
|
$clitoris->value
|
||
|
))
|
||
|
{
|
||
|
exit(
|
||
|
sprintf(
|
||
|
'could not decode _CLITOR_IS_ of %s' . PHP_EOL,
|
||
|
$argv[2]
|
||
|
)
|
||
|
);
|
||
|
}
|
||
12 months ago
|
|
||
12 months ago
|
if ($clitoris->version !== '1.0.0')
|
||
12 months ago
|
{
|
||
|
exit(
|
||
|
sprintf(
|
||
|
'_CLITOR_IS_ of %s not compatible!' . PHP_EOL,
|
||
|
$argv[2]
|
||
|
)
|
||
|
);
|
||
|
}
|
||
12 months ago
|
|
||
12 months ago
|
if (empty($clitoris->file->name))
|
||
|
{
|
||
|
exit(
|
||
|
sprintf(
|
||
|
'_CLITOR_IS_ format issue for %s!' . PHP_EOL,
|
||
|
$argv[2]
|
||
|
)
|
||
|
);
|
||
|
}
|
||
12 months ago
|
|
||
|
// Merge content data
|
||
12 months ago
|
$chain = [];
|
||
12 months ago
|
foreach (
|
||
12 months ago
|
(array)
|
||
12 months ago
|
_exec(
|
||
|
$argv[1],
|
||
|
sprintf(
|
||
|
'%s %s "\d+"',
|
||
|
'keva_filter',
|
||
|
$argv[2]
|
||
|
)
|
||
|
) as $piece)
|
||
12 months ago
|
{
|
||
12 months ago
|
if (
|
||
|
!isset($piece->key) ||
|
||
|
!isset($piece->value) ||
|
||
|
!isset($piece->height)
|
||
|
)
|
||
12 months ago
|
{
|
||
|
exit(
|
||
|
'please wait for all pieces sending complete!'
|
||
|
);
|
||
|
}
|
||
|
|
||
12 months ago
|
// Keep all key versions in memory
|
||
|
$chain[$piece->key][$piece->height] = $piece->value;
|
||
12 months ago
|
|
||
|
print_r(
|
||
|
$piece
|
||
|
);
|
||
12 months ago
|
}
|
||
|
|
||
12 months ago
|
// Select last piece value by it max block height
|
||
|
//
|
||
|
// piece could have many of versions (with same key)
|
||
|
// this feature related to data reading correction after recovery #1
|
||
|
|
||
|
$pieces = [];
|
||
|
|
||
|
foreach ($chain as $key => $height)
|
||
|
{
|
||
|
|
||
|
ksort(
|
||
|
$height
|
||
|
);
|
||
|
|
||
|
$pieces[$key] = $height[array_key_last($height)];
|
||
|
}
|
||
|
|
||
12 months ago
|
ksort(
|
||
|
$pieces
|
||
|
);
|
||
12 months ago
|
|
||
12 months ago
|
// Save file to destination
|
||
12 months ago
|
$filename = isset($argv[3]) ? $argv[3] : sprintf(
|
||
12 months ago
|
'%s/../data/import/[kevacoin][%s]%s',
|
||
12 months ago
|
__DIR__,
|
||
|
$argv[2],
|
||
12 months ago
|
$clitoris->file->name
|
||
12 months ago
|
);
|
||
|
|
||
|
file_put_contents(
|
||
|
$filename,
|
||
|
base64_decode(
|
||
12 months ago
|
implode('', $pieces)
|
||
12 months ago
|
)
|
||
|
);
|
||
|
|
||
|
echo sprintf(
|
||
|
'saved to %s' . PHP_EOL,
|
||
|
$filename
|
||
|
);
|