From f598447a8008934448bb69865d4428d56c757794 Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Sat, 17 Oct 2020 21:04:51 +0700
Subject: [PATCH 01/24] Update ChainOperations.php
---
Tools/ChainOperations/ChainOperations.php | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/Tools/ChainOperations/ChainOperations.php b/Tools/ChainOperations/ChainOperations.php
index 5c278e0..de1edbb 100644
--- a/Tools/ChainOperations/ChainOperations.php
+++ b/Tools/ChainOperations/ChainOperations.php
@@ -14,6 +14,12 @@ class ChainOperations
const OPERATION_CUSTOM_JSON = 'custom_json';
const OPERATION_CUSTOM = 'custom';//only for VIZ
const OPERATION_WITNESS_UPDATE = 'witness_update';
+ const OPERATION_TRANSFER_TO_VESTING = 'transfer_to_vesting'; // GOLOS/?/?
+ const OPERATION_WITHDRAW_VESTING = 'withdraw_vesting'; // GOLOS/?/?
+ const OPERATION_CLAIM = 'claim'; // GOLOS
+ const OPERATION_DONATE = 'donate'; // GOLOS
+ const OPERATION_TRANSFER_TO_TIP = 'transfer_to_tip'; // GOLOS
+ const OPERATION_TRANSFER_FROM_TIP = 'transfer_from_tip'; // GOLOS
/** @var array */
protected static $opMap = [];
@@ -57,4 +63,4 @@ public static function getOperationId($chainName, $operationName)
return self::$opMap[$chainName][$operationName];
}
-}
\ No newline at end of file
+}
From 588ae0f1c61a7cf748127cb883c355e910f34779 Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Sat, 17 Oct 2020 21:18:06 +0700
Subject: [PATCH 02/24] Update ChainOperationsGolos.php
---
.../ChainOperations/ChainOperationsGolos.php | 39 ++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/Tools/ChainOperations/ChainOperationsGolos.php b/Tools/ChainOperations/ChainOperationsGolos.php
index 32b5d06..f3fa752 100644
--- a/Tools/ChainOperations/ChainOperationsGolos.php
+++ b/Tools/ChainOperations/ChainOperationsGolos.php
@@ -14,6 +14,13 @@ class ChainOperationsGolos
ChainOperations::OPERATION_TRANSFER => 2,
ChainOperations::OPERATION_CUSTOM_JSON => 18,
ChainOperations::OPERATION_WITNESS_UPDATE => 11,
+ ChainOperations::OPERATION_TRANSFER_TO_VESTING => 3,
+ ChainOperations::OPERATION_WITHDRAW_VESTING => 4,
+ ChainOperations::OPERATION_CLAIM => 53,
+ ChainOperations::OPERATION_DONATE => 54,
+ ChainOperations::OPERATION_TRANSFER_TO_TIP => 55,
+ ChainOperations::OPERATION_TRANSFER_FROM_TIP => 56,
+
];
const FIELDS_TYPES = [
@@ -64,6 +71,36 @@ class ChainOperationsGolos
'account_creation_fee' => OperationSerializer::TYPE_ASSET,
'maximum_block_size' => OperationSerializer::TYPE_INT32,
'sbd_interest_rate' => OperationSerializer::TYPE_INT16
+ ],
+ ChainOperations::OPERATION_TRANSFER_TO_VESTING => [
+ 'from' => OperationSerializer::TYPE_STRING,
+ 'to' => OperationSerializer::TYPE_STRING,
+ 'amount' => OperationSerializer::TYPE_ASSET
+ ],
+ ChainOperations::OPERATION_WITHDRAW_VESTING => [
+ 'account' => OperationSerializer::TYPE_STRING,
+ 'vesting_shares' => OperationSerializer::TYPE_ASSET
+ ],
+ ChainOperations::OPERATION_CLAIM => [
+ 'from' => OperationSerializer::TYPE_STRING,
+ 'to' => OperationSerializer::TYPE_STRING,
+ 'amount' => OperationSerializer::TYPE_ASSET,
+ 'to_vesting' => OperationSerializer::TYPE_BOOL,
+ 'extensions' => OperationSerializer::TYPE_SET_EXTENSIONS
+ ],
+ ChainOperations::OPERATION_TRANSFER_TO_TIP => [
+ 'from' => OperationSerializer::TYPE_STRING,
+ 'to' => OperationSerializer::TYPE_STRING,
+ 'amount' => OperationSerializer::TYPE_ASSET,
+ 'memo' => OperationSerializer::TYPE_STRING,
+ 'extensions' => OperationSerializer::TYPE_SET_EXTENSIONS
+ ],
+ ChainOperations::OPERATION_TRANSFER_FROM_TIP => [
+ 'from' => OperationSerializer::TYPE_STRING,
+ 'to' => OperationSerializer::TYPE_STRING,
+ 'amount' => OperationSerializer::TYPE_ASSET,
+ 'memo' => OperationSerializer::TYPE_STRING,
+ 'extensions' => OperationSerializer::TYPE_SET_EXTENSIONS
]
];
-}
\ No newline at end of file
+}
From 7b2352a9363d8a36a70b363e7603891862b71faf Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Sat, 17 Oct 2020 21:20:39 +0700
Subject: [PATCH 03/24] Create BroadcastTest.php
---
Tests/BroadcastTest.php | 149 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 149 insertions(+)
create mode 100644 Tests/BroadcastTest.php
diff --git a/Tests/BroadcastTest.php b/Tests/BroadcastTest.php
new file mode 100644
index 0000000..ef490c5
--- /dev/null
+++ b/Tests/BroadcastTest.php
@@ -0,0 +1,149 @@
+getPlatform();
+
+// аккаунт для тестов и активный ключ (все операции тестировались с ним)
+$acc="jackvote";
+$wif='5activeKey';
+
+/** @var CommandQueryData $tx */
+$tx = Transaction::init($connector);
+
+// ТЕСТОВЫЕ БЛОКИ
+
+/*
+// TRANSFER
+$tx->setParamByKey(
+ '0:operations:0',
+ [
+ 'transfer',
+ [
+ 'from' => $acc,
+ 'to' => 'jackvote',
+ 'amount' => '1.000 GOLOS',
+ 'memo' => 'Successfully transfer'
+ ]
+ ]
+);
+*/
+
+/*
+// TRANSFER TO VESTING
+$tx->setParamByKey(
+ '0:operations:0',
+ [
+ 'transfer_to_vesting',
+ [
+ 'from' => $acc,
+ 'to' => 'jackvote',
+ 'amount' => '1.000 GOLOS',
+ 'memo' => 'Successfully to vesting'
+ ]
+ ]
+);
+*/
+
+/*
+// WITHDRAW VESTING
+
+// Определяем доступную для вывода СГ
+$command = new Commands($connector);
+$command = $command->get_accounts();
+$commandQuery = new CommandQueryData();
+$commandQuery->setParamByKey('0', [$acc]);
+$content = $command->execute($commandQuery);
+$obj=$content['result'][0];
+$limit=preg_replace("/[^\d.]+/", "", $obj['vesting_shares'])-preg_replace("/[^\d.]+/", "", $obj['delegated_vesting_shares']);
+$limit=sprintf("%01.6f", $limit);
+echo $limit;
+
+//$limit="500.000000"; // TODO не позволяет вывести всё доступное
+
+// '0.000000 GESTS' - для отмены вывода
+
+$tx->setParamByKey(
+ '0:operations:0',
+ [
+ 'withdraw_vesting',
+ [
+ 'account' => $acc,
+ 'vesting_shares' => $limit.' GESTS'
+ ]
+ ]
+);
+*/
+
+/*
+// CLAIM
+$tx->setParamByKey(
+ '0:operations:0',
+ [
+ 'claim',
+ [
+ 'from' => $acc,
+ 'to' => 'tiptoken',
+ 'amount' => '0.100 GOLOS',
+ 'to_vesting' => true, // true - в СГ, false - в TIP
+ 'extensions' => []
+ ]
+ ]
+);
+*/
+
+/*
+// TRANSFER TO TIP - с баланса(!)
+$tx->setParamByKey(
+ '0:operations:0',
+ [
+ 'transfer_to_tip',
+ [
+ 'from' => $acc,
+ 'to' => 'tiptoken',
+ 'amount' => '0.100 GOLOS',
+ 'memo' => 'Successfully to tip',
+ 'extensions' => []
+ ]
+ ]
+);
+*/
+
+// TRANSFER FROM TIP - в СГ (не на баланс!)
+$tx->setParamByKey(
+ '0:operations:0',
+ [
+ 'transfer_from_tip',
+ [
+ 'from' => $acc,
+ 'to' => 'jackvote',
+ 'amount' => '1.000 GOLOS',
+ 'memo' => 'Successfully from tip',
+ 'extensions' => []
+ ]
+ ]
+);
+
+
+// Общая часть для любой операции: подпись ключом и выполнение операции
+print_r($tx);
+
+Transaction::sign($chainName, $tx, ['active' => $wif]);
+
+$command = new BroadcastTransactionSynchronousCommand($connector);
+$answer = $command->execute(
+ $tx
+);
+
+echo "
\n
\n
\n";
+print_r($answer);
+
+?>
From db433a0ed2422712591eec3c4c3089a5822e1f44 Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Sat, 17 Oct 2020 21:49:06 +0700
Subject: [PATCH 04/24] Update GetTransactionHex.php
---
examples/Broadcast/GetTransactionHex.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/Broadcast/GetTransactionHex.php b/examples/Broadcast/GetTransactionHex.php
index 79854ed..cf4ff97 100644
--- a/examples/Broadcast/GetTransactionHex.php
+++ b/examples/Broadcast/GetTransactionHex.php
@@ -44,7 +44,7 @@
'witness_update',
[
'owner' => 't3ran13-miner',
- 'url' => 'https://golos.io/@t3ran13-miner',
+ 'url' => 'https://golos.id/@t3ran13-miner',
'block_signing_key' => 'GLS7eExwRw2Waqrq7DcC1553revU7MWvjHMqK8sbWGScaBfsThnzN',
'props' =>
[
From a4f1cbb737d157f2fea3559b8f685b16242336a5 Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Sat, 17 Oct 2020 21:50:22 +0700
Subject: [PATCH 05/24] Update README.md
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index e273429..d0ca4dd 100644
--- a/README.md
+++ b/README.md
@@ -320,7 +320,7 @@ class GolosWSConnector extends WSConnectorAbstract
*
* @var string|array
*/
- protected $nodeURL = ['wss://ws.golos.io', 'wss://api.golos.cf'];
+ protected $nodeURL = ['wss://api.golos.blckchnd.com/ws', 'wss://golos.lexa.host/ws', 'wss://golos.solox.world/ws'];
}
@@ -549,4 +549,4 @@ You need to install PhpUnit in your system (https://phpunit.de/manual/3.7/en/ins
cd Tests
phpunit CommandsTest.php
phpunit CommandsTest.php --filter=testGetBlock // test only one command
-```
\ No newline at end of file
+```
From 30d63e8a6fdfe4a83f187bfc22d32b3e879ed9e3 Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Sat, 17 Oct 2020 21:53:19 +0700
Subject: [PATCH 06/24] Update HttpJsonRpcConnectorAbstract.php
---
Connectors/Http/HttpJsonRpcConnectorAbstract.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Connectors/Http/HttpJsonRpcConnectorAbstract.php b/Connectors/Http/HttpJsonRpcConnectorAbstract.php
index 1bcc8e9..3991c43 100644
--- a/Connectors/Http/HttpJsonRpcConnectorAbstract.php
+++ b/Connectors/Http/HttpJsonRpcConnectorAbstract.php
@@ -22,7 +22,7 @@ abstract class HttpJsonRpcConnectorAbstract implements ConnectorInterface
/**
- * current node url, for example 'https://api.golos.io'
+ * current node url, for example 'https://golos.lexa.host'
*
* if you set several nodes urls, if with first node will be trouble
* it will connect after $maxNumberOfTriesToCallApi tries to next node
@@ -339,4 +339,4 @@ public function makeUrlFromArray($data)
return $url;
}
-}
\ No newline at end of file
+}
From dfae582c9e5edd4c421f0bdfd21e453625dff263 Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Sat, 17 Oct 2020 21:54:38 +0700
Subject: [PATCH 07/24] Update WSConnectorAbstract.php
---
Connectors/WebSocket/WSConnectorAbstract.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Connectors/WebSocket/WSConnectorAbstract.php b/Connectors/WebSocket/WSConnectorAbstract.php
index 3c18317..d238c5c 100644
--- a/Connectors/WebSocket/WSConnectorAbstract.php
+++ b/Connectors/WebSocket/WSConnectorAbstract.php
@@ -22,7 +22,7 @@ abstract class WSConnectorAbstract implements ConnectorInterface
protected static $nodeURL;
/**
- * current node url, for example 'wss://ws.golos.io'
+ * current node url, for example 'wss://golos.lexa.host/ws'
*
* @var string
*/
@@ -309,4 +309,4 @@ public function doRequest($apiName, array $data, $answerFormat = self::ANSWER_FO
return $answer;
}
-}
\ No newline at end of file
+}
From 9ace80dbd948641dfe0ed6db6b61667e997d5ad8 Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Sat, 17 Oct 2020 21:55:24 +0700
Subject: [PATCH 08/24] Update WitnessUpdate.php
---
examples/Broadcast/WitnessUpdate.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/Broadcast/WitnessUpdate.php b/examples/Broadcast/WitnessUpdate.php
index 503f34f..e89c50d 100644
--- a/examples/Broadcast/WitnessUpdate.php
+++ b/examples/Broadcast/WitnessUpdate.php
@@ -44,7 +44,7 @@
'witness_update',
[
'owner' => 'guest123',
- 'url' => 'https://golos.io/@guest123',
+ 'url' => 'https://golos.id/@guest123',
'block_signing_key' => 'GLS7eExwRw2Waqrq7DcC1553revU7MWvjHMqK8sbWGScguest123',
'props' =>
[
From 0107323dac3d1e8ecd96698d9ca8ecb0e3fefd2c Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Sat, 17 Oct 2020 21:57:26 +0700
Subject: [PATCH 09/24] Update ChainOperations.php
---
Tools/ChainOperations/ChainOperations.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/Tools/ChainOperations/ChainOperations.php b/Tools/ChainOperations/ChainOperations.php
index de1edbb..4d95906 100644
--- a/Tools/ChainOperations/ChainOperations.php
+++ b/Tools/ChainOperations/ChainOperations.php
@@ -17,7 +17,6 @@ class ChainOperations
const OPERATION_TRANSFER_TO_VESTING = 'transfer_to_vesting'; // GOLOS/?/?
const OPERATION_WITHDRAW_VESTING = 'withdraw_vesting'; // GOLOS/?/?
const OPERATION_CLAIM = 'claim'; // GOLOS
- const OPERATION_DONATE = 'donate'; // GOLOS
const OPERATION_TRANSFER_TO_TIP = 'transfer_to_tip'; // GOLOS
const OPERATION_TRANSFER_FROM_TIP = 'transfer_from_tip'; // GOLOS
From 719b58dff92e5f21b6adc3470cf43df213ce7138 Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Sat, 17 Oct 2020 21:58:41 +0700
Subject: [PATCH 10/24] Update ChainOperationsGolos.php
---
Tools/ChainOperations/ChainOperationsGolos.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/Tools/ChainOperations/ChainOperationsGolos.php b/Tools/ChainOperations/ChainOperationsGolos.php
index f3fa752..2dfd531 100644
--- a/Tools/ChainOperations/ChainOperationsGolos.php
+++ b/Tools/ChainOperations/ChainOperationsGolos.php
@@ -17,7 +17,6 @@ class ChainOperationsGolos
ChainOperations::OPERATION_TRANSFER_TO_VESTING => 3,
ChainOperations::OPERATION_WITHDRAW_VESTING => 4,
ChainOperations::OPERATION_CLAIM => 53,
- ChainOperations::OPERATION_DONATE => 54,
ChainOperations::OPERATION_TRANSFER_TO_TIP => 55,
ChainOperations::OPERATION_TRANSFER_FROM_TIP => 56,
From 42bcb088c0aedbc7622b76c9748b41ad26bd453f Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Wed, 21 Oct 2020 12:17:28 +0700
Subject: [PATCH 11/24] Update BroadcastTest.php
---
Tests/BroadcastTest.php | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/Tests/BroadcastTest.php b/Tests/BroadcastTest.php
index ef490c5..41c92d1 100644
--- a/Tests/BroadcastTest.php
+++ b/Tests/BroadcastTest.php
@@ -64,13 +64,12 @@
$content = $command->execute($commandQuery);
$obj=$content['result'][0];
$limit=preg_replace("/[^\d.]+/", "", $obj['vesting_shares'])-preg_replace("/[^\d.]+/", "", $obj['delegated_vesting_shares']);
-$limit=sprintf("%01.6f", $limit);
-echo $limit;
-
-//$limit="500.000000"; // TODO не позволяет вывести всё доступное
+// $limit=0;
// '0.000000 GESTS' - для отмены вывода
+$limit=sprintf("%01.6f", $limit);
+
$tx->setParamByKey(
'0:operations:0',
[
From f17b873ad897470cf5177e6afbaa5f089a276e0b Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Thu, 22 Oct 2020 13:12:51 +0700
Subject: [PATCH 12/24] Update and rename Tests/BroadcastTest.php to
examples/Broadcast/MoreTest.php
---
.../Broadcast/MoreTest.php | 22 ++++++++++++-------
1 file changed, 14 insertions(+), 8 deletions(-)
rename Tests/BroadcastTest.php => examples/Broadcast/MoreTest.php (84%)
diff --git a/Tests/BroadcastTest.php b/examples/Broadcast/MoreTest.php
similarity index 84%
rename from Tests/BroadcastTest.php
rename to examples/Broadcast/MoreTest.php
index 41c92d1..dfe76e0 100644
--- a/Tests/BroadcastTest.php
+++ b/examples/Broadcast/MoreTest.php
@@ -1,5 +1,5 @@
getPlatform();
// аккаунт для тестов и активный ключ (все операции тестировались с ним)
$acc="jackvote";
-$wif='5activeKey';
+$wif='5_active_Key';
/** @var CommandQueryData $tx */
$tx = Transaction::init($connector);
-// ТЕСТОВЫЕ БЛОКИ
+// ТЕСТОВЫЕ БЛОКИ: раскомментируйте только один из блоков /* */
-/*
// TRANSFER
$tx->setParamByKey(
'0:operations:0',
@@ -35,7 +34,8 @@
]
]
);
-*/
+// END TRANSFER
+
/*
// TRANSFER TO VESTING
@@ -51,6 +51,7 @@
]
]
);
+// END TRANSFER TO VESTING
*/
/*
@@ -80,6 +81,7 @@
]
]
);
+// END WITHDRAW VESTING
*/
/*
@@ -97,10 +99,11 @@
]
]
);
+// END CLAIM
*/
/*
-// TRANSFER TO TIP - с баланса(!)
+// TRANSFER TO TIP - с баланса GOLOS(!)
$tx->setParamByKey(
'0:operations:0',
[
@@ -114,8 +117,10 @@
]
]
);
+// END TRANSFER TO TIP
*/
+/*
// TRANSFER FROM TIP - в СГ (не на баланс!)
$tx->setParamByKey(
'0:operations:0',
@@ -130,7 +135,8 @@
]
]
);
-
+// END TRANSFER FROM TIP
+*/
// Общая часть для любой операции: подпись ключом и выполнение операции
print_r($tx);
From b832ce602fc51e13a0780ddaa837162e81c00633 Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Thu, 22 Oct 2020 13:46:45 +0700
Subject: [PATCH 13/24] Update MoreTest.php
---
examples/Broadcast/MoreTest.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/Broadcast/MoreTest.php b/examples/Broadcast/MoreTest.php
index dfe76e0..ec0acb4 100644
--- a/examples/Broadcast/MoreTest.php
+++ b/examples/Broadcast/MoreTest.php
@@ -8,7 +8,7 @@
use GrapheneNodeClient\Tools\Transaction;
use GrapheneNodeClient\Commands\Single\BroadcastTransactionSynchronousCommand;
-require "../vendor/autoload.php"; // место нахождения библиотек - укажите относительно этого файла
+require "../../../../../vendor/autoload.php"; // местонахождение библиотеки относительно этого файла
$connector = new GolosWSConnector();
$chainName = $connector->getPlatform();
From 55fa51bebbf3fdb6af09b7bb2a92beea444bcb84 Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Fri, 23 Oct 2020 13:10:46 +0700
Subject: [PATCH 14/24] Update README.md
---
README.md | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/README.md b/README.md
index d0ca4dd..fe558c5 100644
--- a/README.md
+++ b/README.md
@@ -153,6 +153,11 @@ namespace GrapheneNodeClient\Tools\ChainOperations
- comment // steem or golos
- content // only viz
- witness_update
+- transfer_to_vesting
+- withdraw_vesting
+- claim
+- transfer_to_tip
+- transfer_from_tip
```php
Date: Fri, 23 Oct 2020 13:12:02 +0700
Subject: [PATCH 15/24] Update OperationSerializer.php
---
Tools/ChainOperations/OperationSerializer.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Tools/ChainOperations/OperationSerializer.php b/Tools/ChainOperations/OperationSerializer.php
index 72e746e..cfa5b4e 100644
--- a/Tools/ChainOperations/OperationSerializer.php
+++ b/Tools/ChainOperations/OperationSerializer.php
@@ -200,7 +200,7 @@ public static function serializeType($type, $value, $byteBuffer, $chainName)
} elseif ($type === self::TYPE_INT8) {
$byteBuffer->writeInt8($value);
} elseif ($type === self::TYPE_BOOL) {
- self::serializeType(self::TYPE_INT8, $value ? 1 : 0, $byteBuffer);
+ self::serializeType(self::TYPE_INT8, $value ? 1 : 0, $byteBuffer, $chainName);
} elseif ($type === self::TYPE_PUBLIC_KEY) {
$clearPubKey = substr($value, 3);
$base58 = new Base58(null, new GMPService()); //decode base 58 to str
@@ -218,4 +218,4 @@ public static function serializeType($type, $value, $byteBuffer, $chainName)
}
-}
\ No newline at end of file
+}
From 25c1ef1be45a6459d5e6bdd868752060580fb91e Mon Sep 17 00:00:00 2001
From: jackvote <38127334+jackvote@users.noreply.github.com>
Date: Mon, 26 Oct 2020 12:39:01 +0700
Subject: [PATCH 16/24] Update MoreTest.php
---
examples/Broadcast/MoreTest.php | 155 +++++++++++++++++++++-----------
1 file changed, 102 insertions(+), 53 deletions(-)
diff --git a/examples/Broadcast/MoreTest.php b/examples/Broadcast/MoreTest.php
index ec0acb4..987e1ce 100644
--- a/examples/Broadcast/MoreTest.php
+++ b/examples/Broadcast/MoreTest.php
@@ -8,21 +8,37 @@
use GrapheneNodeClient\Tools\Transaction;
use GrapheneNodeClient\Commands\Single\BroadcastTransactionSynchronousCommand;
-require "../../../../../vendor/autoload.php"; // местонахождение библиотеки относительно этого файла
+require "../../../../../vendor/autoload.php"; // место нахождения библиотек - укажите относительно этого файла
$connector = new GolosWSConnector();
$chainName = $connector->getPlatform();
-// аккаунт для тестов и активный ключ (все операции тестировались с ним)
+// аккаунт для тестов
$acc="jackvote";
-$wif='5_active_Key';
+
+// активный (все операции тестировались с ним, кроме donate) и постинг (для donate) ключи
+$wif='5_active_key';
+$postingWif='5_posting_key';
+
+$signKey=['active' => $wif];
/** @var CommandQueryData $tx */
$tx = Transaction::init($connector);
-// ТЕСТОВЫЕ БЛОКИ: раскомментируйте только один из блоков /* */
+// ТЕСТОВЫЕ БЛОКИ: раскомментируйте только одну нужную операцию (или выполнится последняя)
+//$oper="transfer";
+//$oper="transfer_to_vesting";
+//$oper="withdraw_vesting"; // для отмены вывода раскомментируйте в блоке $limit=0;
+//$oper="claim";
+$oper="donate";
+//$oper="vote";
+//$oper="transfer_to_tip";
+//$oper="transfer_from_tip";
+
+echo "
\n".$oper."
\n";
+if ($oper=="transfer") {
// TRANSFER
-$tx->setParamByKey(
+ $tx->setParamByKey(
'0:operations:0',
[
'transfer',
@@ -33,13 +49,11 @@
'memo' => 'Successfully transfer'
]
]
-);
+ );
// END TRANSFER
-
-
-/*
+} elseif ($oper=="transfer_to_vesting") {
// TRANSFER TO VESTING
-$tx->setParamByKey(
+ $tx->setParamByKey(
'0:operations:0',
[
'transfer_to_vesting',
@@ -50,28 +64,22 @@
'memo' => 'Successfully to vesting'
]
]
-);
+ );
// END TRANSFER TO VESTING
-*/
-
-/*
+} elseif ($oper=="withdraw_vesting") {
// WITHDRAW VESTING
-
// Определяем доступную для вывода СГ
-$command = new Commands($connector);
-$command = $command->get_accounts();
-$commandQuery = new CommandQueryData();
-$commandQuery->setParamByKey('0', [$acc]);
-$content = $command->execute($commandQuery);
-$obj=$content['result'][0];
-$limit=preg_replace("/[^\d.]+/", "", $obj['vesting_shares'])-preg_replace("/[^\d.]+/", "", $obj['delegated_vesting_shares']);
-
-// $limit=0;
-// '0.000000 GESTS' - для отмены вывода
-
-$limit=sprintf("%01.6f", $limit);
-
-$tx->setParamByKey(
+ $command = new Commands($connector);
+ $command = $command->get_accounts();
+ $commandQuery = new CommandQueryData();
+ $commandQuery->setParamByKey('0', [$acc]);
+ $content = $command->execute($commandQuery);
+ $obj=$content['result'][0];
+ $limit=preg_replace("/[^\d.]+/", "", $obj['vesting_shares'])-preg_replace("/[^\d.]+/", "", $obj['delegated_vesting_shares']);
+// $limit=0; - для отмены вывода '0.000000 GESTS'
+ $limit=sprintf("%01.6f", $limit);
+
+ $tx->setParamByKey(
'0:operations:0',
[
'withdraw_vesting',
@@ -80,49 +88,88 @@
'vesting_shares' => $limit.' GESTS'
]
]
-);
+ );
// END WITHDRAW VESTING
-*/
-
-/*
+} elseif ($oper=="claim") {
// CLAIM
-$tx->setParamByKey(
+ $tx->setParamByKey(
'0:operations:0',
[
'claim',
[
'from' => $acc,
- 'to' => 'tiptoken',
- 'amount' => '0.100 GOLOS',
+ 'to' => 'jackvote',
+ 'amount' => '1.000 GOLOS',
'to_vesting' => true, // true - в СГ, false - в TIP
'extensions' => []
]
]
-);
+ );
// END CLAIM
-*/
+} elseif ($oper=="donate") {
+// DONATE
+ $signKey=['posting' => $postingWif];
-/*
+ $tx->setParamByKey(
+ '0:operations:0',
+ [
+ 'donate',
+ [
+ 'from' => $acc,
+ 'to' => 'tiptoken',
+ 'amount' => '1.000 GOLOS',
+ 'memo' =>
+ [
+ 'app' => "php-graphene-node-client",
+ 'version' => 1,
+ 'target' =>
+ [
+ 'account' => "tiptoken",
+ 'reason' => "test library"
+ ],
+ 'comment' => "Successfully donate"
+ ],
+ 'extensions' => []
+ ]
+ ]
+ );
+// END CLAIM
+} elseif ($oper=="vote") {
+// VOTE
+ $signKey=['posting' => $postingWif];
+
+ $tx->setParamByKey(
+ '0:operations:0',
+ [
+ 'vote',
+ [
+ 'voter' => $acc,
+ 'author' => "jackvote",
+ 'permlink' => "anekdot-2-raza-vypusk-1250",
+ 'weight' => 1000
+ ]
+ ]
+ );
+// END VOTE
+} elseif ($oper=="transfer_to_tip") {
// TRANSFER TO TIP - с баланса GOLOS(!)
-$tx->setParamByKey(
+ $tx->setParamByKey(
'0:operations:0',
[
'transfer_to_tip',
[
'from' => $acc,
- 'to' => 'tiptoken',
- 'amount' => '0.100 GOLOS',
+ 'to' => 'jackvote',
+ 'amount' => '1.000 GOLOS',
'memo' => 'Successfully to tip',
'extensions' => []
]
]
-);
+ );
// END TRANSFER TO TIP
-*/
-
-/*
+} elseif ($oper=="transfer_from_tip") {
// TRANSFER FROM TIP - в СГ (не на баланс!)
-$tx->setParamByKey(
+ $tx->setParamByKey(
'0:operations:0',
[
'transfer_from_tip',
@@ -134,21 +181,23 @@
'extensions' => []
]
]
-);
+ );
// END TRANSFER FROM TIP
-*/
-
+}
// Общая часть для любой операции: подпись ключом и выполнение операции
+echo "
"; print_r($tx); +echo ""; -Transaction::sign($chainName, $tx, ['active' => $wif]); +Transaction::sign($chainName, $tx, $signKey); // подписываем операцию соответствующим ключом $command = new BroadcastTransactionSynchronousCommand($connector); + $answer = $command->execute( $tx ); -echo "
\n"; print_r($answer); - +echo ""; ?> From 749efa31e8994df460aab7eae47c26a7477b0c9c Mon Sep 17 00:00:00 2001 From: jackvote <38127334+jackvote@users.noreply.github.com> Date: Mon, 26 Oct 2020 12:40:30 +0700 Subject: [PATCH 17/24] Update ChainOperations.php --- Tools/ChainOperations/ChainOperations.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Tools/ChainOperations/ChainOperations.php b/Tools/ChainOperations/ChainOperations.php index 4d95906..de1edbb 100644 --- a/Tools/ChainOperations/ChainOperations.php +++ b/Tools/ChainOperations/ChainOperations.php @@ -17,6 +17,7 @@ class ChainOperations const OPERATION_TRANSFER_TO_VESTING = 'transfer_to_vesting'; // GOLOS/?/? const OPERATION_WITHDRAW_VESTING = 'withdraw_vesting'; // GOLOS/?/? const OPERATION_CLAIM = 'claim'; // GOLOS + const OPERATION_DONATE = 'donate'; // GOLOS const OPERATION_TRANSFER_TO_TIP = 'transfer_to_tip'; // GOLOS const OPERATION_TRANSFER_FROM_TIP = 'transfer_from_tip'; // GOLOS From b6fc3036ebcef5acf5480f58cb1bb185e07df69b Mon Sep 17 00:00:00 2001 From: jackvote <38127334+jackvote@users.noreply.github.com> Date: Mon, 26 Oct 2020 12:42:08 +0700 Subject: [PATCH 18/24] Update ChainOperationsGolos.php --- Tools/ChainOperations/ChainOperationsGolos.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Tools/ChainOperations/ChainOperationsGolos.php b/Tools/ChainOperations/ChainOperationsGolos.php index 2dfd531..75e4966 100644 --- a/Tools/ChainOperations/ChainOperationsGolos.php +++ b/Tools/ChainOperations/ChainOperationsGolos.php @@ -17,6 +17,7 @@ class ChainOperationsGolos ChainOperations::OPERATION_TRANSFER_TO_VESTING => 3, ChainOperations::OPERATION_WITHDRAW_VESTING => 4, ChainOperations::OPERATION_CLAIM => 53, + ChainOperations::OPERATION_DONATE => 54, ChainOperations::OPERATION_TRANSFER_TO_TIP => 55, ChainOperations::OPERATION_TRANSFER_FROM_TIP => 56, @@ -87,6 +88,22 @@ class ChainOperationsGolos 'to_vesting' => OperationSerializer::TYPE_BOOL, 'extensions' => OperationSerializer::TYPE_SET_EXTENSIONS ], + ChainOperations::OPERATION_DONATE => [ + 'from' => OperationSerializer::TYPE_STRING, + 'to' => OperationSerializer::TYPE_STRING, + 'amount' => OperationSerializer::TYPE_ASSET, + 'memo' => OperationSerializer::TYPE_DONATE_MEMO + ], + OperationSerializer::TYPE_DONATE_MEMO => [ + 'app' => OperationSerializer::TYPE_STRING, + 'version' => OperationSerializer::TYPE_INT16, + 'target' => OperationSerializer::TYPE_DONATE_MEMO_TARGET, + 'comment' => OperationSerializer::TYPE_STRING + ], + OperationSerializer::TYPE_DONATE_MEMO_TARGET => [ + 'author' => OperationSerializer::TYPE_STRING, + 'permlink' => OperationSerializer::TYPE_STRING + ], ChainOperations::OPERATION_TRANSFER_TO_TIP => [ 'from' => OperationSerializer::TYPE_STRING, 'to' => OperationSerializer::TYPE_STRING, From b072896ecaf52df96a4b1100e7e01757228e9cdc Mon Sep 17 00:00:00 2001 From: jackvote <38127334+jackvote@users.noreply.github.com> Date: Mon, 26 Oct 2020 12:54:17 +0700 Subject: [PATCH 19/24] Update OperationSerializer.php --- Tools/ChainOperations/OperationSerializer.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tools/ChainOperations/OperationSerializer.php b/Tools/ChainOperations/OperationSerializer.php index cfa5b4e..baf5090 100644 --- a/Tools/ChainOperations/OperationSerializer.php +++ b/Tools/ChainOperations/OperationSerializer.php @@ -10,6 +10,8 @@ class OperationSerializer { const TYPE_CHAIN_PROPERTIES = 'chain_properties'; + const TYPE_DONATE_MEMO = 'donate_memo'; + const TYPE_DONATE_MEMO_TARGET = 'donate_memo_target'; const TYPE_SET_EXTENSIONS = 'set_extensions'; const TYPE_SET_BENEFICIARIES = 'set_beneficiaries'; const TYPE_BENEFICIARY = 'set_beneficiary'; @@ -212,6 +214,18 @@ public static function serializeType($type, $value, $byteBuffer, $chainName) self::serializeType($type, $value[$field], $byteBuffer, $chainName); } } + } elseif ($type === self::TYPE_DONATE_MEMO) { + if (count($value) > 0) { + foreach (self::getOpFieldsTypes($chainName, self::TYPE_DONATE_MEMO) as $field => $type) { + self::serializeType($type, $value[$field], $byteBuffer, $chainName); + } + } + } elseif ($type === self::TYPE_DONATE_MEMO_TARGET) { + if (count($value) > 0) { + foreach (self::getOpFieldsTypes($chainName, self::TYPE_DONATE_MEMO_TARGET) as $field => $type) { + self::serializeType($type, $value[$field], $byteBuffer, $chainName); + } + } } return $byteBuffer; From 53885c89d70079949f28929b192a91de03d365b3 Mon Sep 17 00:00:00 2001 From: jackvote <38127334+jackvote@users.noreply.github.com> Date: Mon, 2 Nov 2020 08:46:25 +0700 Subject: [PATCH 20/24] Update ChainOperations.php --- Tools/ChainOperations/ChainOperations.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Tools/ChainOperations/ChainOperations.php b/Tools/ChainOperations/ChainOperations.php index de1edbb..4d95906 100644 --- a/Tools/ChainOperations/ChainOperations.php +++ b/Tools/ChainOperations/ChainOperations.php @@ -17,7 +17,6 @@ class ChainOperations const OPERATION_TRANSFER_TO_VESTING = 'transfer_to_vesting'; // GOLOS/?/? const OPERATION_WITHDRAW_VESTING = 'withdraw_vesting'; // GOLOS/?/? const OPERATION_CLAIM = 'claim'; // GOLOS - const OPERATION_DONATE = 'donate'; // GOLOS const OPERATION_TRANSFER_TO_TIP = 'transfer_to_tip'; // GOLOS const OPERATION_TRANSFER_FROM_TIP = 'transfer_from_tip'; // GOLOS From 11d630ffb42e866c1aca71be51a1d7ee6ed4e992 Mon Sep 17 00:00:00 2001 From: jackvote <38127334+jackvote@users.noreply.github.com> Date: Mon, 2 Nov 2020 08:47:10 +0700 Subject: [PATCH 21/24] Update ChainOperationsGolos.php --- Tools/ChainOperations/ChainOperationsGolos.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/Tools/ChainOperations/ChainOperationsGolos.php b/Tools/ChainOperations/ChainOperationsGolos.php index 75e4966..2dfd531 100644 --- a/Tools/ChainOperations/ChainOperationsGolos.php +++ b/Tools/ChainOperations/ChainOperationsGolos.php @@ -17,7 +17,6 @@ class ChainOperationsGolos ChainOperations::OPERATION_TRANSFER_TO_VESTING => 3, ChainOperations::OPERATION_WITHDRAW_VESTING => 4, ChainOperations::OPERATION_CLAIM => 53, - ChainOperations::OPERATION_DONATE => 54, ChainOperations::OPERATION_TRANSFER_TO_TIP => 55, ChainOperations::OPERATION_TRANSFER_FROM_TIP => 56, @@ -88,22 +87,6 @@ class ChainOperationsGolos 'to_vesting' => OperationSerializer::TYPE_BOOL, 'extensions' => OperationSerializer::TYPE_SET_EXTENSIONS ], - ChainOperations::OPERATION_DONATE => [ - 'from' => OperationSerializer::TYPE_STRING, - 'to' => OperationSerializer::TYPE_STRING, - 'amount' => OperationSerializer::TYPE_ASSET, - 'memo' => OperationSerializer::TYPE_DONATE_MEMO - ], - OperationSerializer::TYPE_DONATE_MEMO => [ - 'app' => OperationSerializer::TYPE_STRING, - 'version' => OperationSerializer::TYPE_INT16, - 'target' => OperationSerializer::TYPE_DONATE_MEMO_TARGET, - 'comment' => OperationSerializer::TYPE_STRING - ], - OperationSerializer::TYPE_DONATE_MEMO_TARGET => [ - 'author' => OperationSerializer::TYPE_STRING, - 'permlink' => OperationSerializer::TYPE_STRING - ], ChainOperations::OPERATION_TRANSFER_TO_TIP => [ 'from' => OperationSerializer::TYPE_STRING, 'to' => OperationSerializer::TYPE_STRING, From ff0bde4ba8a29dd184ad5d7d5a67cae8a1605808 Mon Sep 17 00:00:00 2001 From: jackvote <38127334+jackvote@users.noreply.github.com> Date: Mon, 2 Nov 2020 08:48:07 +0700 Subject: [PATCH 22/24] Update OperationSerializer.php --- Tools/ChainOperations/OperationSerializer.php | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Tools/ChainOperations/OperationSerializer.php b/Tools/ChainOperations/OperationSerializer.php index baf5090..cfa5b4e 100644 --- a/Tools/ChainOperations/OperationSerializer.php +++ b/Tools/ChainOperations/OperationSerializer.php @@ -10,8 +10,6 @@ class OperationSerializer { const TYPE_CHAIN_PROPERTIES = 'chain_properties'; - const TYPE_DONATE_MEMO = 'donate_memo'; - const TYPE_DONATE_MEMO_TARGET = 'donate_memo_target'; const TYPE_SET_EXTENSIONS = 'set_extensions'; const TYPE_SET_BENEFICIARIES = 'set_beneficiaries'; const TYPE_BENEFICIARY = 'set_beneficiary'; @@ -214,18 +212,6 @@ public static function serializeType($type, $value, $byteBuffer, $chainName) self::serializeType($type, $value[$field], $byteBuffer, $chainName); } } - } elseif ($type === self::TYPE_DONATE_MEMO) { - if (count($value) > 0) { - foreach (self::getOpFieldsTypes($chainName, self::TYPE_DONATE_MEMO) as $field => $type) { - self::serializeType($type, $value[$field], $byteBuffer, $chainName); - } - } - } elseif ($type === self::TYPE_DONATE_MEMO_TARGET) { - if (count($value) > 0) { - foreach (self::getOpFieldsTypes($chainName, self::TYPE_DONATE_MEMO_TARGET) as $field => $type) { - self::serializeType($type, $value[$field], $byteBuffer, $chainName); - } - } } return $byteBuffer; From 9fdc2c02bd5c35b5c3a8aeaa94e1eeb5b7720af2 Mon Sep 17 00:00:00 2001 From: jackvote <38127334+jackvote@users.noreply.github.com> Date: Mon, 2 Nov 2020 08:56:14 +0700 Subject: [PATCH 23/24] Update OperationSerializer.php --- Tools/ChainOperations/OperationSerializer.php | 410 ++++++++++++++---- 1 file changed, 324 insertions(+), 86 deletions(-) diff --git a/Tools/ChainOperations/OperationSerializer.php b/Tools/ChainOperations/OperationSerializer.php index cfa5b4e..bf24952 100644 --- a/Tools/ChainOperations/OperationSerializer.php +++ b/Tools/ChainOperations/OperationSerializer.php @@ -3,24 +3,32 @@ namespace GrapheneNodeClient\Tools\ChainOperations; use GrapheneNodeClient\Connectors\ConnectorInterface; +use GrapheneNodeClient\Tools\ChainOperations\TypeSerializers\TypeSerializerInterface; use StephenHill\Base58; use StephenHill\GMPService; use t3ran13\ByteBuffer\ByteBuffer; class OperationSerializer { - const TYPE_CHAIN_PROPERTIES = 'chain_properties'; - const TYPE_SET_EXTENSIONS = 'set_extensions'; - const TYPE_SET_BENEFICIARIES = 'set_beneficiaries'; - const TYPE_BENEFICIARY = 'set_beneficiary'; - const TYPE_SET_STRING = 'set_string'; - const TYPE_PUBLIC_KEY = 'public_key'; - const TYPE_STRING = 'string'; - const TYPE_INT16 = 'int16'; - const TYPE_INT32 = 'int32'; - const TYPE_ASSET = 'asset'; - const TYPE_BOOL = 'bool'; - const TYPE_INT8 = 'int8'; + const TYPE_CHAIN_PROPERTIES = 'chainProperties'; + const TYPE_DONATE_MEMO = 'donateMemo'; + const TYPE_SET_EXTENSIONS = 'setExtensions'; + const TYPE_SET_BENEFICIARIES = 'setBeneficiaries'; + const TYPE_SET_FUTURE_EXTENSIONS = 'setFutureExtensions'; + const TYPE_SET_STRING = 'setString'; + const TYPE_BENEFICIARY = 'beneficiary'; + const TYPE_PUBLIC_KEY = 'publicKey'; + const TYPE_STRING = 'string'; + const TYPE_INT8 = 'int8'; + const TYPE_INT16 = 'int16'; + const TYPE_INT32 = 'int32'; + const TYPE_INT64 = 'int64'; + const TYPE_ASSET = 'asset'; + const TYPE_BOOL = 'bool'; + const TYPE_VARIANT_OBJECT = 'variantObject'; + const TYPE_OPTIONAL_STRING = 'optionalString'; + const TYPE_VOID = 'void'; + const TYPE_FUTURE_EXTENSIONS = 'futureExtensions'; /** @var array */ protected static $opFieldsMap = []; @@ -130,91 +138,321 @@ public static function getOpFieldsTypes($chainName, $operationName) * @param ByteBuffer $byteBuffer * @param string $chainName * - * @return mixed + * @return void * @throws \Exception */ - public static function serializeType($type, $value, $byteBuffer, $chainName) + public static function serializeType(string $type, $value, ByteBuffer $byteBuffer, string $chainName) { - if ($type === self::TYPE_STRING) { - //Writes a UTF8 encoded string prefixed 32bit base 128 variable-length integer. - $strLength = strlen($value); + $serializer = 'serialize' . ucfirst($type); + self::$serializer($value, $byteBuffer, $chainName); + } - if ($strLength <= 128) { - $byteBuffer->writeInt8($strLength); - } elseif ($strLength <= 16511) { - $strLength = ceil($strLength / 128) * 256 - + ($strLength - ceil($strLength / 128) * 128); - $byteBuffer->writeInt16LE($strLength); - } else { - $n3 = ceil($strLength / (128 * 128)); - $n2 = ceil(($strLength - $n3 * 128 * 128) / 128); - $strLength = $n3 * 256 * 256 - + $n2 * 256 - + ($strLength - $n3 * 128 * 128 - $n2 * 128); - $byteBuffer->writeInt32LE($strLength); - if ($strLength <= 16777215) { - $byteBuffer->setCurrentOffset($byteBuffer->getCurrentOffset() - 1); - } - } - $byteBuffer->writeVStringLE($value); - } elseif ($type === self::TYPE_SET_STRING) { - $byteBuffer->writeInt8(count($value)); - foreach ($value as $string) { - self::serializeType(self::TYPE_STRING, $string, $byteBuffer); + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + */ + public static function serializeString($value, ByteBuffer $byteBuffer, string $chainName) + { + //Writes a UTF8 encoded string prefixed 32bit base 128 variable-length integer. + $strLength = strlen($value); + + if ($strLength <= 128) { + $byteBuffer->writeInt8($strLength); + } elseif ($strLength <= 16511) { + $strLength = ceil($strLength / 128) * 256 + + ($strLength - ceil($strLength / 128) * 128); + $byteBuffer->writeInt16LE($strLength); + } else { + $n3 = ceil($strLength / (128 * 128)); + $n2 = ceil(($strLength - $n3 * 128 * 128) / 128); + $strLength = $n3 * 256 * 256 + + $n2 * 256 + + ($strLength - $n3 * 128 * 128 - $n2 * 128); + $byteBuffer->writeInt32LE($strLength); + if ($strLength <= 16777215) { + $byteBuffer->setCurrentOffset($byteBuffer->getCurrentOffset() - 1); } - } elseif ($type === self::TYPE_INT16) { - $byteBuffer->writeInt16LE($value); - } elseif ($type === self::TYPE_INT32) { - $byteBuffer->writeInt32LE($value); - } elseif ($type === self::TYPE_ASSET) { - list($amount, $symbol) = explode(' ', $value); - - $byteBuffer->writeInt64LE(str_replace('.', '', $amount)); - - $dot = strpos($amount, '.'); - $precision = $dot === false ? 0 : strlen($amount) - $dot - 1; - $byteBuffer->writeInt8($precision); - - $byteBuffer->writeVStringLE(strtoupper($symbol)); - for ($i = 0; $i < 7 - strlen($symbol); $i++) { - $byteBuffer->writeInt8(0); + } + $byteBuffer->writeVStringLE($value); + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + */ + public static function serializeInt8($value, ByteBuffer $byteBuffer, string $chainName) + { + $byteBuffer->writeInt8($value); + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + */ + public static function serializeInt16($value, ByteBuffer $byteBuffer, string $chainName) + { + $byteBuffer->writeInt16LE($value); + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + */ + public static function serializeInt32($value, ByteBuffer $byteBuffer, string $chainName) + { + $byteBuffer->writeInt32LE($value); + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + */ + public static function serializeInt64($value, ByteBuffer $byteBuffer, string $chainName) + { + $byteBuffer->writeInt64LE($value); + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + */ + public static function serializeAsset($value, ByteBuffer $byteBuffer, string $chainName) + { + list($amount, $symbol) = explode(' ', $value); + + $byteBuffer->writeInt64LE(str_replace('.', '', $amount)); + + $dot = strpos($amount, '.'); + $precision = $dot === false ? 0 : strlen($amount) - $dot - 1; + $byteBuffer->writeInt8($precision); + + $byteBuffer->writeVStringLE(strtoupper($symbol)); + for ($i = 0; $i < 7 - strlen($symbol); $i++) { + $byteBuffer->writeInt8(0); + } + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializeSetString($value, ByteBuffer $byteBuffer, string $chainName) + { + $byteBuffer->writeInt8(count($value)); + foreach ($value as $string) { + self::serializeString($string, $byteBuffer, $chainName); + } + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializeSetExtension($value, ByteBuffer $byteBuffer, string $chainName) + { + $byteBuffer->writeInt8(count($value)); + foreach ($value as $extension) { + $byteBuffer->writeInt8($extension[0]); + if ($extension[0] === 0) { + self::serializeSetBeneficiaries($extension[1], $byteBuffer, $chainName); + } else { + throw new \Exception("There is no serializer logic for '{$extension[0]}' extension"); } - } elseif ($type === self::TYPE_SET_EXTENSIONS) { - $byteBuffer->writeInt8(count($value)); - foreach ($value as $extension) { - $byteBuffer->writeInt8($extension[0]); - if ($extension[0] === 0) { - self::serializeType(self::TYPE_SET_BENEFICIARIES, $extension[1], $byteBuffer); - } else { - throw new \Exception("There is no serializer logic for '{$extension[0]}' extension"); - } + } + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializeSetBeneficiaries($value, ByteBuffer $byteBuffer, string $chainName) + { + $byteBuffer->writeInt8(count($value['beneficiaries'])); + foreach ($value['beneficiaries'] as $beneficiary) { + self::serializeBeneficiary($beneficiary, $byteBuffer, $chainName); + } + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializeBeneficiary($value, ByteBuffer $byteBuffer, string $chainName) + { + self::serializeString($value['account'], $byteBuffer, $chainName); + self::serializeInt16($value['weight'], $byteBuffer, $chainName); + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializeBool($value, ByteBuffer $byteBuffer, string $chainName) + { + self::serializeInt8($value ? 1 : 0, $byteBuffer, $chainName); + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializePublicKey($value, ByteBuffer $byteBuffer, string $chainName) + { + $clearPubKey = substr($value, 3); + $base58 = new Base58(null, new GMPService()); //decode base 58 to str + $stringPubKey = substr($base58->decode($clearPubKey), 0, 33); + $byteBuffer->writeVStringLE($stringPubKey); + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializeChainProperties($value, ByteBuffer $byteBuffer, string $chainName) + { + if (count($value) > 0) { + foreach (self::getOpFieldsTypes($chainName, self::TYPE_CHAIN_PROPERTIES) as $field => $type) { + self::serializeType($type, $value[$field], $byteBuffer, $chainName); } - } elseif ($type === self::TYPE_SET_BENEFICIARIES) { - $byteBuffer->writeInt8(count($value['beneficiaries'])); - foreach ($value['beneficiaries'] as $beneficiary) { - self::serializeType(self::TYPE_BENEFICIARY, $beneficiary, $byteBuffer); + } + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializeSetFutureExtensions($value, ByteBuffer $byteBuffer, string $chainName) + { + $byteBuffer->writeInt8(count($value)); + foreach ($value as $extension) { + self::serializeFutureExtensions($extension, $byteBuffer, $chainName); + } + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializeFutureExtensions($value, ByteBuffer $byteBuffer, string $chainName) + { + throw new \Exception('There is no serializer logic for ' . self::TYPE_FUTURE_EXTENSIONS); + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializeDonateMemo($value, ByteBuffer $byteBuffer, string $chainName) + { + if (count($value) > 0) { + foreach (self::getOpFieldsTypes($chainName, self::TYPE_DONATE_MEMO) as $field => $type) { + self::serializeType($type, $value[$field] ?? null, $byteBuffer, $chainName); } - } elseif ($type === self::TYPE_BENEFICIARY) { - self::serializeType(self::TYPE_STRING, $value['account'], $byteBuffer); - self::serializeType(self::TYPE_INT16, $value['weight'], $byteBuffer); - } elseif ($type === self::TYPE_INT8) { - $byteBuffer->writeInt8($value); - } elseif ($type === self::TYPE_BOOL) { - self::serializeType(self::TYPE_INT8, $value ? 1 : 0, $byteBuffer, $chainName); - } elseif ($type === self::TYPE_PUBLIC_KEY) { - $clearPubKey = substr($value, 3); - $base58 = new Base58(null, new GMPService()); //decode base 58 to str - $stringPubKey = substr($base58->decode($clearPubKey), 0, 33); - $byteBuffer->writeVStringLE($stringPubKey); - } elseif ($type === self::TYPE_CHAIN_PROPERTIES) { - if (count($value) > 0) { - foreach (self::getOpFieldsTypes($chainName, self::TYPE_CHAIN_PROPERTIES) as $field => $type) { - self::serializeType($type, $value[$field], $byteBuffer, $chainName); - } + } + } + + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializeVariantObject($value, ByteBuffer $byteBuffer, string $chainName) + { + $byteBuffer->writeInt8(count($value)); + foreach ($value as $key => $val) { + self::serializeString($key, $byteBuffer, $chainName); + if (is_string($val)) { + $prefix = 5; + $type = self::TYPE_STRING; + } elseif (is_int($val)) { + $prefix = 2; + $type = self::TYPE_INT64; + } else { + throw new \Exception('Correct value for ' . self::TYPE_VARIANT_OBJECT . 'is array pf numbers or strings'); } + + self::serializeInt8($prefix, $byteBuffer, $chainName); + self::serializeType($type, $val, $byteBuffer, $chainName); } + } - return $byteBuffer; + /** + * @param mixed $value + * @param ByteBuffer $byteBuffer + * @param string $chainName + * + * @return void + * @throws \Exception + */ + public static function serializeOptionalString($value, ByteBuffer $byteBuffer, string $chainName) + { + if ($value === null) { + self::serializeInt8(0, $byteBuffer, $chainName); + } else { + self::serializeInt8(1, $byteBuffer, $chainName); + self::serializeString($value, $byteBuffer, $chainName); + } } From 485caf0582e424ec4b31273a59b4d2d7b50f2302 Mon Sep 17 00:00:00 2001 From: jackvote <38127334+jackvote@users.noreply.github.com> Date: Mon, 2 Nov 2020 09:03:19 +0700 Subject: [PATCH 24/24] Update ChainOperations.php --- Tools/ChainOperations/ChainOperations.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Tools/ChainOperations/ChainOperations.php b/Tools/ChainOperations/ChainOperations.php index 4d95906..bf4e23e 100644 --- a/Tools/ChainOperations/ChainOperations.php +++ b/Tools/ChainOperations/ChainOperations.php @@ -14,6 +14,7 @@ class ChainOperations const OPERATION_CUSTOM_JSON = 'custom_json'; const OPERATION_CUSTOM = 'custom';//only for VIZ const OPERATION_WITNESS_UPDATE = 'witness_update'; + const OPERATION_WITNESS_UPDATE = 'donate'; const OPERATION_TRANSFER_TO_VESTING = 'transfer_to_vesting'; // GOLOS/?/? const OPERATION_WITHDRAW_VESTING = 'withdraw_vesting'; // GOLOS/?/? const OPERATION_CLAIM = 'claim'; // GOLOS