This is an automated email from the ASF dual-hosted git repository. cmorris pushed a commit to branch splitroles-blockchain in repository https://gitbox.apache.org/repos/asf/incubator-milagro-dta.git
commit 2409254f104fc30600d003780196c2dff7a07170 Author: Christopher Morris <[email protected]> AuthorDate: Mon Sep 30 14:15:05 2019 +0100 Both secret & order working with TXs --- libs/documents/docs.go | 9 +- libs/documents/docs.pb.go | 160 +++++++++++++++++++----------------- libs/documents/docs.proto | 1 + libs/documents/docs.validator.pb.go | 1 + pkg/common/chain.go | 8 +- pkg/common/common.go | 12 +-- pkg/defaultservice/fulfill.go | 47 +++++------ pkg/defaultservice/order.go | 123 ++++++++++++++------------- pkg/endpoints/endpoints.go | 22 +---- pkg/service/service.go | 4 +- pkg/tendermint/tendermint.go | 16 ++-- pkg/tendermint/websockets.go | 24 ++++++ 12 files changed, 227 insertions(+), 200 deletions(-) diff --git a/libs/documents/docs.go b/libs/documents/docs.go index 2845aad..75c1c1c 100644 --- a/libs/documents/docs.go +++ b/libs/documents/docs.go @@ -118,10 +118,11 @@ func DecodeOrderDocument(rawdoc []byte, tag string, orderdoc *OrderDoc, sikeSK [ orderdoc.OrderDocument = &cipherText //validate the order document - err = orderdoc.OrderDocument.Validate() - if err != nil { - return err - } + //TODO: temp remove validation because we arent using IPFS any more + // err = orderdoc.OrderDocument.Validate() + // if err != nil { + // return err + // } return nil } diff --git a/libs/documents/docs.pb.go b/libs/documents/docs.pb.go index 0a5cb42..c42f56d 100644 --- a/libs/documents/docs.pb.go +++ b/libs/documents/docs.pb.go @@ -651,12 +651,13 @@ func (m *OrderPart3) GetTimestamp() int64 { } type OrderPart4 struct { - Secret string `protobuf:"bytes,1,opt,name=Secret,proto3" json:"Secret,omitempty"` - PreviousOrderCID string `protobuf:"bytes,2,opt,name=PreviousOrderCID,proto3" json:"PreviousOrderCID,omitempty"` - Timestamp int64 `protobuf:"varint,3,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Secret string `protobuf:"bytes,1,opt,name=Secret,proto3" json:"Secret,omitempty"` + PreviousOrderCID string `protobuf:"bytes,2,opt,name=PreviousOrderCID,proto3" json:"PreviousOrderCID,omitempty"` + Timestamp int64 `protobuf:"varint,3,opt,name=Timestamp,proto3" json:"Timestamp,omitempty"` + Extension map[string]string `protobuf:"bytes,4,rep,name=Extension,proto3" json:"Extension,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *OrderPart4) Reset() { *m = OrderPart4{} } @@ -705,6 +706,13 @@ func (m *OrderPart4) GetTimestamp() int64 { return 0 } +func (m *OrderPart4) GetExtension() map[string]string { + if m != nil { + return m.Extension + } + return nil +} + type Policy struct { Version float32 `protobuf:"fixed32,1,opt,name=Version,proto3" json:"Version,omitempty"` Name string `protobuf:"bytes,2,opt,name=Name,proto3" json:"Name,omitempty"` @@ -881,6 +889,7 @@ func init() { proto.RegisterMapType((map[string]string)(nil), "documents.OrderPart2.ExtensionEntry") proto.RegisterType((*OrderPart3)(nil), "documents.OrderPart3") proto.RegisterType((*OrderPart4)(nil), "documents.OrderPart4") + proto.RegisterMapType((map[string]string)(nil), "documents.OrderPart4.ExtensionEntry") proto.RegisterType((*Policy)(nil), "documents.Policy") proto.RegisterType((*PlainTestMessage1)(nil), "documents.PlainTestMessage1") proto.RegisterType((*EncryptTestMessage1)(nil), "documents.EncryptTestMessage1") @@ -890,73 +899,74 @@ func init() { func init() { proto.RegisterFile("docs.proto", fileDescriptor_2a25dace11219bce) } var fileDescriptor_2a25dace11219bce = []byte{ - // 1086 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xc4, 0x56, 0xcd, 0x6f, 0x1b, 0x45, - 0x14, 0x67, 0x6d, 0xc7, 0xc9, 0xbe, 0xb8, 0x8e, 0x3b, 0x75, 0xda, 0x55, 0xa8, 0x9a, 0x68, 0x15, - 0xa1, 0x20, 0x11, 0x87, 0x38, 0x6e, 0x54, 0xa2, 0x4a, 0x08, 0xdb, 0x01, 0xac, 0xf2, 0x61, 0xd6, - 0x69, 0x40, 0xaa, 0xda, 0x68, 0xb2, 0x3b, 0x71, 0x46, 0xf1, 0xce, 0xac, 0x76, 0xc7, 0x49, 0x2d, - 0xe0, 0xcc, 0x81, 0x0b, 0x12, 0x67, 0x2e, 0x48, 0xbd, 0x72, 0x44, 0xe2, 0xce, 0xff, 0x11, 0x91, - 0x03, 0x88, 0xff, 0x80, 0x1b, 0x68, 0x66, 0x3f, 0xbc, 0x6b, 0xec, 0xa6, 0x07, 0x24, 0x7c, 0x9a, - 0xf7, 0xde, 0xef, 0xbd, 0x79, 0x1f, 0xbf, 0x79, 0x5e, 0x00, 0x87, 0xdb, 0x41, 0xcd, 0xf3, 0xb9, - 0xe0, 0x48, 0x77, 0xb8, 0x3d, 0x74, 0x09, 0x13, 0xc1, 0xca, 0x6e, 0x9f, 0x8a, 0xd3, 0xe1, 0x71, - 0xcd, 0xe6, 0xee, 0x96, 0x7b, 0x41, 0xc5, 0x19, 0xbf, 0xd8, 0xea, 0xf3, 0x4d, 0x85, 0xdb, 0x3c, - 0xc7, 0x03, 0xea, 0x60, 0xc1, 0xfd, 0x60, 0x2b, 0x39, 0x86, 0x21, 0x56, 0x36, 0x53, 0x7e, 0x7d, - 0xde, 0xe7, 0x5b, 0x4a, 0x7d, 0x3c, 0x3c, 0x51, 0x92, 0x12, 0xd4, 0x29, 0x84, 0x9b, 0xdf, 0x6a, - 0x50, 0xee, 0xd1, 0x3e, 0x23, 0xce, 0x3e, 0x3b, 0x27, 0x03, 0xee, 0x11, 0xb4, 0x0e, 0xba, 0xd4, - 0x60, 0x31, 0xf4, 0x89, 0xa1, 0xad, 0x69, 0x1b,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, 0x3f, 0xb2, 0x12, 0x04, 0x5a, - 0x83, 0xc5, 0xae, 0x4f, 0xce, 0x29, 0x1f, 0x06, 0xb2, 0x65, 0x05, 0x75, 0x49, 0x5a, 0x85, 0x4c, - 0x28, 0xc9, 0xa4, 0x0e, 0x46, 0x1e, 0x69, 0x71, 0x87, 0x18, 0x73, 0xea, 0xba, 0x8c, 0x4e, 0x46, - 0x91, 0x72, 0x9c, 0x51, 0x51, 0x41, 0xd2, 0x2a, 0xd4, 0x80, 0xe5, 0x4c, 0x8d, 0x49, 0xb8, 0x79, - 0x85, 0x9d, 0x6e, 0x44, 0x75, 0xa8, 0x66, 0x0c, 0xf1, 0x05, 0x0b, 0xca, 0x69, 0xaa, 0x0d, 0x6d, - 0xc0, 0x52, 0x46, 0xdf, 0x39, 0x34, 0x74, 0xd5, 0xe4, 0x49, 0x35, 0x7a, 0x08, 0x60, 0x11, 0x9b, - 0x7a, 0x54, 0x4e, 0xcf, 0x80, 0xb5, 0xfc, 0xc6, 0x62, 0xbd, 0x9a, 0x9a, 0x67, 0x62, 0x0c, 0x99, - 0x76, 0x5a, 0xb5, 0x52, 0x78, 0xf3, 0x27, 0x0d, 0xf4, 0x44, 0x4c, 0xcf, 0x43, 0xcb, 0xce, 0x63, - 0x13, 0xf2, 0xaf, 0x48, 0x46, 0x89, 0x8b, 0xd2, 0xc7, 0x5e, 0x30, 0x1c, 0x60, 0x41, 0x9c, 0x47, - 0x24, 0xe6, 0xc8, 0xa4, 0x1a, 0xdd, 0x03, 0x68, 0x51, 0xef, 0x94, 0xf8, 0x07, 0xe4, 0xb9, 0x50, - 0x93, 0x2b, 0x59, 0x29, 0x0d, 0x2a, 0x43, 0xae, 0x73, 0xa8, 0xc6, 0x55, 0xb2, 0x72, 0x9d, 0x43, - 0xf3, 0x2f, 0x0d, 0xa0, 0xd3, 0x6e, 0x47, 0xe5, 0xa1, 0x07, 0x70, 0xe7, 0xbd, 0xa1, 0x38, 0x25, - 0x4c, 0x50, 0x1b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 0xf3, 0x37, 0x2d, 0xcd, 0x0a, 0xb9, 0x08, 0x2d, 0xe2, 0x10, 0xd7, 0x13, 0xf1, 0xfa, 0xd5, - 0xad, 0x94, 0xe6, 0xbf, 0xeb, 0xd4, 0x1e, 0x18, 0xe9, 0xd5, 0x16, 0xff, 0x9d, 0xb4, 0xb1, 0xc0, - 0xd1, 0x2e, 0x9b, 0x69, 0xcf, 0x76, 0xb9, 0x70, 0xfd, 0xca, 0xfa, 0x21, 0x5d, 0x63, 0x43, 0x7e, - 0x07, 0xf4, 0x88, 0xed, 0x13, 0x11, 0x7f, 0x07, 0x84, 0xd2, 0xff, 0xc6, 0x02, 0x73, 0x17, 0x8a, - 0x5d, 0x3e, 0xa0, 0xf6, 0xe8, 0x25, 0x7f, 0x7d, 0x08, 0x0a, 0x9f, 0x60, 0x37, 0x1e, 0xa0, 0x3a, - 0x9b, 0xdb, 0x70, 0xb3, 0x3b, 0xc0, 0x94, 0x1d, 0x90, 0x40, 0x44, 0x1f, 0x58, 0xdb, 0xe8, 0x2e, - 0xe8, 0xd2, 0x28, 0x48, 0x20, 0xb6, 0xa3, 0x02, 0xc7, 0x0a, 0x73, 0x07, 0x6e, 0x45, 0xbd, 0x9c, - 0xe5, 0x54, 0x9f, 0x74, 0xaa, 0x9b, 0x1b, 0x50, 0xea, 0x51, 0xd7, 0x1b, 0x90, 0x9e, 0xf0, 0x29, - 0xeb, 0xcb, 0x2c, 0x5b, 0x9c, 0x09, 0xc2, 0xe2, 0x0e, 0xc6, 0xe2, 0x71, 0x51, 0x7d, 0x73, 0xee, - 0xfc, 0x13, 0x00, 0x00, 0xff, 0xff, 0x68, 0xf8, 0x5f, 0x01, 0xf3, 0x0a, 0x00, 0x00, + // 1093 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x56, 0xcf, 0x6f, 0x1b, 0xc5, + 0x17, 0xff, 0xae, 0xed, 0x38,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0, 0x1a, 0x2c, 0x76, 0x7d, 0x72, 0x4e, 0xf9, 0x30, 0x90, 0x57, 0x56, 0x50, 0x9b, + 0xa4, 0x5d, 0xc8, 0x84, 0x92, 0x2c, 0xea, 0x60, 0xe4, 0x91, 0x16, 0x77, 0x88, 0x31, 0xa7, 0xb6, + 0xcb, 0xf8, 0x64, 0x16, 0x69, 0xc7, 0x15, 0x15, 0x15, 0x25, 0xed, 0x42, 0x0d, 0x58, 0xce, 0x9c, + 0x31, 0x49, 0x37, 0xaf, 0xb8, 0xd3, 0x41, 0x54, 0x87, 0x6a, 0x06, 0x88, 0x37, 0x58, 0x50, 0x41, + 0x53, 0x31, 0xb4, 0x01, 0x4b, 0x19, 0x7f, 0xe7, 0xd0, 0xd0, 0xd5, 0x25, 0x4f, 0xba, 0xd1, 0x43, + 0x00, 0x8b, 0xd8, 0xd4, 0xa3, 0xb2, 0x7b, 0x06, 0xac, 0xe5, 0x37, 0x16, 0xeb, 0xd5, 0x54, 0x3f, + 0x13, 0x30, 0x54, 0xda, 0x69, 0xd5, 0x4a, 0xf1, 0xcd, 0x1f, 0x34, 0xd0, 0x13, 0x33, 0xdd, 0x0f, + 0x2d, 0xdb, 0x8f, 0x4d, 0xc8, 0xbf, 0xa2, 0x18, 0x25, 0x2f, 0x2a, 0x1f, 0x7b, 0xc1, 0x70, 0x80, + 0x05, 0x71, 0x1e, 0x91, 0x58, 0x23, 0x93, 0x6e, 0x74, 0x0f, 0xa0, 0x45, 0xbd, 0x53, 0xe2, 0x1f, + 0x90, 0xe7, 0x42, 0x75, 0xae, 0x64, 0xa5, 0x3c, 0xa8, 0x0c, 0xb9, 0xce, 0xa1, 0x6a, 0x57, 0xc9, + 0xca, 0x75, 0x0e, 0xcd, 0x3f, 0x34, 0x80, 0x4e, 0xbb, 0x1d, 0x1d, 0x0f, 0x3d, 0x80, 0x3b, 0xef, + 0x0c, 0xc5, 0x29, 0x61, 0x82, 0xda, 0x58, 0x50, 0xce, 0x2c, 0x72, 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x40, 0x5d, 0x56, 0x17, 0xfb, 0xa2, 0xae, 0x1e, 0xf0, 0x62, 0x7d, 0x79, 0xf2, 0x5e, 0x15, 0x68, + 0xa5, 0x88, 0x99, 0xb0, 0x1d, 0xf5, 0x90, 0x67, 0x84, 0xed, 0xa4, 0xc2, 0x76, 0x32, 0x61, 0x0d, + 0x03, 0x66, 0x87, 0x35, 0x52, 0x61, 0x0d, 0x93, 0x42, 0x75, 0x5a, 0x47, 0xd1, 0x12, 0x2c, 0x3e, + 0x66, 0x81, 0x47, 0x6c, 0x7a, 0x42, 0x89, 0x53, 0xf9, 0x1f, 0xba, 0x07, 0x2b, 0x29, 0xce, 0xd1, + 0x23, 0xc6, 0x2f, 0xd8, 0x11, 0x16, 0x47, 0x81, 0xc0, 0xbe, 0xa8, 0x68, 0x68, 0x0d, 0xee, 0xa6, + 0xf1, 0xc7, 0xec, 0x2c, 0x66, 0xf4, 0x14, 0x23, 0x67, 0xfe, 0x94, 0x4b, 0x5f, 0x08, 0x7a, 0x13, + 0x6e, 0xb5, 0xb8, 0xeb, 0x52, 0x21, 0xeb, 0x1b, 0x8b, 0x3f, 0x94, 0xe7, 0x34, 0x08, 0xbd, 0x07, + 0x95, 0x78, 0x4c, 0xab, 0x3c, 0xaf, 0x38, 0x64, 0xfe, 0x16, 0x94, 0xed, 0x64, 0xfe, 0xfa, 0x4e, + 0x36, 0x41, 0xdf, 0x7f, 0x2e, 0x08, 0x53, 0xc3, 0xae, 0xa0, 0xa6, 0xe6, 0xfa, 0xd4, 0x46, 0xd6, + 0x12, 0xda, 0x3e, 0x13, 0xfe, 0xc8, 0x1a, 0x87, 0xad, 0x3c, 0x84, 0x72, 0x16, 0x44, 0x15, 0xc8, + 0x9f, 0x25, 0x07, 0x96, 0x4b, 0x54, 0x85, 0xb9, 0x73, 0x3c, 0x18, 0x86, 0x8f, 0x50, 0xb7, 0x42, + 0x63, 0x2f, 0xf7, 0x40, 0x33, 0x7f, 0xd1, 0xd2, 0xaa, 0x90, 0x83, 0xd0, 0x22, 0x0e, 0x71, 0x3d, + 0x11, 0x8f, 0x5f, 0xdd, 0x4a, 0x79, 0xfe, 0xb9, 0x9b, 0xda, 0x03, 0x23, 0x3d, 0xda, 0xe2, 0xbf, + 0x93, 0x36, 0x16, 0x38, 0x9a, 0x65, 0x33, 0xf1, 0xec, 0x2d, 0x17, 0xae, 0x1f, 0x59, 0xdf, 0xa5, + 0xf5, 0xd1, 0x90, 0xdf, 0x01, 0x3d, 0x62, 0xfb, 0x44, 0xc4, 0xdf, 0x01, 0xa1, 0xf5, 0xdf, 0x57, + 0x41, 0xe3, 0x5f, 0x53, 0xc1, 0x2e, 0x14, 0xbb, 0x7c, 0x40, 0xed, 0xd1, 0x4b, 0xfe, 0x7c, 0x11, + 0x14, 0x3e, 0xc2, 0x6e, 0x1c, 0xac, 0xd6, 0xe6, 0x36, 0xdc, 0xec, 0x0e, 0x30, 0x65, 0x07, 0x24, + 0x10, 0xd1, 0x27, 0xde, 0x36, 0xba, 0x0b, 0xba, 0x04, 0x05, 0x09, 0xc4, 0x76, 0xb4, 0xfd, 0xd8, + 0x61, 0xee, 0xc0, 0xad, 0xa8, 0x9b, 0xb3, 0x82, 0xea, 0x93, 0x41, 0x75, 0x73, 0x03, 0x4a, 0x3d, + 0xea, 0x7a, 0x03, 0xd2, 0x13, 0x3e, 0x65, 0x7d, 0x59, 0x65, 0x8b, 0x33, 0x41, 0x58, 0xdc, 0xc3, + 0xd8, 0x3c, 0x2e, 0xaa, 0xaf, 0xde, 0x9d, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, 0x52, 0x13, 0xdf, + 0x60, 0x75, 0x0b, 0x00, 0x00, } diff --git a/libs/documents/docs.proto b/libs/documents/docs.proto index c60619f..1f326ef 100644 --- a/libs/documents/docs.proto +++ b/libs/documents/docs.proto @@ -113,6 +113,7 @@ message OrderPart4 { string Secret = 1; string PreviousOrderCID = 2 [(validator.field) = {regex: "^Q[[:alnum:]]{45}$|^$"}]; int64 Timestamp = 3 [(validator.field) = {int_gt:1564050341,int_lt:32521429541}]; + map<string, string> Extension = 4; } diff --git a/libs/documents/docs.validator.pb.go b/libs/documents/docs.validator.pb.go index 66a1638..8475cc8 100644 --- a/libs/documents/docs.validator.pb.go +++ b/libs/documents/docs.validator.pb.go @@ -161,6 +161,7 @@ func (this *OrderPart4) Validate() error { if !(this.Timestamp < 32521429541) { return github_com_mwitkow_go_proto_validators.FieldError("Timestamp", fmt.Errorf(`value '%v' must be less than '32521429541'`, this.Timestamp)) } + // Validation of proto3 map<> fields is unsupported. return nil } func (this *Policy) Validate() error { diff --git a/pkg/common/chain.go b/pkg/common/chain.go index 50d74ca..d7a7023 100644 --- a/pkg/common/chain.go +++ b/pkg/common/chain.go @@ -24,11 +24,11 @@ func CreateTX(nodeID string, store *datastore.Store, id string, order *documents return nil, nil, errors.Wrap(err, "Failed to encode IDDocument") } TXID := sha256.Sum256(rawDoc) - // TXIDhex = hex.EncodeToString(TXID[:]) + TXIDhex := hex.EncodeToString(TXID[:]) //Write order to store - //if err := WriteOrderToStore(store, order.Reference, TXIDhex); err != nil { - // return nil, nil, errors.New("Save Order to store") - // } + if err := WriteOrderToStore(store, order.Reference, TXIDhex); err != nil { + return nil, nil, errors.New("Save Order to store") + } return TXID[:], rawDoc, nil } diff --git a/pkg/common/common.go b/pkg/common/common.go index 91adc16..694019d 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -135,7 +135,7 @@ func CreateAndStoreOrderPart2(ipfs ipfs.Connector, store *datastore.Store, order } // CreateAndStorePart3 adds part 3 "redemption request" to the order doc -func CreateAndStorePart3(ipfs ipfs.Connector, store *datastore.Store, order *documents.OrderDoc, orderPart2CID, nodeID string, beneficiaryEncryptedData []byte, recipients map[string]documents.IDDoc) (orderPart3CID string, err error) { +func CreateAndStorePart3(ipfs ipfs.Connector, store *datastore.Store, order *documents.OrderDoc, orderPart2CID, nodeID string, beneficiaryEncryptedData []byte, recipients map[string]documents.IDDoc) (*documents.OrderDoc, error) { //Add part 3 "redemption request" to the order doc redemptionRequest := documents.OrderPart3{ //TODO @@ -146,11 +146,7 @@ func CreateAndStorePart3(ipfs ipfs.Connector, store *datastore.Store, order *doc } order.OrderPart3 = &redemptionRequest //Write the updated doc back to IPFS - orderPart3CID, err = WriteOrderToIPFS(nodeID, ipfs, store, nodeID, order, recipients) - if err != nil { - return "", nil - } - return orderPart3CID, nil + return order, nil } // CreateAndStoreOrderPart4 - @@ -216,8 +212,8 @@ func WriteOrderToIPFS(nodeID string, ipfs ipfs.Connector, store *datastore.Store return ipfsAddress, nil } -func WriteOrderToStore(store *datastore.Store, orderReference string, ipfsAddress string) error { - if err := store.Set("order", orderReference, ipfsAddress, map[string]string{"time": time.Now().UTC().Format(time.RFC3339)}); err != nil { +func WriteOrderToStore(store *datastore.Store, orderReference string, address string) error { + if err := store.Set("order", orderReference, address, map[string]string{"time": time.Now().UTC().Format(time.RFC3339)}); err != nil { return errors.New("Save Order to store") } return nil diff --git a/pkg/defaultservice/fulfill.go b/pkg/defaultservice/fulfill.go index 2857bef..27d865b 100644 --- a/pkg/defaultservice/fulfill.go +++ b/pkg/defaultservice/fulfill.go @@ -19,7 +19,6 @@ package defaultservice import ( "encoding/hex" - "encoding/json" "time" "github.com/apache/incubator-milagro-dta/libs/cryptowallet" @@ -56,11 +55,9 @@ func (s *Service) FulfillOrder(tx *api.BlockChainTX) (string, error) { return "", err } - //Retrieve the order from IPFS + //Decode the supplied order order := &documents.OrderDoc{} err = documents.DecodeOrderDocument(reqPayload, txHashString, order, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) - - // order, err := common.RetrieveOrderFromIPFS(s.Ipfs, orderPart1CID, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) if err != nil { return "", err } @@ -83,12 +80,11 @@ func (s *Service) FulfillOrder(tx *api.BlockChainTX) (string, error) { } //Create an order part 2 - Part2 := documents.OrderPart2{ + order.OrderPart2 = &documents.OrderPart2{ CommitmentPublicKey: commitmentPublicKey, PreviousOrderCID: txHashString, Timestamp: time.Now().Unix(), } - order.OrderPart2 = &Part2 txHash, payload, err := common.CreateTX(nodeID, s.Store, nodeID, order, recipientList) //_ = txHashID @@ -107,18 +103,26 @@ func (s *Service) FulfillOrder(tx *api.BlockChainTX) (string, error) { RecipientID: []string{order.PrincipalCID, nodeID}, Payload: payload, TXhash: txHash, - Tags: map[string]string{"reference": order.Reference}, + Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)}, } return tendermint.PostToChain(chainTX, "FulfillOrder") } // FulfillOrderSecret - -func (s *Service) FulfillOrderSecret(req *api.FulfillOrderSecretRequest) (string, error) { +func (s *Service) FulfillOrderSecret(tx *api.BlockChainTX) (string, error) { //Initialise values from Request object - orderPart3CID := req.OrderPart3CID + reqPayload := tx.Payload + txHashString := hex.EncodeToString(tx.TXhash) + + signerID, err := documents.OrderDocumentSigner(reqPayload) + if err != nil { + return "", err + } + nodeID := s.NodeID() - remoteIDDocCID := req.SenderDocumentCID + remoteIDDocCID := signerID + _, _, _, sikeSK, err := common.RetrieveIdentitySecrets(s.Store, nodeID) if err != nil { return "", err @@ -129,8 +133,9 @@ func (s *Service) FulfillOrderSecret(req *api.FulfillOrderSecretRequest) (string return "", err } - //Retrieve the order from IPFS - order, err := common.RetrieveOrderFromIPFS(s.Ipfs, orderPart3CID, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) + //Decode the supplied order + order := &documents.OrderDoc{} + err = documents.DecodeOrderDocument(reqPayload, txHashString, order, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) if err != nil { return "", err } @@ -152,25 +157,21 @@ func (s *Service) FulfillOrderSecret(req *api.FulfillOrderSecretRequest) (string return "", err } - //Create an order response in IPFS - orderPart4ID, err := common.CreateAndStoreOrderPart4(s.Ipfs, s.Store, order, commitmentPrivateKey, orderPart3CID, nodeID, recipientList) - if err != nil { - return "", err + order.OrderPart4 = &documents.OrderPart4{ + Secret: commitmentPrivateKey, + PreviousOrderCID: txHashString, + Timestamp: time.Now().Unix(), } - response := &api.FulfillOrderSecretResponse{ - OrderPart4CID: orderPart4ID, - } - - marshaledRequest, _ := json.Marshal(response) + txHash, payload, err := common.CreateTX(nodeID, s.Store, nodeID, order, recipientList) //Write the requests to the chain chainTX := &api.BlockChainTX{ Processor: api.TXFulfillOrderSecretResponse, SenderID: nodeID, RecipientID: []string{s.MasterFiduciaryNodeID(), order.BeneficiaryCID}, - Payload: marshaledRequest, - Tags: map[string]string{"reference": order.Reference}, + Payload: payload, + Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)}, } return tendermint.PostToChain(chainTX, "FulfillOrderSecret") } diff --git a/pkg/defaultservice/order.go b/pkg/defaultservice/order.go index f89a08b..5f9027c 100644 --- a/pkg/defaultservice/order.go +++ b/pkg/defaultservice/order.go @@ -18,8 +18,10 @@ package defaultservice import ( + "encoding/base64" "encoding/hex" "encoding/json" + "time" "github.com/apache/incubator-milagro-dta/libs/cryptowallet" "github.com/apache/incubator-milagro-dta/libs/documents" @@ -141,29 +143,14 @@ func (s *Service) Order1(req *api.OrderRequest) (string, error) { return "", err } - fulfillExtension, err := s.Plugin.PrepareOrderPart1(order, req.Extension) - if err != nil { - return "", err - } - - //Write Order to IPFS - orderPart1CID, err := common.WriteOrderToIPFS(nodeID, s.Ipfs, s.Store, nodeID, order, recipientList) - if err != nil { - return "", err - } - - request := &api.FulfillOrderRequest{ - DocumentCID: nodeID, - OrderPart1CID: orderPart1CID, - Extension: fulfillExtension, - } + // fulfillExtension, err := s.Plugin.PrepareOrderPart1(order, req.Extension) + // if err != nil { + // return "", err + // } //This is serialized and output to the chain txHash, payload, err := common.CreateTX(nodeID, s.Store, nodeID, order, recipientList) - marshaledRequest, _ := json.Marshal(request) - _ = marshaledRequest - //Write the requests to the chain chainTX := &api.BlockChainTX{ Processor: api.TXFulfillRequest, @@ -171,7 +158,7 @@ func (s *Service) Order1(req *api.OrderRequest) (string, error) { RecipientID: []string{s.MasterFiduciaryNodeID(), nodeID}, Payload: payload, //marshaledRequest, TXhash: txHash, - Tags: map[string]string{"reference": order.Reference}, + Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)}, } tendermint.PostToChain(chainTX, "Order1") return order.Reference, nil @@ -217,7 +204,6 @@ func (s *Service) Order2(tx *api.BlockChainTX) (string, error) { order.OrderPart2.Extension = make(map[string]string) } for key, value := range extension { - order.OrderPart2.Extension[key] = value } @@ -238,14 +224,17 @@ func (s *Service) Order2(tx *api.BlockChainTX) (string, error) { } txHash, payload, err := common.CreateTX(nodeID, s.Store, nodeID, order, recipientList) + print(hex.EncodeToString(txHash)) + txHash64 := base64.StdEncoding.EncodeToString(txHash) + //Write the Order2 results to the chain chainTX := &api.BlockChainTX{ Processor: api.TXOrderResponse, SenderID: "", //use no Sender so we can read our own Result for testing RecipientID: []string{nodeID}, Payload: payload, - TXhash: txHash, - Tags: map[string]string{"reference": order.Reference}, + TXhash: []byte(txHash64), + Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)}, } return tendermint.PostToChain(chainTX, "Order2") @@ -254,8 +243,8 @@ func (s *Service) Order2(tx *api.BlockChainTX) (string, error) { // OrderSecret1 - func (s *Service) OrderSecret1(req *api.OrderSecretRequest) (string, error) { orderReference := req.OrderReference - var orderPart2CID string - if err := s.Store.Get("order", orderReference, &orderPart2CID); err != nil { + var previousOrderHash string + if err := s.Store.Get("order", orderReference, &previousOrderHash); err != nil { return "", err } @@ -279,16 +268,32 @@ func (s *Service) OrderSecret1(req *api.OrderSecretRequest) (string, error) { return "", err } - //If we already did a transfer the Order doc is self signed so, check with own Key so we can re-process the transfer - order, err := common.RetrieveOrderFromIPFS(s.Ipfs, orderPart2CID, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) + tx, err := tendermint.TXbyHash(previousOrderHash) if err != nil { - //check if we are re-trying the call, so the OrderDoc is locally signed - order, err = common.RetrieveOrderFromIPFS(s.Ipfs, orderPart2CID, sikeSK, nodeID, localIDDoc.BLSPublicKey) + return "", err + } + + _ = tx + + order := &documents.OrderDoc{} + err = documents.DecodeOrderDocument(tx.Payload, previousOrderHash, order, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) + if err != nil { + err = documents.DecodeOrderDocument(tx.Payload, previousOrderHash, order, sikeSK, nodeID, localIDDoc.BLSPublicKey) if err != nil { - return "", errors.Wrap(err, "Fail to retrieve Order from IPFS") + return "", errors.Wrap(err, "Fail to retrieve existing order") } } + //If we already did a transfer the Order doc is self signed so, check with own Key so we can re-process the transfer + // order, err := common.RetrieveOrderFromIPFS(s.Ipfs, previousOrderHash, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) + // if err != nil { + // //check if we are re-trying the call, so the OrderDoc is locally signed + // order, err = common.RetrieveOrderFromIPFS(s.Ipfs, previousOrderHash, sikeSK, nodeID, localIDDoc.BLSPublicKey) + // if err != nil { + // return "", errors.Wrap(err, "Fail to retrieve Order from IPFS") + // } + // } + if err := s.Plugin.ValidateOrderSecretRequest(req, *order); err != nil { return "", err } @@ -298,40 +303,38 @@ func (s *Service) OrderSecret1(req *api.OrderSecretRequest) (string, error) { } //Create a piece of data that is destined for the beneficiary, passed via the Master Fiduciary - beneficiaryEncryptedData, extension, err := s.Plugin.ProduceBeneficiaryEncryptedData(blsSK, order, req) + beneficiaryEncryptedData, _, err := s.Plugin.ProduceBeneficiaryEncryptedData(blsSK, order, req) if err != nil { return "", err } //Create a request Object in IPFS - orderPart3CID, err := common.CreateAndStorePart3(s.Ipfs, s.Store, order, orderPart2CID, nodeID, beneficiaryEncryptedData, recipientList) - if err != nil { - return "", err - } - - //Post the address of the updated doc to the custody node - request := &api.FulfillOrderSecretRequest{ - SenderDocumentCID: nodeID, - OrderPart3CID: orderPart3CID, - Extension: extension, + order.OrderPart3 = &documents.OrderPart3{ + Redemption: "SignedReferenceNumber", + PreviousOrderCID: previousOrderHash, + BeneficiaryEncryptedData: beneficiaryEncryptedData, + Timestamp: time.Now().Unix(), } - marshaledRequest, _ := json.Marshal(request) + txHash, payload, err := common.CreateTX(nodeID, s.Store, nodeID, order, recipientList) //Write the requests to the chain chainTX := &api.BlockChainTX{ Processor: api.TXFulfillOrderSecretRequest, SenderID: nodeID, RecipientID: []string{s.MasterFiduciaryNodeID()}, - Payload: marshaledRequest, - Tags: map[string]string{"reference": order.Reference}, + Payload: payload, + Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)}, } return tendermint.PostToChain(chainTX, "OrderSecret1") } // OrderSecret2 - -func (s *Service) OrderSecret2(req *api.FulfillOrderSecretResponse) (string, error) { +func (s *Service) OrderSecret2(tx *api.BlockChainTX) (string, error) { nodeID := s.NodeID() + reqPayload := tx.Payload + txHashString := hex.EncodeToString(tx.TXhash) + _, _, _, sikeSK, err := common.RetrieveIdentitySecrets(s.Store, nodeID) if err != nil { return "", err @@ -343,9 +346,10 @@ func (s *Service) OrderSecret2(req *api.FulfillOrderSecretResponse) (string, err } //Retrieve the response Order from IPFS - orderPart4, err := common.RetrieveOrderFromIPFS(s.Ipfs, req.OrderPart4CID, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) + order := &documents.OrderDoc{} + err = documents.DecodeOrderDocument(reqPayload, txHashString, order, sikeSK, nodeID, remoteIDDoc.BLSPublicKey) - if orderPart4.BeneficiaryCID != nodeID { + if order.BeneficiaryCID != nodeID { return "", errors.New("Invalid Processor") } @@ -354,27 +358,34 @@ func (s *Service) OrderSecret2(req *api.FulfillOrderSecretResponse) (string, err return "", err } - finalPrivateKey, finalPublicKey, ext, err := s.Plugin.ProduceFinalSecret(seed, sikeSK, orderPart4, orderPart4, nodeID) + finalPrivateKey, _, extension, err := s.Plugin.ProduceFinalSecret(seed, sikeSK, order, order, nodeID) if err != nil { return "", err } - request := &api.OrderSecretResponse{ - Secret: finalPrivateKey, - Commitment: finalPublicKey, - OrderReference: orderPart4.Reference, - Extension: ext, + if order.OrderPart4.Extension == nil { + order.OrderPart4.Extension = make(map[string]string) + } + for key, value := range extension { + order.OrderPart4.Extension[key] = value } - marshaledRequest, _ := json.Marshal(request) + order.OrderPart4.Extension["FinalPrivateKey"] = finalPrivateKey + + //Output Only to self for autoviewing + recipientList, err := common.BuildRecipientList(s.Ipfs, nodeID, nodeID) + if err != nil { + return "", err + } + txHash, payload, err := common.CreateTX(nodeID, s.Store, nodeID, order, recipientList) //Write the requests to the chain chainTX := &api.BlockChainTX{ Processor: api.TXOrderSecretResponse, //NONE SenderID: "", // so we can view it RecipientID: []string{nodeID}, //don't send this to chain, seed compromise becomes fatal, sent just debugging - Payload: marshaledRequest, - Tags: map[string]string{"reference": orderPart4.Reference, "part": "4"}, + Payload: payload, + Tags: map[string]string{"reference": order.Reference, "txhash": hex.EncodeToString(txHash)}, } return tendermint.PostToChain(chainTX, "OrderSecret2") } diff --git a/pkg/endpoints/endpoints.go b/pkg/endpoints/endpoints.go index 05758f6..f7d053d 100644 --- a/pkg/endpoints/endpoints.go +++ b/pkg/endpoints/endpoints.go @@ -369,16 +369,7 @@ func MakeOrderSecret1Endpoint(m service.Service) endpoint.Endpoint { //MakeOrderSecret2Endpoint - func MakeOrderSecret2Endpoint(m service.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req, ok := request.(*api.FulfillOrderSecretResponse) - if !ok { - return nil, transport.ErrInvalidRequest - } - if err := validateRequest(req); err != nil { - return "", err - } - return m.OrderSecret2(req) - } + return nil } //MakeFulfillOrderEndpoint - @@ -388,16 +379,7 @@ func MakeFulfillOrderEndpoint(m service.Service) endpoint.Endpoint { //MakeFulfillOrderSecretEndpoint - func MakeFulfillOrderSecretEndpoint(m service.Service) endpoint.Endpoint { - return func(ctx context.Context, request interface{}) (response interface{}, err error) { - req, ok := request.(*api.FulfillOrderSecretRequest) - if !ok { - return nil, transport.ErrInvalidRequest - } - if err := validateRequest(req); err != nil { - return "", err - } - return m.FulfillOrderSecret(req) - } + return nil } //MakeStatusEndpoint - diff --git a/pkg/service/service.go b/pkg/service/service.go index 26c3189..8f3bb2b 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -35,14 +35,14 @@ type Service interface { //Order processing OrderSecret1(req *api.OrderSecretRequest) (string, error) - OrderSecret2(req *api.FulfillOrderSecretResponse) (string, error) + OrderSecret2(tx *api.BlockChainTX) (string, error) Order1(req *api.OrderRequest) (string, error) Order2(tx *api.BlockChainTX) (string, error) //Fullfill processing FulfillOrder(tx *api.BlockChainTX) (string, error) - FulfillOrderSecret(req *api.FulfillOrderSecretRequest) (string, error) + FulfillOrderSecret(tx *api.BlockChainTX) (string, error) NodeID() string MasterFiduciaryNodeID() string diff --git a/pkg/tendermint/tendermint.go b/pkg/tendermint/tendermint.go index 6c7eeee..84ca3e2 100644 --- a/pkg/tendermint/tendermint.go +++ b/pkg/tendermint/tendermint.go @@ -138,14 +138,14 @@ func callNextTX(svc service.Service, tx *api.BlockChainTX, listenPort string) er return nil } - // if tx.Processor == "v1/fulfill/order/secret" { - // svc.FulfillOrderSecret(tx) - // return nil - // } - // if tx.Processor == "v1/order/secret2" { - // svc.OrderSecret1(tx) - // return nil - // } + if tx.Processor == "v1/fulfill/order/secret" { + svc.FulfillOrderSecret(tx) + return nil + } + if tx.Processor == "v1/order/secret2" { + svc.OrderSecret2(tx) + return nil + } desintationURL := fmt.Sprintf("http://localhost"+listenPort+"/%s", tx.Processor) diff --git a/pkg/tendermint/websockets.go b/pkg/tendermint/websockets.go index a17f192..2de01bf 100644 --- a/pkg/tendermint/websockets.go +++ b/pkg/tendermint/websockets.go @@ -103,6 +103,30 @@ func subscribeAndQueue(queueWaiting chan api.BlockChainTX, logger *logger.Logger return nil } +func TXbyHash(TXHash string) (api.BlockChainTX, error) { + client := tmclient.NewHTTP("tcp://"+node+"", "/websocket") + query := fmt.Sprintf("tag.txhash='%s'", TXHash) + result, err := client.TxSearch(query, true, 1, 1) + + if len(result.Txs) == 0 { + return api.BlockChainTX{}, errors.New("Not found") + } + + payload := api.BlockChainTX{} + err = json.Unmarshal(result.Txs[0].Tx, &payload) + + _ = payload + + if err != nil { + return payload, err + } + // + // res := result.Txs[0] + // tx := res.Tx + return payload, nil + +} + //loadAllHistoricTX - load the history for this node into a queue func loadAllHistoricTX(start int, end int, txHistory []ctypes.ResultTx, nodeID string, listenPort string) error { //cycle through the historic transactions page by page
