From 3d47f0fca3c3d057c64573ac3b8de555b2f36a39 Mon Sep 17 00:00:00 2001 From: Dario Rekowski on RockPI Date: Wed, 23 Oct 2019 07:54:28 +0000 Subject: [PATCH] adding gradido protobuf messages --- mithril_client | 2 +- .../TransactionCreationsController.php | 21 ++ .../protobuf/gradido/BasicTypes.proto | 33 ++ .../protobuf/gradido/StateCreateGroup.proto | 15 + .../gradido/StateGroupChangeParent.proto | 12 + .../protobuf/gradido/Transaction.proto | 20 ++ .../protobuf/gradido/TransactionBody.proto | 16 + .../Messages/protobuf/gradido/Transfer.proto | 19 ++ src/Model/Table/StateUsersTable.php | 8 +- src/Model/Table/TransactionCreationsTable.php | 5 +- src/Template/Layout/default.ctp | 2 +- src/Template/Pages/gradido.ctp | 4 +- src/Template/Pages/home.ctp | 293 ++---------------- 13 files changed, 165 insertions(+), 285 deletions(-) create mode 100644 src/Model/Messages/protobuf/gradido/BasicTypes.proto create mode 100644 src/Model/Messages/protobuf/gradido/StateCreateGroup.proto create mode 100644 src/Model/Messages/protobuf/gradido/StateGroupChangeParent.proto create mode 100644 src/Model/Messages/protobuf/gradido/Transaction.proto create mode 100644 src/Model/Messages/protobuf/gradido/TransactionBody.proto create mode 100644 src/Model/Messages/protobuf/gradido/Transfer.proto diff --git a/mithril_client b/mithril_client index a37f26ae9..92d3e9def 160000 --- a/mithril_client +++ b/mithril_client @@ -1 +1 @@ -Subproject commit a37f26ae9ce3bd3c25cfeb9b51bef3f2a4a6ebeb +Subproject commit 92d3e9def837e48f2d8e3da0b2de487e6fa27d7b diff --git a/src/Controller/TransactionCreationsController.php b/src/Controller/TransactionCreationsController.php index 126932538..01e3626c0 100644 --- a/src/Controller/TransactionCreationsController.php +++ b/src/Controller/TransactionCreationsController.php @@ -12,6 +12,13 @@ use App\Controller\AppController; */ class TransactionCreationsController extends AppController { + + public function initialize() + { + parent::initialize(); + //$this->Auth->allow(['add', 'edit']); + $this->Auth->allow('add'); + } /** * Index method * @@ -42,6 +49,19 @@ class TransactionCreationsController extends AppController $this->set('transactionCreation', $transactionCreation); } + + public function create() + { + $startTime = microtime(true); + $this->viewBuilder()->setLayout('frontend'); + $session = $this->getRequest()->getSession(); + $user = $session->read('StateUser'); + //var_dump($user); + $transactionCreation = $this->TransactionCreations->newEntity(); + $transactionCreation->state_user_id = $user->id; + $timeUsed = microtime(true) - $startTime; + $this->set(compact('transactionCreation', 'timeUsed')); + } /** * Add method @@ -50,6 +70,7 @@ class TransactionCreationsController extends AppController */ public function add() { + $transactionCreation = $this->TransactionCreations->newEntity(); if ($this->request->is('post')) { $transactionCreation = $this->TransactionCreations->patchEntity($transactionCreation, $this->request->getData()); diff --git a/src/Model/Messages/protobuf/gradido/BasicTypes.proto b/src/Model/Messages/protobuf/gradido/BasicTypes.proto new file mode 100644 index 000000000..6e0f208d9 --- /dev/null +++ b/src/Model/Messages/protobuf/gradido/BasicTypes.proto @@ -0,0 +1,33 @@ +syntax = "proto3" + +package gradido; + +message Key { + oneof key { + bytes ed25519 = 2; // ed25519 signature (libsodium default) + bytes ed25519_ref10 = 3; // ed25519 ref10 signature + } +} + +message SignaturePair { + bytes pubKey = 1; + oneof signature { + bytes ed25519 = 2; // ed25519 signature (libsodium default) + bytes ed25519_ref10 = 3; // ed25519 ref10 signature + } +} + +message SignatureMap { + repeated SignaturePair sigPair = 1; // Each signature pair corresponds to a unique Key required to sign the transaction. +} + +/* An exact date and time. This is the same data structure as the protobuf Timestamp.proto (see the comments in https://github.com/google/protobuf/blob/master/src/google/protobuf/timestamp.proto) */ +message Timestamp { + int64 seconds = 1; // Number of complete seconds since the start of the epoch + int32 nanos = 2; // Number of nanoseconds since the start of the last second +} + +/* An exact date and time, with a resolution of one second (no nanoseconds). */ +message TimestampSeconds { + int64 seconds = 1; // Number of complete seconds since the start of the epoch +} \ No newline at end of file diff --git a/src/Model/Messages/protobuf/gradido/StateCreateGroup.proto b/src/Model/Messages/protobuf/gradido/StateCreateGroup.proto new file mode 100644 index 000000000..0fd3b58c7 --- /dev/null +++ b/src/Model/Messages/protobuf/gradido/StateCreateGroup.proto @@ -0,0 +1,15 @@ +syntax = "proto3" + +package gradido; + +import "BasicTypes.proto"; + +// need signature from this group and from parent (if it isn't zero) +message StateCreateGroup { + string name = 1; + Key groupPublicKey = 2; + Key parentGroupPublicKey = 3; + reserved "hederaConsensusId"; + reserved 4; + +} \ No newline at end of file diff --git a/src/Model/Messages/protobuf/gradido/StateGroupChangeParent.proto b/src/Model/Messages/protobuf/gradido/StateGroupChangeParent.proto new file mode 100644 index 000000000..8742bf5aa --- /dev/null +++ b/src/Model/Messages/protobuf/gradido/StateGroupChangeParent.proto @@ -0,0 +1,12 @@ +syntax = "proto3" + +package gradido; + +import "BasicTypes.proto"; + +// need signature from this group and from both parents (if it isn't zero) +message StateGroupChangeParent { + Key groupPublicKey = 1; + Key newParentGroupPublicKey = 2; + Key oldParentGroupPublicKey = 3; +} \ No newline at end of file diff --git a/src/Model/Messages/protobuf/gradido/Transaction.proto b/src/Model/Messages/protobuf/gradido/Transaction.proto new file mode 100644 index 000000000..37bfffe60 --- /dev/null +++ b/src/Model/Messages/protobuf/gradido/Transaction.proto @@ -0,0 +1,20 @@ +syntax = "proto3" + +package gradido; + +import "BasicTypes.proto"; +import "TransactionBody.proto"; + +/* + id will be set by Node server + txHash will be also set by Node server, + calculated from previous transaction txHash and this id, sigMap and received; +*/ + +message Transaction { + uint64 id = 1; + TimestampSeconds received = 2; + SignatureMap sigMap = 3; + bytes txHash = 4; + bytes bodyBytes = 5; +} \ No newline at end of file diff --git a/src/Model/Messages/protobuf/gradido/TransactionBody.proto b/src/Model/Messages/protobuf/gradido/TransactionBody.proto new file mode 100644 index 000000000..e85f09b52 --- /dev/null +++ b/src/Model/Messages/protobuf/gradido/TransactionBody.proto @@ -0,0 +1,16 @@ +syntax = "proto3" + +package gradido; + +import "Transfer.proto"; +import "StateCreateGroup.proto"; +import "StateGroupChangeParent.proto"; + +message TransactionBody { + string memo = 1; // max 150 chars + oneof data { + StateCreateGroup createGroup = 2; + StateGroupChangeParent groupChangeParent = 3; + Transfer transfer = 4; + } +} \ No newline at end of file diff --git a/src/Model/Messages/protobuf/gradido/Transfer.proto b/src/Model/Messages/protobuf/gradido/Transfer.proto new file mode 100644 index 000000000..ebff885df --- /dev/null +++ b/src/Model/Messages/protobuf/gradido/Transfer.proto @@ -0,0 +1,19 @@ +syntax = "proto3" + +package gradido; + +message SenderAmount { + bytes ed25519_sender_pubkey = 1; + sint64 amount = 2; + sint64 senderFinalBalance = 3; // sender balance after transaction, including perishability +} + +message ReceiverAmount { + bytes ed25519_receiver_pubkey = 1; + sint64 amount = 2; +} + +message Transfer { + repeated SenderAmount senderAmounts = 1; + repeated ReceiverAmount receiverAmounts = 2; +} \ No newline at end of file diff --git a/src/Model/Table/StateUsersTable.php b/src/Model/Table/StateUsersTable.php index 4c73ddbc2..fe18766e9 100644 --- a/src/Model/Table/StateUsersTable.php +++ b/src/Model/Table/StateUsersTable.php @@ -41,10 +41,10 @@ class StateUsersTable extends Table $this->setDisplayField('id'); $this->setPrimaryKey('id'); - $this->belongsTo('Indices', [ + /*$this->belongsTo('Indices', [ 'foreignKey' => 'index_id', 'joinType' => 'INNER' - ]); + ]);*/ $this->belongsTo('StateGroups', [ 'foreignKey' => 'state_group_id', 'joinType' => 'INNER' @@ -91,8 +91,8 @@ class StateUsersTable extends Table */ public function buildRules(RulesChecker $rules) { - $rules->add($rules->existsIn(['index_id'], 'Indices')); - $rules->add($rules->existsIn(['state_group_id'], 'StateGroups')); + // $rules->add($rules->existsIn(['index_id'], 'Indices')); + //$rules->add($rules->existsIn(['state_group_id'], 'StateGroups')); return $rules; } diff --git a/src/Model/Table/TransactionCreationsTable.php b/src/Model/Table/TransactionCreationsTable.php index 60a636aa2..8f0afc158 100644 --- a/src/Model/Table/TransactionCreationsTable.php +++ b/src/Model/Table/TransactionCreationsTable.php @@ -64,8 +64,9 @@ class TransactionCreationsTable extends Table ->notEmptyString('amount'); $validator - ->requirePresence('ident_hash', 'create') - ->notEmptyString('ident_hash'); + //->requirePresence('ident_hash', 'create') + //->notEmptyString('ident_hash'); + ->allowEmptyString('ident_hash', null, 'create'); return $validator; } diff --git a/src/Template/Layout/default.ctp b/src/Template/Layout/default.ctp index b5e38e309..926f3a556 100644 --- a/src/Template/Layout/default.ctp +++ b/src/Template/Layout/default.ctp @@ -13,7 +13,7 @@ * @license https://opensource.org/licenses/mit-license.php MIT License */ -$cakeDescription = 'CakePHP: the rapid development php framework'; +$cakeDescription = 'Gradido'; ?> diff --git a/src/Template/Pages/gradido.ctp b/src/Template/Pages/gradido.ctp index 14d4bb3fc..f6a2213cc 100644 --- a/src/Template/Pages/gradido.ctp +++ b/src/Template/Pages/gradido.ctp @@ -8,7 +8,7 @@ - - + + \ No newline at end of file diff --git a/src/Template/Pages/home.ctp b/src/Template/Pages/home.ctp index 5a3731e4c..3926921c4 100644 --- a/src/Template/Pages/home.ctp +++ b/src/Template/Pages/home.ctp @@ -1,276 +1,19 @@ -layout = false; - -if (!Configure::read('debug')) : - throw new NotFoundException( - 'Please replace src/Template/Pages/home.ctp with your own version or re-enable debug mode.' - ); -endif; - -$cakeDescription = 'CakePHP: the rapid development PHP framework'; -?> - - - - Html->charset() ?> - - - <?= $cakeDescription ?> - - - Html->meta('icon') ?> - Html->css('base.css') ?> - Html->css('style.css') ?> - Html->css('home.css') ?> - - - - -
-
Html->image('cake.logo.svg') ?>
-
-

Welcome to CakePHP Red Velvet. Build fast. Grow solid.

+layout = false;?> + + Web Assembly Test (CakePHP Single Node Version) + + + +
+
+

Gradido

+

Implementierung wählen

+
+
-
- -
-
-
-

Please be aware that this page will not be shown if you turn off debug mode unless you replace src/Template/Pages/home.ctp with your own version.

-
-
- -
- -
-
- -
-
-

Environment

-
    - =')) : ?> -
  • Your version of PHP is 5.6.0 or higher (detected ).
  • - -
  • Your version of PHP is too low. You need PHP 5.6.0 or higher to use CakePHP (detected ).
  • - - - -
  • Your version of PHP has the mbstring extension loaded.
  • - -
  • Your version of PHP does NOT have the mbstring extension loaded.
  • - - - -
  • Your version of PHP has the openssl extension loaded.
  • - -
  • Your version of PHP has the mcrypt extension loaded.
  • - -
  • Your version of PHP does NOT have the openssl or mcrypt extension loaded.
  • - - - -
  • Your version of PHP has the intl extension loaded.
  • - -
  • Your version of PHP does NOT have the intl extension loaded.
  • - -
-
-
-

Filesystem

-
    - -
  • Your tmp directory is writable.
  • - -
  • Your tmp directory is NOT writable.
  • - - - -
  • Your logs directory is writable.
  • - -
  • Your logs directory is NOT writable.
  • - - - - -
  • The Engine is being used for core caching. To change the config edit config/app.php
  • - -
  • Your cache is NOT working. Please check the settings in config/app.php
  • - -
-
-
-
- -
-
-

Database

- connect(); - } catch (Exception $connectionError) { - $connected = false; - $errorMsg = $connectionError->getMessage(); - if (method_exists($connectionError, 'getAttributes')) : - $attributes = $connectionError->getAttributes(); - if (isset($errorMsg['message'])) : - $errorMsg .= '
' . $attributes['message']; - endif; - endif; - } - ?> -
    - -
  • CakePHP is able to connect to the database.
  • - -
  • CakePHP is NOT able to connect to the database.
  • - -
-
-
-

DebugKit

-
    - -
  • DebugKit is loaded.
  • - -
  • DebugKit is NOT loaded. You need to either install pdo_sqlite, or define the "debug_kit" connection name.
  • - -
-
-
-
- -
-
-

Editing this Page

-
    -
  • To change the content of this page, edit: src/Template/Pages/home.ctp.
  • -
  • You can also add some CSS styles for your pages at: webroot/css/.
  • -
-
-
-

Getting Started

- -
-
- -
-
-

More about Cake

-

- CakePHP is a rapid development framework for PHP which uses commonly known design patterns like Front Controller and MVC.
- Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility. -

-
-
-
- -
-
- P -

Help and Bug Reports

- -
-
- r -

Docs and Downloads

- -
-
- s -

Training and Certification

- -
-
- - - + + + \ No newline at end of file