phpkevacoinblockchainkevacoin-apicliclitor-phpclitorblockchain-fsdistributed-storagedecentralized-storageblockchain-storagecli-app
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.
156 lines
3.2 KiB
156 lines
3.2 KiB
1 year 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;
|
||
|
}
|
||
|
|
||
1 year ago
|
// Check file exits
|
||
|
if (!file_exists($argv[2]))
|
||
|
{
|
||
|
exit('filename does not exist!' . PHP_EOL);
|
||
|
}
|
||
|
|
||
|
// Get file hash sum
|
||
|
$md5file = md5_file(
|
||
|
$argv[2]
|
||
|
);
|
||
|
|
||
|
// Split content to smaller parts, according to the protocol limits
|
||
|
$size = isset($argv[3]) && $argv[3] <= 3072 ? (int) $argv[3] : 3072;
|
||
|
|
||
|
$pieces = str_split(
|
||
|
base64_encode(
|
||
|
file_get_contents(
|
||
|
$argv[2]
|
||
|
)
|
||
|
),
|
||
|
$size
|
||
|
);
|
||
|
|
||
|
// Count total pieces
|
||
|
$total = count(
|
||
|
$pieces
|
||
|
);
|
||
|
|
||
|
// Get software protocol details
|
||
|
$software = _exec(
|
||
|
$argv[1],
|
||
|
'-getinfo'
|
||
|
);
|
||
|
|
||
|
print_r($software);
|
||
|
|
||
|
// Create namespace to collect there data pieces
|
||
|
$ns = _exec(
|
||
1 year ago
|
$argv[1],
|
||
|
sprintf(
|
||
1 year ago
|
"%s '%s'",
|
||
1 year ago
|
'keva_namespace',
|
||
1 year ago
|
$md5file
|
||
1 year ago
|
)
|
||
|
);
|
||
|
|
||
1 year ago
|
print_r($ns);
|
||
1 year ago
|
|
||
1 year ago
|
// Create meta description for the future generations
|
||
|
print_r(
|
||
|
_exec(
|
||
|
$argv[1],
|
||
|
sprintf(
|
||
|
"%s %s '%s' '%s'",
|
||
|
'keva_put',
|
||
|
$ns->namespaceId,
|
||
|
'_CLITOR_IS_',
|
||
|
json_encode(
|
||
|
[
|
||
1 year ago
|
'version' => '1.0.0',
|
||
1 year ago
|
'model' =>
|
||
|
[
|
||
|
'name' => 'kevacoin',
|
||
|
'software' =>
|
||
|
[
|
||
|
'version' => $software->version,
|
||
|
'protocol' => $software->protocolversion
|
||
1 year ago
|
],
|
||
|
'namespace' => $ns->namespaceId
|
||
1 year ago
|
],
|
||
|
'pieces' =>
|
||
|
[
|
||
|
'total' => $total,
|
||
|
'size' => $size,
|
||
|
],
|
||
|
'file' =>
|
||
|
[
|
||
|
'name' => basename(
|
||
|
$argv[2]
|
||
|
),
|
||
|
'mime' => mime_content_type(
|
||
|
$argv[2]
|
||
|
),
|
||
|
'size' => filesize(
|
||
|
$argv[2]
|
||
|
),
|
||
|
'md5' => $md5file
|
||
|
]
|
||
|
]
|
||
|
)
|
||
|
)
|
||
|
)
|
||
|
);
|
||
1 year ago
|
|
||
1 year ago
|
// Begin pieces saving
|
||
|
foreach ($pieces as $key => $value)
|
||
|
{
|
||
|
print_r(
|
||
|
_exec(
|
||
1 year ago
|
$argv[1],
|
||
|
sprintf(
|
||
1 year ago
|
"%s '%s' '%s' '%s'",
|
||
1 year ago
|
'keva_put',
|
||
1 year ago
|
$ns->namespaceId,
|
||
1 year ago
|
$key,
|
||
|
$value
|
||
|
)
|
||
1 year ago
|
)
|
||
|
);
|
||
1 year ago
|
|
||
1 year ago
|
// Apply delays to prevent too-long-mempool-chain reject
|
||
|
$delay = isset($argv[4]) && $argv[4] > 0 ? (int) $argv[4] : 60;
|
||
1 year ago
|
|
||
|
echo sprintf(
|
||
1 year ago
|
'%s/%s sent, waiting %s seconds...' . PHP_EOL,
|
||
|
$key + 1,
|
||
|
$total,
|
||
|
$delay
|
||
1 year ago
|
);
|
||
1 year ago
|
|
||
|
sleep($delay);
|
||
|
}
|
||
|
|
||
|
// Print result
|
||
|
echo sprintf(
|
||
12 months ago
|
'done! run to extract: php %s/get.php %s %s' . PHP_EOL,
|
||
|
__DIR__,
|
||
1 year ago
|
$argv[1],
|
||
|
$ns->namespaceId
|
||
|
);
|