Merged in daemon_upgrade (pull request #10)

Updated to v 0.3.0 dameon api
This commit is contained in:
Paul Kirby 2018-11-06 21:05:48 +00:00
commit 334af6183a
4 changed files with 60 additions and 34 deletions

View file

@ -116,11 +116,14 @@ class LBRY_Admin
*/
public function wallet_callback()
{
// Get first available address from Daemon
$address = LBRY()->daemon->address_list();
$address = is_array($address) && !empty($address) ? $address[0] : '';
printf(
'<input type="text" id="%1$s" name="%2$s[%1$s]" value="%3$s" readonly />',
LBRY_WALLET,
LBRY_SETTINGS,
isset($this->options[LBRY_WALLET]) ? esc_attr($this->options[LBRY_WALLET]) : ''
$address
);
}
@ -145,7 +148,8 @@ class LBRY_Admin
// TODO: Maybe make this more elegant?
$options = '';
// Create options list, select current license
foreach (LBRY_AVAILABLE_LICENSES as $value => $name) {
//
foreach (LBRY()->licenses as $value => $name) {
$selected = $this->options[LBRY_LICENSE] === $value;
$options .= '<option value="' . $value . '"';

View file

@ -25,42 +25,60 @@ class LBRY_Daemon
}
/**
* Returns an unused wallet address
* https://lbryio.github.io/lbry/#wallet_unused_address
* Returns an unused address
* https://lbry.tech/api/sdk#address_unused
* @return string Unused wallet address in base58
*/
public function wallet_unused_address()
{
try {
$result = $this->request('wallet_unused_address');
$result = $this->request('address_unused');
return $result->result;
} catch (LBRYDaemonException $e) {
$this->logger->log('wallet_unused_address error', $e->getMessage() . ' | Code: ' . $e->getCode());
LBRY()->notice->set_notice('error', 'Issue getting unused wallet address.');
$this->logger->log('address_unused error', $e->getMessage() . ' | Code: ' . $e->getCode());
LBRY()->notice->set_notice('error', 'Issue getting unused address.');
return;
}
}
/**
* Returns the balance of a current LBRY wallet
* https://lbryio.github.io/lbry/cli/#wallet_balance
* Returns an array of Address lists
* https://lbry.tech/api/sdk#address_list
* @return array Array of address lists linked to this account
*/
public function address_list()
{
try {
$result = $this->request('address_list');
return $result->result;
} catch (LBRYDaemonException $e) {
$this->logger->log('address_list error', $e->getMessage() . ' | Code: ' . $e->getCode());
LBRY()->notice->set_notice('error', 'Issue getting address list.');
return;
}
}
/**
* Returns the balance of a current LBRY account
* https://lbry.tech/api/sdk#account_balance
* @param string $address Wallet Address
* @return float Wallet Balance
*/
public function wallet_balance()
{
try {
$result = $this->request('wallet_balance');
$result = $this->request('account_balance');
return $result->result;
} catch (LBRYDaemonException $e) {
$this->logger->log('wallet_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
LBRY()->notice->set_notice('error', 'Issue getting wallet address.');
$this->logger->log('account_balance error', $e->getMessage() . ' | Code: ' . $e->getCode());
LBRY()->notice->set_notice('error', 'Issue getting account balance.');
return;
}
}
/**
* https://lbryio.github.io/lbry/#channel_list
* Returns a list of channels for this account
* https://lbry.tech/api/sdk#channel_list
* @return array claim dictionary or null if empty
*/
public function channel_list()
@ -76,7 +94,8 @@ class LBRY_Daemon
}
/**
* https://lbryio.github.io/lbry/#channel_new
* Create a claim for a new channel
* https://lbry.tech/api/sdk#channel_new
* @return array dictionary containing result of the request
*/
public function channel_new($channel_name, $bid_amount)
@ -100,7 +119,7 @@ class LBRY_Daemon
'channel_new',
array(
'channel_name' => $channel_name,
'amount' => floatval($bid_amount)
'amount' => number_format(floatval($bid_amount), 2, '.', '')
)
);
return $result->result;
@ -113,6 +132,7 @@ class LBRY_Daemon
/**
* Publishes a post to the LBRY Network
* https://lbry.tech/api/sdk#publish
* @param string $name The slug for the post
* @param float $bid The amount of LBC to bid
* @param string $filepath The path of the temporary content file
@ -121,7 +141,7 @@ class LBRY_Daemon
* @param string $language Two letter ISO Code of the language
* @return string $channel The Claim ID of the Channel
*/
public function publish($name, $bid, $filepath, $title, $description, $language, $channel, $thumbnail = false)
public function publish($name, $bid, $filepath, $title, $description, $language, $license, $channel, $thumbnail = false)
{
$args = array(
'name' => $name,
@ -130,6 +150,7 @@ class LBRY_Daemon
'title' => $title,
'description' => $description,
'language' => $language,
'license' => $license,
);
// Make sure we aren't publishing to unattributed

View file

@ -39,7 +39,7 @@ class LBRY_Network_Publisher
// If everything went well with the conversion, carry on
if ($write_status) {
$name = $post->post_name;
$bid = floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]);
$bid = number_format(floatval(get_option(LBRY_SETTINGS)[LBRY_LBC_PUBLISH]), 2, '.', '');
$title = $post->post_title;
$language = substr(get_locale(), 0, 2);
$license = get_option(LBRY_SETTINGS)[LBRY_LICENSE];
@ -60,7 +60,8 @@ class LBRY_Network_Publisher
}
$description .= ' | Originally published at ' . get_permalink($post);
LBRY()->daemon->publish($name, $bid, $filepath, $title, $description, $language, $channel, $thumbnail);
//TODO: Switch this to an array of args. This is getting out of hand.
LBRY()->daemon->publish($name, $bid, $filepath, $title, $description, $language, $license, $channel, $thumbnail);
}
} catch (Exception $e) {
error_log('Issue publishing post ' . $post->ID . ' to LBRY: ' . $e->getMessage());

View file

@ -43,6 +43,20 @@ class LBRYPress
*/
public $network = null;
/**
* The Licenses Available
*/
public $licenses = array(
'Creative Commons Attribution 4.0 International' => 'Creative Commons Attribution 4.0 International',
'Creative Commons Attribution-ShareAlike 4.0 International' => 'Creative Commons Attribution-ShareAlike 4.0 International',
'Creative Commons Attribution-NoDerivatives 4.0 International' => 'Creative Commons Attribution-NoDerivatives 4.0 International',
'Creative Commons Attribution-NonCommercial 4.0 International' => 'Creative Commons Attribution-NonCommercial 4.0 International',
'Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International' => 'Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International',
'Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International' => 'Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International',
'Copyrighted' => 'Copyrighted',
'Public Domain' => 'Public Domain'
);
/**
* Main LBRYPress Instance.
*
@ -103,16 +117,6 @@ class LBRYPress
$this->define('LBRY_LBC_PUBLISH', 'lbry_lbc_publish'); // amount of lbc to use per publish
$this->define('LBRY_WILL_PUBLISH', 'lbry_will_publish'); // The meta key for if to publish to LBRY Network or not
$this->define('LBRY_POST_CHANNEL', 'lbry_channel'); // The meta key for which channel to publish
$this->define('LBRY_AVAILABLE_LICENSES', array(
'Creative Commons Attribution 4.0 International' => 'Creative Commons Attribution 4.0 International',
'Creative Commons Attribution-ShareAlike 4.0 International' => 'Creative Commons Attribution-ShareAlike 4.0 International',
'Creative Commons Attribution-NoDerivatives 4.0 International' => 'Creative Commons Attribution-NoDerivatives 4.0 International',
'Creative Commons Attribution-NonCommercial 4.0 International' => 'Creative Commons Attribution-NonCommercial 4.0 International',
'Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International' => 'Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International',
'Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International' => 'Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International',
'Copyrighted' => 'Copyrighted',
'Public Domain' => 'Public Domain'
));
}
/**
@ -166,15 +170,11 @@ class LBRYPress
// Add options to the options table we need
if (! get_option(LBRY_SETTINGS)) {
// Get a wallet address
// TODO: May have to rethink this based on how wallet address are linked to daemon
$wallet_address = $this->daemon->wallet_unused_address();
// Default options
$option_defaults = array(
LBRY_WALLET => $wallet_address,
LBRY_SPEECH => null,
LBRY_LICENSE => 'mit',
LBRY_LICENSE => $this->licenses[0],
LBRY_LBC_PUBLISH => 1
);
@ -199,7 +199,7 @@ class LBRYPress
public function deactivate()
{
// TODO: Stop the daemon
error_log('Deactivated');
error_log('Deactivated LBRYPress');
}
public function published_on_lbry_banner($content)