From b4feb6d55c38ff4c26fca569a12e1e7e6ab4ab70 Mon Sep 17 00:00:00 2001 From: astaphobia Date: Tue, 21 Jan 2020 14:57:29 +0800 Subject: [PATCH 1/3] escrow and more adjustment --- documentation.swagger.json | 68 ++++++++++++++++++++++++++++++-------- model/escrow.proto | 24 ++++++++++++++ model/mempool.proto | 4 ++- model/transaction.proto | 3 ++ service/escrow.proto | 16 +++++++++ 5 files changed, 100 insertions(+), 15 deletions(-) create mode 100644 model/escrow.proto create mode 100644 service/escrow.proto diff --git a/documentation.swagger.json b/documentation.swagger.json index 95dbec9..2f75733 100644 --- a/documentation.swagger.json +++ b/documentation.swagger.json @@ -269,6 +269,22 @@ } } }, + "/v1/escrow/PostEscrowApprovalRequest": { + "post": { + "tags": [ + "EscrowTransactionService" + ], + "operationId": "PostApprovalEscrowTransaction", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/modelTransaction" + } + } + } + } + }, "/v1/host/GetHostInfo": { "get": { "tags": [ @@ -958,6 +974,37 @@ "modelEmptyTransactionBody": { "type": "object" }, + "modelEscrow": { + "type": "object", + "properties": { + "Amount": { + "type": "string", + "format": "int64" + }, + "ApproverAddress": { + "type": "string" + }, + "Commission": { + "type": "string", + "format": "int64" + }, + "ID": { + "type": "string", + "format": "int64" + }, + "RecipientAddress": { + "type": "string" + }, + "SenderAddress": { + "type": "string" + }, + "Timeout": { + "type": "string", + "format": "uint64", + "title": "Timeout is BlockHeight gap" + } + } + }, "modelEventType": { "type": "string", "default": "EventAny", @@ -1317,6 +1364,9 @@ "type": "integer", "format": "int64" }, + "Escrow": { + "$ref": "#/definitions/modelEscrow" + }, "FeePerByte": { "type": "string", "format": "int64" @@ -1726,6 +1776,10 @@ "type": "string", "format": "int64" }, + "Escrow": { + "title": "nullable", + "$ref": "#/definitions/modelEscrow" + }, "Fee": { "type": "string", "format": "int64" @@ -1860,19 +1914,5 @@ } } } - }, - "x-stream-definitions": { - "modelGetNodeHardwareResponse": { - "properties": { - "error": { - "$ref": "#/definitions/runtimeStreamError" - }, - "result": { - "$ref": "#/definitions/modelGetNodeHardwareResponse" - } - }, - "title": "Stream result of modelGetNodeHardwareResponse", - "type": "object" - } } } diff --git a/model/escrow.proto b/model/escrow.proto new file mode 100644 index 0000000..887702d --- /dev/null +++ b/model/escrow.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; + +package model; +option go_package = "github.com/zoobc/zoobc-core/common/model"; + +message Escrow { + int64 ID = 1 [ jstype = JS_STRING ]; + string SenderAddress = 2; + string RecipientAddress = 3; + string ApproverAddress = 4; + int64 Amount = 5 [ jstype = JS_STRING ]; + int64 Commission = 6 [ jstype = JS_STRING ]; + // Timeout is BlockHeight gap + uint64 Timeout = 7 [ jstype = JS_STRING ]; +} +enum EscrowApproval { + Approve = 0; + Reject = 1; +} +message PostEscrowApprovalRequest { +// EscrowApproval Approval +// int64 TransactionID + bytes ApprovalBytes = 1; +} \ No newline at end of file diff --git a/model/mempool.proto b/model/mempool.proto index 03a5166..218ba13 100644 --- a/model/mempool.proto +++ b/model/mempool.proto @@ -4,7 +4,7 @@ package model; option go_package = "github.com/zoobc/zoobc-core/common/model"; import "model/pagination.proto"; - +import "model/escrow.proto"; // Mempool represent the mempool data structure stored in the database message MempoolTransaction { int64 ID = 1 [jstype = JS_STRING]; @@ -14,6 +14,8 @@ message MempoolTransaction { bytes TransactionBytes = 5; string SenderAccountAddress = 6; string RecipientAccountAddress = 7; + Escrow Escrow = 8; + } message GetMempoolTransactionRequest { diff --git a/model/transaction.proto b/model/transaction.proto index 68ebc2b..089bddf 100644 --- a/model/transaction.proto +++ b/model/transaction.proto @@ -7,6 +7,7 @@ import "model/proofOfOwnership.proto"; import "model/pagination.proto"; import "model/batchReceipt.proto"; import "model/nodeRegistration.proto"; +import "model/escrow.proto"; // Transaction represent the transaction data structure stored in the database message Transaction { @@ -35,6 +36,8 @@ message Transaction { RemoveAccountDatasetTransactionBody removeAccountDatasetTransactionBody = 21; } bytes Signature = 22; + // nullable + Escrow Escrow = 23; } enum TransactionType { diff --git a/service/escrow.proto b/service/escrow.proto new file mode 100644 index 0000000..af688fc --- /dev/null +++ b/service/escrow.proto @@ -0,0 +1,16 @@ +syntax = "proto3"; + +package service; +option go_package = "github.com/zoobc/zoobc-core/common/service"; + +import "model/transaction.proto"; +import "model/escrow.proto"; +import "google/api/annotations.proto"; + +service EscrowTransactionService { + rpc PostApprovalEscrowTransaction(model.PostEscrowApprovalRequest) returns (model.Transaction) { + option (google.api.http) = { + post: "/v1/escrow/PostEscrowApprovalRequest" + }; + } +} From e31653a58bb2791bb7423945c2f8980629ddf850 Mon Sep 17 00:00:00 2001 From: astaphobia Date: Wed, 22 Jan 2020 13:36:36 +0800 Subject: [PATCH 2/3] add status and latest stage of record for rollback purposes --- documentation.swagger.json | 16 ++++++++++++++++ model/escrow.proto | 12 ++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/documentation.swagger.json b/documentation.swagger.json index 6b34faf..05c3eb9 100644 --- a/documentation.swagger.json +++ b/documentation.swagger.json @@ -999,12 +999,19 @@ "type": "string", "format": "int64" }, + "Latest": { + "type": "boolean", + "format": "boolean" + }, "RecipientAddress": { "type": "string" }, "SenderAddress": { "type": "string" }, + "Status": { + "$ref": "#/definitions/modelEscrowStatus" + }, "Timeout": { "type": "string", "format": "uint64", @@ -1012,6 +1019,15 @@ } } }, + "modelEscrowStatus": { + "type": "string", + "default": "Approved", + "enum": [ + "Approved", + "Rejected", + "Expired" + ] + }, "modelEventType": { "type": "string", "default": "EventAny", diff --git a/model/escrow.proto b/model/escrow.proto index 887702d..a603dbc 100644 --- a/model/escrow.proto +++ b/model/escrow.proto @@ -12,13 +12,21 @@ message Escrow { int64 Commission = 6 [ jstype = JS_STRING ]; // Timeout is BlockHeight gap uint64 Timeout = 7 [ jstype = JS_STRING ]; + EscrowStatus Status = 8; + bool Latest = 9; } +enum EscrowStatus { + Approved = 0; + Rejected = 1; + Expired = 2; +} + enum EscrowApproval { Approve = 0; Reject = 1; } +// PostEscrowApprovalRequest message for approval transaction escrow message PostEscrowApprovalRequest { -// EscrowApproval Approval -// int64 TransactionID + // ApprovalBytes format: [EscrowApproval][int64 TransactionID] bytes ApprovalBytes = 1; } \ No newline at end of file From a228fadc50f71952bdbd520d3e7e49d8d882003d Mon Sep 17 00:00:00 2001 From: astaphobia Date: Wed, 22 Jan 2020 15:07:03 +0800 Subject: [PATCH 3/3] ad block_height into escrow_transaction --- documentation.swagger.json | 4 ++++ model/escrow.proto | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/documentation.swagger.json b/documentation.swagger.json index 05c3eb9..8d7d61b 100644 --- a/documentation.swagger.json +++ b/documentation.swagger.json @@ -991,6 +991,10 @@ "ApproverAddress": { "type": "string" }, + "BlockHeight": { + "type": "integer", + "format": "int64" + }, "Commission": { "type": "string", "format": "int64" diff --git a/model/escrow.proto b/model/escrow.proto index a603dbc..ddcf76f 100644 --- a/model/escrow.proto +++ b/model/escrow.proto @@ -13,7 +13,8 @@ message Escrow { // Timeout is BlockHeight gap uint64 Timeout = 7 [ jstype = JS_STRING ]; EscrowStatus Status = 8; - bool Latest = 9; + uint32 BlockHeight = 9; + bool Latest = 10; } enum EscrowStatus { Approved = 0;