Update sdk #17
3 changed files with 65 additions and 51 deletions
|
@ -148,9 +148,9 @@ class LBRY_Admin
|
|||
*/
|
||||
public function wallet_callback()
|
||||
{
|
||||
// Get first available address from Daemon
|
||||
// Get first available account address from Daemon
|
||||
$address = LBRY()->daemon->address_list();
|
||||
$address = is_array($address) && !empty($address) ? $address[0] : '';
|
||||
$address = is_array($address) && !empty($address) ? $address[0]->address : '';
|
||||
printf(
|
||||
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" readonly />',
|
||||
LBRY_WALLET,
|
||||
|
|
|
@ -45,15 +45,21 @@ class LBRY_Daemon
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns an array of Address lists
|
||||
* Returns an paginated array of Address lists
|
||||
* https://lbry.tech/api/sdk#address_list
|
||||
* @param int $page Pagination page number
|
||||
* @return array Array of address lists linked to this account
|
||||
*/
|
||||
public function address_list()
|
||||
public function address_list($page = 1)
|
||||
{
|
||||
// Get 20 per page
|
||||
$params = array(
|
||||
'page' => $page,
|
||||
'page_size' => 20
|
||||
);
|
||||
try {
|
||||
$result = $this->request('address_list');
|
||||
return $result->result;
|
||||
$result = $this->request('address_list', $params);
|
||||
return $result->result->items;
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('address_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
LBRY()->notice->set_notice('error', 'Issue getting address list.');
|
||||
|
@ -62,7 +68,7 @@ class LBRY_Daemon
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the balance of a current LBRY account
|
||||
* Returns the available balance of a current LBRY account
|
||||
* https://lbry.tech/api/sdk#account_balance
|
||||
* @param string $address Wallet Address
|
||||
* @return float Wallet Balance
|
||||
|
@ -71,7 +77,7 @@ class LBRY_Daemon
|
|||
{
|
||||
try {
|
||||
$result = $this->request('account_balance');
|
||||
return $result->result;
|
||||
return $result->result->available;
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('account_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
LBRY()->notice->set_notice('error', 'Issue getting account balance.');
|
||||
|
@ -82,12 +88,18 @@ class LBRY_Daemon
|
|||
/**
|
||||
* Returns a list of channels for this account
|
||||
* https://lbry.tech/api/sdk#channel_list
|
||||
* @param int $page Pagination page number
|
||||
* @return array claim dictionary or null if empty
|
||||
*/
|
||||
public function channel_list()
|
||||
public function channel_list($page = 1)
|
||||
{
|
||||
$params = array(
|
||||
'page' => $page,
|
||||
'page_size' => 20
|
||||
);
|
||||
|
||||
try {
|
||||
$result = $this->request('channel_list')->result;
|
||||
$result = $this->request('channel_list', $params)->result->items;
|
||||
return empty($result) ? null : $result;
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('channel_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
|
@ -98,7 +110,7 @@ class LBRY_Daemon
|
|||
|
||||
/**
|
||||
* Create a claim for a new channel
|
||||
* https://lbry.tech/api/sdk#channel_new
|
||||
* https://lbry.tech/api/sdk#channel_create
|
||||
* @return array dictionary containing result of the request
|
||||
*/
|
||||
public function channel_new($channel_name, $bid_amount)
|
||||
|
@ -118,16 +130,16 @@ class LBRY_Daemon
|
|||
|
||||
try {
|
||||
$result = $this->request(
|
||||
'channel_new',
|
||||
'channel_create',
|
||||
array(
|
||||
'channel_name' => $channel_name,
|
||||
'amount' => number_format(floatval($bid_amount), 2, '.', '')
|
||||
'name' => $channel_name,
|
||||
'bid' => number_format(floatval($bid_amount), 2, '.', '')
|
||||
)
|
||||
);
|
||||
return $result->result;
|
||||
} catch (LBRYDaemonException $e) {
|
||||
$this->logger->log('channel_new error', $e->getMessage() . ' | Code: ' . $e->getCode());
|
||||
LBRY()->notice->set_notice('error', 'Issue creating new channel.');
|
||||
throw new \Exception('Issue creating new channel.', 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,17 +21,19 @@ class LBRY_Network_Publisher
|
|||
$converted = LBRY()->network->parser->convert_to_markdown($post);
|
||||
$write_status = $file && fwrite($file, $converted);
|
||||
fclose($file);
|
||||
$endtime = microtime(true);
|
||||
|
||||
try {
|
||||
if (!$write_status) {
|
||||
throw new \Exception('Write Status failure', 1);
|
||||
}
|
||||
|
||||
// If everything went well with the conversion, carry on
|
||||
if ($write_status) {
|
||||
$args = array(
|
||||
'name' => $post->post_name,
|
||||
'bid' => number_format(floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]), 2, '.', ''),
|
||||
'file_path' => $filepath,
|
||||
'title' => $post->post_title,
|
||||
'language' => substr(get_locale(), 0, 2),
|
||||
'languages' => array(substr(get_locale(), 0, 2)),
|
||||
'license' => get_option(LBRY_SETTINGS)[LBRY_LICENSE]
|
||||
);
|
||||
|
||||
|
@ -45,7 +47,7 @@ class LBRY_Network_Publisher
|
|||
$featured_image = wp_get_attachment_image_src($featured_id, 'medium');
|
||||
|
||||
if ($featured_image[0]) {
|
||||
$args['thumbnail'] = $featured_image[0];
|
||||
$args['thumbnail_url'] = $featured_image[0];
|
||||
}
|
||||
|
||||
// Build description using Yoast if installed and its used, excerpt/title otherwise
|
||||
|
@ -62,10 +64,10 @@ class LBRY_Network_Publisher
|
|||
$args['description'] = $description;
|
||||
|
||||
$result = LBRY()->daemon->publish($args);
|
||||
if ($result->success) {
|
||||
error_log(print_r($result, true));
|
||||
update_post_meta($post->ID, LBRY_PERM_URL, $result->output->permanent_url);
|
||||
}
|
||||
$outputs = $result->outputs;
|
||||
|
||||
if ($outputs && is_array($outputs)) {
|
||||
update_post_meta($post->ID, LBRY_PERM_URL, $result->outputs[0]->permanent_url);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
error_log('Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage());
|
||||
|
|
Loading…
Reference in a new issue