Skip to content

Commit 5d9fae0

Browse files
committed
add new witness_update broadcast operation
1 parent a0e86d8 commit 5d9fae0

9 files changed

+272
-11
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ namespace GrapheneNodeClient\Tools\ChainOperations
152152
- transfer
153153
- comment // steem or golos
154154
- content // only viz
155+
- witness_update
155156

156157
```php
157158
<?php

Tools/ChainOperations/ChainOperations.php

+20-10
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ChainOperations
1313
const OPERATION_TRANSFER = 'transfer';
1414
const OPERATION_CUSTOM_JSON = 'custom_json';
1515
const OPERATION_CUSTOM = 'custom';//only for VIZ
16+
const OPERATION_WITNESS_UPDATE = 'witness_update';
1617

1718
/** @var array */
1819
protected static $opMap = [];
@@ -27,17 +28,26 @@ class ChainOperations
2728
public static function getOperationId($chainName, $operationName)
2829
{
2930
if (!isset(self::$opMap[$chainName])) {
30-
if ($chainName === ConnectorInterface::PLATFORM_GOLOS) {
31-
$op = ChainOperationsGolos::IDS;
32-
} elseif ($chainName === ConnectorInterface::PLATFORM_STEEMIT) {
33-
$op = ChainOperationsSteem::IDS;
34-
} elseif ($chainName === ConnectorInterface::PLATFORM_VIZ) {
35-
$op = ChainOperationsViz::IDS;
36-
} elseif ($chainName === ConnectorInterface::PLATFORM_WHALESHARES) {
37-
$op = ChainOperationsWhaleshares::IDS;
38-
} else {
39-
throw new \Exception("There is no operations id's for '{$chainName}'");
31+
switch ($chainName) {
32+
case ConnectorInterface::PLATFORM_GOLOS:
33+
$op = ChainOperationsGolos::IDS;
34+
break;
35+
case ConnectorInterface::PLATFORM_HIVE:
36+
$op = ChainOperationsHive::IDS;
37+
break;
38+
case ConnectorInterface::PLATFORM_STEEMIT:
39+
$op = ChainOperationsSteem::IDS;
40+
break;
41+
case ConnectorInterface::PLATFORM_VIZ:
42+
$op = ChainOperationsViz::IDS;
43+
break;
44+
case ConnectorInterface::PLATFORM_WHALESHARES:
45+
$op = ChainOperationsWhaleshares::IDS;
46+
break;
47+
default:
48+
throw new \Exception("There is no operations id's for '{$chainName}'");
4049
}
50+
4151
self::$opMap[$chainName] = $op;
4252
}
4353

Tools/ChainOperations/ChainOperationsGolos.php

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ChainOperationsGolos
1313
ChainOperations::OPERATION_COMMENT_OPTIONS => 19,
1414
ChainOperations::OPERATION_TRANSFER => 2,
1515
ChainOperations::OPERATION_CUSTOM_JSON => 18,
16+
ChainOperations::OPERATION_WITNESS_UPDATE => 11,
1617
];
1718

1819
const FIELDS_TYPES = [
@@ -51,6 +52,18 @@ class ChainOperationsGolos
5152
'required_posting_auths' => OperationSerializer::TYPE_SET_STRING,
5253
'id' => OperationSerializer::TYPE_STRING,
5354
'json' => OperationSerializer::TYPE_STRING
55+
],
56+
ChainOperations::OPERATION_WITNESS_UPDATE => [
57+
'owner' => OperationSerializer::TYPE_STRING,
58+
'url' => OperationSerializer::TYPE_STRING,
59+
'block_signing_key' => OperationSerializer::TYPE_PUBLIC_KEY,
60+
'props' => OperationSerializer::TYPE_CHAIN_PROPERTIES,
61+
'fee' => OperationSerializer::TYPE_ASSET
62+
],
63+
OperationSerializer::TYPE_CHAIN_PROPERTIES => [
64+
'account_creation_fee' => OperationSerializer::TYPE_ASSET,
65+
'maximum_block_size' => OperationSerializer::TYPE_INT32,
66+
'sbd_interest_rate' => OperationSerializer::TYPE_INT16
5467
]
5568
];
5669
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace GrapheneNodeClient\Tools\ChainOperations;
4+
5+
6+
use GrapheneNodeClient\Connectors\ConnectorInterface;
7+
8+
class ChainOperationsHive
9+
{
10+
const IDS = [
11+
ChainOperations::OPERATION_VOTE => 0,
12+
ChainOperations::OPERATION_COMMENT => 1,
13+
ChainOperations::OPERATION_COMMENT_OPTIONS => 19,
14+
ChainOperations::OPERATION_TRANSFER => 2,
15+
ChainOperations::OPERATION_CUSTOM_JSON => 18,
16+
ChainOperations::OPERATION_WITNESS_UPDATE => 11,
17+
];
18+
19+
const FIELDS_TYPES = [
20+
ChainOperations::OPERATION_VOTE => [
21+
'voter' => OperationSerializer::TYPE_STRING,
22+
'author' => OperationSerializer::TYPE_STRING,
23+
'permlink' => OperationSerializer::TYPE_STRING,
24+
'weight' => OperationSerializer::TYPE_INT16
25+
],
26+
ChainOperations::OPERATION_COMMENT => [
27+
'parent_author' => OperationSerializer::TYPE_STRING,
28+
'parent_permlink' => OperationSerializer::TYPE_STRING,
29+
'author' => OperationSerializer::TYPE_STRING,
30+
'permlink' => OperationSerializer::TYPE_STRING,
31+
'title' => OperationSerializer::TYPE_STRING,
32+
'body' => OperationSerializer::TYPE_STRING,
33+
'json_metadata' => OperationSerializer::TYPE_STRING
34+
],
35+
ChainOperations::OPERATION_COMMENT_OPTIONS => [
36+
'author' => OperationSerializer::TYPE_STRING,
37+
'permlink' => OperationSerializer::TYPE_STRING,
38+
'max_accepted_payout' => OperationSerializer::TYPE_ASSET,
39+
'percent_steem_dollars' => OperationSerializer::TYPE_INT16,
40+
'allow_votes' => OperationSerializer::TYPE_BOOL,
41+
'allow_curation_rewards' => OperationSerializer::TYPE_BOOL,
42+
'extensions' => OperationSerializer::TYPE_SET_EXTENSIONS
43+
],
44+
ChainOperations::OPERATION_TRANSFER => [
45+
'from' => OperationSerializer::TYPE_STRING,
46+
'to' => OperationSerializer::TYPE_STRING,
47+
'amount' => OperationSerializer::TYPE_ASSET,
48+
'memo' => OperationSerializer::TYPE_STRING
49+
],
50+
ChainOperations::OPERATION_CUSTOM_JSON => [
51+
'required_auths' => OperationSerializer::TYPE_SET_STRING,
52+
'required_posting_auths' => OperationSerializer::TYPE_SET_STRING,
53+
'id' => OperationSerializer::TYPE_STRING,
54+
'json' => OperationSerializer::TYPE_STRING
55+
],
56+
ChainOperations::OPERATION_WITNESS_UPDATE => [
57+
'owner' => OperationSerializer::TYPE_STRING,
58+
'url' => OperationSerializer::TYPE_STRING,
59+
'block_signing_key' => OperationSerializer::TYPE_PUBLIC_KEY,
60+
'props' => OperationSerializer::TYPE_CHAIN_PROPERTIES,
61+
'fee' => OperationSerializer::TYPE_ASSET
62+
],
63+
OperationSerializer::TYPE_CHAIN_PROPERTIES => [
64+
'account_creation_fee' => OperationSerializer::TYPE_ASSET,
65+
'maximum_block_size' => OperationSerializer::TYPE_INT32,
66+
'sbd_interest_rate' => OperationSerializer::TYPE_INT16
67+
]
68+
];
69+
}

Tools/ChainOperations/ChainOperationsSteem.php

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ChainOperationsSteem
1313
ChainOperations::OPERATION_COMMENT_OPTIONS => 19,
1414
ChainOperations::OPERATION_TRANSFER => 2,
1515
ChainOperations::OPERATION_CUSTOM_JSON => 18,
16+
ChainOperations::OPERATION_WITNESS_UPDATE => 11,
1617
];
1718

1819
const FIELDS_TYPES = [
@@ -51,6 +52,18 @@ class ChainOperationsSteem
5152
'required_posting_auths' => OperationSerializer::TYPE_SET_STRING,
5253
'id' => OperationSerializer::TYPE_STRING,
5354
'json' => OperationSerializer::TYPE_STRING
55+
],
56+
ChainOperations::OPERATION_WITNESS_UPDATE => [
57+
'owner' => OperationSerializer::TYPE_STRING,
58+
'url' => OperationSerializer::TYPE_STRING,
59+
'block_signing_key' => OperationSerializer::TYPE_PUBLIC_KEY,
60+
'props' => OperationSerializer::TYPE_CHAIN_PROPERTIES,
61+
'fee' => OperationSerializer::TYPE_ASSET
62+
],
63+
OperationSerializer::TYPE_CHAIN_PROPERTIES => [
64+
'account_creation_fee' => OperationSerializer::TYPE_ASSET,
65+
'maximum_block_size' => OperationSerializer::TYPE_INT32,
66+
'sbd_interest_rate' => OperationSerializer::TYPE_INT16
5467
]
5568
];
5669
}

Tools/ChainOperations/ChainOperationsViz.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class ChainOperationsViz
99
{
1010
const IDS = [
1111
ChainOperations::OPERATION_TRANSFER => 2,
12-
ChainOperations::OPERATION_CUSTOM => 10
12+
ChainOperations::OPERATION_CUSTOM => 10,
13+
ChainOperations::OPERATION_WITNESS_UPDATE => 6,
1314
];
1415

1516
const FIELDS_TYPES = [
@@ -24,6 +25,11 @@ class ChainOperationsViz
2425
'required_posting_auths' => OperationSerializer::TYPE_SET_STRING,
2526
'id' => OperationSerializer::TYPE_STRING,
2627
'json' => OperationSerializer::TYPE_STRING
28+
],
29+
ChainOperations::OPERATION_WITNESS_UPDATE => [
30+
'owner' => OperationSerializer::TYPE_STRING,
31+
'url' => OperationSerializer::TYPE_STRING,
32+
'block_signing_key' => OperationSerializer::TYPE_PUBLIC_KEY
2733
]
2834
];
2935
}

Tools/ChainOperations/ChainOperationsWhaleshares.php

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class ChainOperationsWhaleshares
1313
ChainOperations::OPERATION_COMMENT_OPTIONS => 19,
1414
ChainOperations::OPERATION_TRANSFER => 2,
1515
ChainOperations::OPERATION_CUSTOM_JSON => 18,
16+
ChainOperations::OPERATION_WITNESS_UPDATE => 9,
1617
];
1718

1819
const FIELDS_TYPES = [
@@ -51,6 +52,17 @@ class ChainOperationsWhaleshares
5152
'required_posting_auths' => OperationSerializer::TYPE_SET_STRING,
5253
'id' => OperationSerializer::TYPE_STRING,
5354
'json' => OperationSerializer::TYPE_STRING
55+
],
56+
ChainOperations::OPERATION_WITNESS_UPDATE => [
57+
'owner' => OperationSerializer::TYPE_STRING,
58+
'url' => OperationSerializer::TYPE_STRING,
59+
'block_signing_key' => OperationSerializer::TYPE_PUBLIC_KEY,
60+
'props' => OperationSerializer::TYPE_CHAIN_PROPERTIES,
61+
'fee' => OperationSerializer::TYPE_ASSET
62+
],
63+
OperationSerializer::TYPE_CHAIN_PROPERTIES => [
64+
'account_creation_fee' => OperationSerializer::TYPE_ASSET,
65+
'maximum_block_size' => OperationSerializer::TYPE_INT32
5466
]
5567
];
5668
}
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
4+
namespace GrapheneNodeClient\Debug;
5+
6+
use GrapheneNodeClient\Commands\CommandQueryData;
7+
use GrapheneNodeClient\Commands\Single\GetTransactionHexCommand;
8+
use GrapheneNodeClient\Connectors\Http\GolosHttpJsonRpcConnector;
9+
use GrapheneNodeClient\Connectors\Http\SteemitHttpJsonRpcConnector;
10+
use GrapheneNodeClient\Connectors\Http\VizHttpJsonRpcConnector;
11+
use GrapheneNodeClient\Connectors\Http\WhalesharesHttpJsonRpcConnector;
12+
use GrapheneNodeClient\Connectors\WebSocket\GolosWSConnector;
13+
use GrapheneNodeClient\Connectors\WebSocket\SteemitWSConnector;
14+
use GrapheneNodeClient\Connectors\WebSocket\VizWSConnector;
15+
use GrapheneNodeClient\Connectors\WebSocket\WhalesharesWSConnector;
16+
use GrapheneNodeClient\Tools\Transaction;
17+
18+
19+
ini_set('display_errors', 1);
20+
ini_set('display_startup_errors', 1);
21+
error_reporting(E_ALL);
22+
require __DIR__ . '/../../vendor/autoload.php';
23+
24+
echo "\n GetTransactionHex START";
25+
26+
27+
$connector = new GolosWSConnector();
28+
//$connector = new SteemitWSConnector();
29+
//$connector = new VizWSConnector();
30+
//$connector = new WhalesharesWSConnector();
31+
//$connector = new GolosHttpJsonRpcConnector();
32+
//$connector = new SteemitHttpJsonRpcConnector();
33+
//$connector = new VizHttpJsonRpcConnector();
34+
//$connector = new WhalesharesHttpJsonRpcConnector();
35+
36+
37+
//transfer agregation to few users
38+
$chainName = $connector->getPlatform();
39+
/** @var CommandQueryData $tx */
40+
$tx = Transaction::init($connector);
41+
$tx->setParamByKey(
42+
'0:operations:0',
43+
[
44+
'witness_update',
45+
[
46+
'owner' => 't3ran13-miner',
47+
'url' => 'https://golos.io/@t3ran13-miner',
48+
'block_signing_key' => 'GLS7eExwRw2Waqrq7DcC1553revU7MWvjHMqK8sbWGScaBfsThnzN',
49+
'props' =>
50+
[
51+
'account_creation_fee' => '0.001 GOLOS',
52+
'maximum_block_size' => 131072,
53+
'sbd_interest_rate' => 1000
54+
],
55+
'fee' => '0.000 GOLOS'
56+
]
57+
]
58+
);
59+
60+
$command = new GetTransactionHexCommand($connector);
61+
$answer = $command->execute(
62+
$tx
63+
);
64+
65+
66+
67+
echo PHP_EOL . '<pre>' . print_r($answer, true) . '<pre>';
68+
die; //FIXME delete it

examples/Broadcast/WitnessUpdate.php

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
4+
namespace GrapheneNodeClient\examples\Broadcast;
5+
6+
use GrapheneNodeClient\Commands\CommandQueryData;
7+
use GrapheneNodeClient\Commands\Single\BroadcastTransactionSynchronousCommand;
8+
use GrapheneNodeClient\Connectors\Http\GolosHttpJsonRpcConnector;
9+
use GrapheneNodeClient\Connectors\Http\SteemitHttpJsonRpcConnector;
10+
use GrapheneNodeClient\Connectors\Http\VizHttpJsonRpcConnector;
11+
use GrapheneNodeClient\Connectors\Http\WhalesharesHttpJsonRpcConnector;
12+
use GrapheneNodeClient\Connectors\WebSocket\GolosWSConnector;
13+
use GrapheneNodeClient\Connectors\WebSocket\SteemitWSConnector;
14+
use GrapheneNodeClient\Connectors\WebSocket\VizWSConnector;
15+
use GrapheneNodeClient\Connectors\WebSocket\WhalesharesWSConnector;
16+
use GrapheneNodeClient\Tools\Transaction;
17+
18+
19+
ini_set('display_errors', 1);
20+
ini_set('display_startup_errors', 1);
21+
error_reporting(E_ALL);
22+
require __DIR__ . '/../../vendor/autoload.php';
23+
24+
echo "\n WitnessUpdate.php START";
25+
26+
27+
$connector = new GolosWSConnector();
28+
//$connector = new SteemitWSConnector();
29+
//$connector = new VizWSConnector();
30+
//$connector = new WhalesharesWSConnector();
31+
//$connector = new GolosHttpJsonRpcConnector();
32+
//$connector = new SteemitHttpJsonRpcConnector();
33+
//$connector = new VizHttpJsonRpcConnector();
34+
//$connector = new WhalesharesHttpJsonRpcConnector();
35+
36+
37+
//transfer agregation to few users
38+
$chainName = $connector->getPlatform();
39+
/** @var CommandQueryData $tx */
40+
$tx = Transaction::init($connector);
41+
$tx->setParamByKey(
42+
'0:operations:0',
43+
[
44+
'witness_update',
45+
[
46+
'owner' => 'guest123',
47+
'url' => 'https://golos.io/@guest123',
48+
'block_signing_key' => 'GLS7eExwRw2Waqrq7DcC1553revU7MWvjHMqK8sbWGScguest123',
49+
'props' =>
50+
[
51+
'account_creation_fee' => '0.001 GOLOS',
52+
'maximum_block_size' => 131072,
53+
'sbd_interest_rate' => 1000
54+
],
55+
'fee' => '0.000 GOLOS'
56+
]
57+
]
58+
);
59+
Transaction::sign($chainName, $tx, ['active' => '5_active_private_key']);
60+
61+
$command = new BroadcastTransactionSynchronousCommand($connector);
62+
$answer = $command->execute(
63+
$tx
64+
);
65+
66+
67+
68+
echo PHP_EOL . '<pre>' . print_r($answer, true) . '<pre>';
69+
die; //FIXME delete it

0 commit comments

Comments
 (0)