diff --git a/.gitignore b/.gitignore index c85767c7..49ce3c19 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ - /vendor \ No newline at end of file diff --git a/.godir b/.godir new file mode 100644 index 00000000..fefc2ed7 --- /dev/null +++ b/.godir @@ -0,0 +1 @@ +github.com/dileepaj/tracified-gateway \ No newline at end of file diff --git a/Gopkg.lock b/Gopkg.lock index e9345c63..42ffac99 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -95,6 +95,14 @@ revision = "792786c7400a136282c1664665ae0a8db921c6c2" version = "v1.0.0" +[[projects]] + digest = "1:ed615c5430ecabbb0fb7629a182da65ecee6523900ac1ac932520860878ffcad" + name = "github.com/robfig/cron" + packages = ["."] + pruneopts = "UT" + revision = "b41be1df696709bb6395fe435af20370037c0b4c" + version = "v1.1" + [[projects]] digest = "1:54bd573538ca13ccf85d18c99249d934f17957f17263256b42565a11c854c1de" name = "github.com/segmentio/go-loggly" @@ -115,7 +123,7 @@ [[projects]] branch = "master" - digest = "1:abfbdfc9eeeafac74501521dc9c11b6e7a756ae1cbb2986416c3fb452cadcd37" + digest = "1:393ea46f2901b064b74759d9b83fad9d93005a7a050db69b88448c4b18005c80" name = "github.com/stellar/go" packages = [ "amount", @@ -138,7 +146,7 @@ "xdr", ] pruneopts = "UT" - revision = "c235e807644d76fc15c8328df4cbb49a25b990d0" + revision = "d0fd3fc54379730416baf402381451150bb5569b" [[projects]] branch = "master" @@ -169,11 +177,11 @@ [[projects]] branch = "master" - digest = "1:225564f71149334315118db714e1ea87513e4a11cf4acb27e26bc7577cebfa0b" + digest = "1:9652da56be8fe4998e79e36be6b9d30fe4fd4aacb73ecf0d9b3a33228189dc7e" name = "golang.org/x/sys" packages = ["unix"] pruneopts = "UT" - revision = "62eef0e2fa9b2c385f7b2778e763486da6880d37" + revision = "b4a75ba826a64a70990f11a225237acd6ef35c9f" [[projects]] branch = "v2" @@ -196,6 +204,7 @@ "github.com/chebyrash/promise", "github.com/gorilla/handlers", "github.com/gorilla/mux", + "github.com/robfig/cron", "github.com/stellar/go/build", "github.com/stellar/go/clients/horizon", "github.com/stellar/go/keypair", diff --git a/Gopkg.toml b/Gopkg.toml index d7bec995..d354ba24 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -37,6 +37,10 @@ name = "github.com/gorilla/mux" version = "1.6.2" +[[constraint]] + name = "github.com/robfig/cron" + version = "1.1.0" + [[constraint]] branch = "master" name = "github.com/stellar/go" @@ -48,3 +52,10 @@ [prune] go-tests = true unused-packages = true + +[metadata.heroku] + root-package = "github.com/dileepaj/tracified-gateway" + go-version = "go1.10.3" + install = [ "." ] + ensure = "true" + additional-tools = ["github.com/golang-migrate/migrate"] \ No newline at end of file diff --git a/Procfile b/Procfile new file mode 100644 index 00000000..bdb03546 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: tracified-gateway \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 81e57a81..00000000 --- a/README.md +++ /dev/null @@ -1,68 +0,0 @@ -# Tracified Blockchain - -This project implements the tracified Blockchain-gateway. - -# Git Workflow - -Master branch is the main development branch. Do not commit directly to master branch. -Staging branch is for the staging environment which mimics production environment. - -**TODO: figure out who, when and how to merge to staging branch** - - -Steps to contribute: - -- Clone a local repo or if already cloned pull latest version with `git pull` -- Create a new feature branch for the work you're doing `git checkout -b feature-branch-name` -- Develop, Add, Commit as much as you like 😎 -- Once your feature is complete and all tests are passed, you can push your branch to bitbucket with `git push -u origin feature-branch-name` -- Goto bitbucket and create a new pull request to merge your feature branch -- Add a team member to review your pull request and ask to merge. - -# Getting Started - -- GO Installation - https://docs.google.com/document/d/1yTEBXge5kwnq5u6AUcPC61OALerW1SFoAh6KqPme-MY/edit?usp=sharing -``` -``` -- Setting Environmental variables - -``` - set GOPATH=E:\GO\ -``` - -- Install packages - -``` - go get -u github.com/golang/dep/cmd/dep - dep init - dep ensure - - -``` - -- Build - -``` - go build -``` - -- Run - -``` - go run main.go -``` - -# Folder Structure - -| Name | Description | -| ------------------------ | ----------------------------------------------------------------- | -| **bin** | Contains the executable from the GO build. | -| **src** | Contains source code that will be compiled to the exe file | -| **pkg** | Contains packages that are/ has to be imported. | - -#Logging && Error - - Log errors exactly where they occur. - - DO NOT LOG class OR function names - - Pass errors to upper layers ONLY TO IDENTIFY WHAT WENT WRONG AND SEND CLIENT APPROPRIATE RESPONSE (not to log errors in upper layers) - - If we require to send message to upper layers regarding the type of errors, define them in the comments and pass that message In other instances if upper layers don't have to know exactly what types of erros can come in advance just pass them to upper layers. diff --git a/api/APImodel/dao.go b/api/apiModel/dao.go similarity index 88% rename from api/APImodel/dao.go rename to api/apiModel/dao.go index 20e235ad..0f2dfe83 100644 --- a/api/APImodel/dao.go +++ b/api/apiModel/dao.go @@ -1,7 +1,8 @@ package apiModel import( - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/model" + ) type GetCOCCollection struct { diff --git a/api/APImodel/proof.go b/api/apiModel/proof.go similarity index 97% rename from api/APImodel/proof.go rename to api/apiModel/proof.go index ca396fa0..bb936cc5 100644 --- a/api/APImodel/proof.go +++ b/api/apiModel/proof.go @@ -1,7 +1,7 @@ package apiModel import ( - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/model" ) //poc Success response @@ -56,11 +56,15 @@ type InsertSuccess struct { // } type SubmitXDRSuccess struct { - Message string - Txns []model.TransactionCollectionBody - + Status string } +// type SubmitXDRSuccess struct { +// Message string +// Txns []model.TransactionCollectionBody + +// } + type GenesisSuccess struct { Message string ProfileTxn string @@ -210,7 +214,7 @@ type InsertTDP struct { } type TestTDP struct { - XDR string + XDR string // RawTDP string } diff --git a/api/businessFacades/cocHandlers.go b/api/businessFacades/cocHandlers.go new file mode 100644 index 00000000..9beed918 --- /dev/null +++ b/api/businessFacades/cocHandlers.go @@ -0,0 +1,330 @@ +package businessFacades + +import ( + // "io/ioutil" + "github.com/dileepaj/tracified-gateway/dao" + // "github.com/dileepaj/tracified-gateway/proofs/retriever/stellarRetriever" + + // "gopkg.in/mgo.v2/bson" + // "github.com/fanliao/go-promise" + + // "gopkg.in/mgo.v2" + "github.com/stellar/go/build" + "github.com/stellar/go/xdr" + + "encoding/json" + "fmt" + // "gopkg.in/mgo.v2" + + "net/http" + + // "github.com/fanliao/go-promise" + "github.com/gorilla/mux" + + "github.com/dileepaj/tracified-gateway/api/apiModel" + // "github.com/dileepaj/tracified-gateway/dao" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/builder" + // "github.com/dileepaj/tracified-gateway/proofs/interpreter" +) + +func GetCocBySender(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + + object := dao.Connection{} + p := object.GetCOCbySender(vars["Sender"]) + p.Then(func(data interface{}) interface{} { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) + // result := apiModel.GetMultiCOCCollection{ + // Collection: data} + json.NewEncoder(w).Encode(data) + return data + }).Catch(func(error error) error { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusNotFound) + // result := model.Error{Code: http.StatusNotFound, + // Message: "No Results Found"} + json.NewEncoder(w).Encode(error) + return error + }) + p.Await() + +} + +func GetCocByReceiver(w http.ResponseWriter, r *http.Request) { + vars := mux.Vars(r) + + object := dao.Connection{} + p := object.GetCOCbyReceiver(vars["Receiver"]) + p.Then(func(data interface{}) interface{} { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) + // result := apiModel.GetMultiCOCCollection{ + // Collection: data} + json.NewEncoder(w).Encode(data) + return data + }).Catch(func(error error) error { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusNotFound) + // result := model.Error{Code: http.StatusNotFound, + // Message: "No Results Found"} + json.NewEncoder(w).Encode(error) + return error + }) + p.Await() + +} + +func InsertCocCollection(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + var GObj model.COCCollectionBody + err := json.NewDecoder(r.Body).Decode(&GObj) + if err != nil { + w.WriteHeader(http.StatusBadRequest) + json.NewEncoder(w).Encode("Error while Decoding the body") + fmt.Println(err) + return + } + var accept xdr.Transaction + var reject xdr.Transaction + err = xdr.SafeUnmarshalBase64(GObj.AcceptXdr, &accept) + if err != nil { + fmt.Println(err) + } + + brr := build.TransactionBuilder{TX: &accept, NetworkPassphrase: build.TestNetwork.Passphrase} + fmt.Println(build.TestNetwork.Passphrase) + // fmt.Println(brr.Hash()) + t, _ := brr.Hash() + test := fmt.Sprintf("%x", t) + + err = xdr.SafeUnmarshalBase64(GObj.RejectXdr, &reject) + if err != nil { + fmt.Println(err) + } + + brr1 := build.TransactionBuilder{TX: &reject, NetworkPassphrase: build.TestNetwork.Passphrase} + fmt.Println(build.TestNetwork.Passphrase) + // fmt.Println(brr.Hash()) + t1, _ := brr1.Hash() + test1 := fmt.Sprintf("%x", t1) + + GObj.AcceptTxn = test + GObj.RejectTxn = test1 + fmt.Println(GObj) + object := dao.Connection{} + err1 := object.InsertCoc(GObj) + + if err1 != nil { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusNotFound) + result := apiModel.InsertCOCCollectionResponse{ + Message: "Failed"} + json.NewEncoder(w).Encode(result) + return + } else { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) + result := apiModel.InsertCOCCollectionResponse{ + Message: "Success", Body: GObj} + json.NewEncoder(w).Encode(result) + return + } +} + +func UpdateCocCollection(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + var GObj model.COCCollectionBody + var selection model.COCCollectionBody + var result apiModel.InsertCOCCollectionResponse + + err := json.NewDecoder(r.Body).Decode(&GObj) + if err != nil { + w.WriteHeader(http.StatusBadRequest) + json.NewEncoder(w).Encode("Error while Decoding the body") + fmt.Println(err) + return + } + fmt.Println(GObj) + object := dao.Connection{} + switch GObj.Status { + case "accepted": + p := object.GetCOCbyAcceptTxn(GObj.AcceptTxn) + p.Then(func(data interface{}) interface{} { + selection = data.(model.COCCollectionBody) + display := &builder.AbstractTDPInsert{XDR: GObj.AcceptXdr} + response := display.TDPInsert() + + if response.Error.Code == 404 { + w.WriteHeader(response.Error.Code) + result = apiModel.InsertCOCCollectionResponse{ + Message: "Failed"} + json.NewEncoder(w).Encode(result) + }else{ + selection.TxnHash=response.TXNID + err1 := object.UpdateCOC(selection, GObj) + if err1 != nil { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusNotFound) + result = apiModel.InsertCOCCollectionResponse{ + Message: "Failed"} + json.NewEncoder(w).Encode(result) + + } else { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) + body:=selection + body.AcceptTxn=GObj.AcceptTxn + body.AcceptXdr=GObj.AcceptXdr + body.Status=GObj.Status + result = apiModel.InsertCOCCollectionResponse{ + Message: "Success", Body: body} + json.NewEncoder(w).Encode(result) + + } + } + + + + return data + }).Catch(func(error error) error { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusNotFound) + json.NewEncoder(w).Encode(error) + return error + }) + p.Await() + break + case "rejected": + p := object.GetCOCbyRejectTxn(GObj.RejectTxn) + p.Then(func(data interface{}) interface{} { + selection = data.(model.COCCollectionBody) + display := &builder.AbstractTDPInsert{XDR: GObj.RejectXdr} + response := display.TDPInsert() + + if response.Error.Code == 404 { + w.WriteHeader(response.Error.Code) + result = apiModel.InsertCOCCollectionResponse{ + Message: "Failed"} + json.NewEncoder(w).Encode(result) + }else{ + selection.TxnHash=response.TXNID + err1 := object.UpdateCOC(selection, GObj) + if err1 != nil { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusNotFound) + result = apiModel.InsertCOCCollectionResponse{ + Message: "Failed"} + json.NewEncoder(w).Encode(result) + + } else { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) + body:=selection + body.RejectTxn=GObj.RejectTxn + body.RejectXdr=GObj.RejectXdr + body.Status=GObj.Status + result = apiModel.InsertCOCCollectionResponse{ + Message: "Success", Body: body} + json.NewEncoder(w).Encode(result) + + } + } + + + + return data + }).Catch(func(error error) error { + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusNotFound) + json.NewEncoder(w).Encode(error) + return error + }) + p.Await() + break + } + + + + // err1 := object.UpdateCOC(selection, GObj) + // if err1 != nil { + // w.Header().Set("Content-Type", "application/json; charset=UTF-8") + // w.WriteHeader(http.StatusNotFound) + // result := apiModel.InsertCOCCollectionResponse{ + // Message: "Failed"} + // json.NewEncoder(w).Encode(result) + // return + // } else { + // w.Header().Set("Content-Type", "application/json; charset=UTF-8") + // w.WriteHeader(http.StatusOK) + // result := apiModel.InsertCOCCollectionResponse{ + // Message: "Success", Body: GObj} + // json.NewEncoder(w).Encode(result) + // return + // } + return +} + +// func InsertTransactionCollection(w http.ResponseWriter, r *http.Request) { +// w.Header().Set("Content-Type", "application/json; charset=UTF-8") +// var GObj model.TransactionCollectionBody +// err := json.NewDecoder(r.Body).Decode(&GObj) +// if err != nil { +// w.WriteHeader(http.StatusBadRequest) +// json.NewEncoder(w).Encode("Error while Decoding the body") +// fmt.Println(err) +// return +// } + +// fmt.Println(GObj) +// object := dao.Connection{} +// err1 := object.InsertTransaction(GObj) + +// if err1 != nil { +// w.Header().Set("Content-Type", "application/json; charset=UTF-8") +// w.WriteHeader(http.StatusNotFound) +// result := apiModel.InsertTransactionCollectionResponse{ +// Message: "Failed"} +// json.NewEncoder(w).Encode(result) +// return +// } else { +// w.Header().Set("Content-Type", "application/json; charset=UTF-8") +// w.WriteHeader(http.StatusOK) +// result := apiModel.InsertTransactionCollectionResponse{ +// Message: "Success", Body: GObj} +// json.NewEncoder(w).Encode(result) +// return +// } +// } +// func UpdateTransactionCollection(w http.ResponseWriter, r *http.Request) { +// w.Header().Set("Content-Type", "application/json; charset=UTF-8") +// var GObj model.TransactionUpdate +// err := json.NewDecoder(r.Body).Decode(&GObj) +// if err != nil { +// w.WriteHeader(http.StatusBadRequest) +// json.NewEncoder(w).Encode("Error while Decoding the body") +// fmt.Println(err) +// return +// } + +// fmt.Println(GObj) +// object := dao.Connection{} +// err1 := object.UpdateTransaction(GObj.Selector,GObj.Update) + +// if err1 != nil { +// w.Header().Set("Content-Type", "application/json; charset=UTF-8") +// w.WriteHeader(http.StatusNotFound) +// result := apiModel.InsertTransactionCollectionResponse{ +// Message: "Failed"} +// json.NewEncoder(w).Encode(result) +// return +// } else { +// w.Header().Set("Content-Type", "application/json; charset=UTF-8") +// w.WriteHeader(http.StatusOK) +// result := apiModel.InsertTransactionCollectionResponse{ +// Message: "Success", Body: GObj.Update} +// json.NewEncoder(w).Encode(result) +// return +// } +// } diff --git a/api/businessFacades/handlers.go b/api/businessFacades/handlers.go index 2c60c975..81ef2f79 100644 --- a/api/businessFacades/handlers.go +++ b/api/businessFacades/handlers.go @@ -2,15 +2,15 @@ package businessFacades import ( // "io/ioutil" - "github.com/tracified-gateway/dao" - "github.com/tracified-gateway/proofs/retriever/stellarRetriever" + // "github.com/dileepaj/tracified-gateway/dao" + "github.com/dileepaj/tracified-gateway/proofs/retriever/stellarRetriever" // "gopkg.in/mgo.v2/bson" // "github.com/fanliao/go-promise" // "gopkg.in/mgo.v2" - "github.com/stellar/go/build" - "github.com/stellar/go/xdr" + // "github.com/stellar/go/build" + // "github.com/stellar/go/xdr" "encoding/json" "fmt" @@ -21,11 +21,11 @@ import ( // "github.com/fanliao/go-promise" "github.com/gorilla/mux" - "github.com/tracified-gateway/api/apiModel" - // "github.com/tracified-gateway/dao" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/builder" - // "github.com/tracified-gateway/proofs/interpreter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + // "github.com/dileepaj/tracified-gateway/dao" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/builder" + // "github.com/dileepaj/tracified-gateway/proofs/interpreter" ) func CreateTrust(w http.ResponseWriter, r *http.Request) { @@ -258,304 +258,3 @@ func DeveloperRetriever(w http.ResponseWriter, r *http.Request) { return } - -func GetCocBySender(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - - object := dao.Connection{} - p := object.GetCOCbySender(vars["Sender"]) - p.Then(func(data interface{}) interface{} { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) - // result := apiModel.GetMultiCOCCollection{ - // Collection: data} - json.NewEncoder(w).Encode(data) - return data - }).Catch(func(error error) error { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusNotFound) - // result := model.Error{Code: http.StatusNotFound, - // Message: "No Results Found"} - json.NewEncoder(w).Encode(error) - return error - }) - p.Await() - -} - -func GetCocByReceiver(w http.ResponseWriter, r *http.Request) { - vars := mux.Vars(r) - - object := dao.Connection{} - p := object.GetCOCbyReceiver(vars["Receiver"]) - p.Then(func(data interface{}) interface{} { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) - // result := apiModel.GetMultiCOCCollection{ - // Collection: data} - json.NewEncoder(w).Encode(data) - return data - }).Catch(func(error error) error { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusNotFound) - // result := model.Error{Code: http.StatusNotFound, - // Message: "No Results Found"} - json.NewEncoder(w).Encode(error) - return error - }) - p.Await() - -} - -func InsertCocCollection(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - var GObj model.COCCollectionBody - err := json.NewDecoder(r.Body).Decode(&GObj) - if err != nil { - w.WriteHeader(http.StatusBadRequest) - json.NewEncoder(w).Encode("Error while Decoding the body") - fmt.Println(err) - return - } - var accept xdr.Transaction - var reject xdr.Transaction - err = xdr.SafeUnmarshalBase64(GObj.AcceptXdr, &accept) - if err != nil { - fmt.Println(err) - } - - brr := build.TransactionBuilder{TX: &accept, NetworkPassphrase: build.TestNetwork.Passphrase} - fmt.Println(build.TestNetwork.Passphrase) - // fmt.Println(brr.Hash()) - t, _ := brr.Hash() - test := fmt.Sprintf("%x", t) - - err = xdr.SafeUnmarshalBase64(GObj.RejectXdr, &reject) - if err != nil { - fmt.Println(err) - } - - brr1 := build.TransactionBuilder{TX: &reject, NetworkPassphrase: build.TestNetwork.Passphrase} - fmt.Println(build.TestNetwork.Passphrase) - // fmt.Println(brr.Hash()) - t1, _ := brr1.Hash() - test1 := fmt.Sprintf("%x", t1) - - GObj.AcceptTxn = test - GObj.RejectTxn = test1 - fmt.Println(GObj) - object := dao.Connection{} - err1 := object.InsertCoc(GObj) - - if err1 != nil { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusNotFound) - result := apiModel.InsertCOCCollectionResponse{ - Message: "Failed"} - json.NewEncoder(w).Encode(result) - return - } else { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) - result := apiModel.InsertCOCCollectionResponse{ - Message: "Success", Body: GObj} - json.NewEncoder(w).Encode(result) - return - } -} - -func UpdateCocCollection(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - var GObj model.COCCollectionBody - var selection model.COCCollectionBody - var result apiModel.InsertCOCCollectionResponse - - err := json.NewDecoder(r.Body).Decode(&GObj) - if err != nil { - w.WriteHeader(http.StatusBadRequest) - json.NewEncoder(w).Encode("Error while Decoding the body") - fmt.Println(err) - return - } - fmt.Println(GObj) - object := dao.Connection{} - switch GObj.Status { - case "accepted": - p := object.GetCOCbyAcceptTxn(GObj.AcceptTxn) - p.Then(func(data interface{}) interface{} { - selection = data.(model.COCCollectionBody) - display := &builder.AbstractTDPInsert{XDR: GObj.AcceptXdr} - response := display.TDPInsert() - - if response.Error.Code == 404 { - w.WriteHeader(response.Error.Code) - result = apiModel.InsertCOCCollectionResponse{ - Message: "Failed"} - json.NewEncoder(w).Encode(result) - }else{ - selection.TxnHash=response.TXNID - err1 := object.UpdateCOC(selection, GObj) - if err1 != nil { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusNotFound) - result = apiModel.InsertCOCCollectionResponse{ - Message: "Failed"} - json.NewEncoder(w).Encode(result) - - } else { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) - body:=selection - body.AcceptTxn=GObj.AcceptTxn - body.AcceptXdr=GObj.AcceptXdr - body.Status=GObj.Status - result = apiModel.InsertCOCCollectionResponse{ - Message: "Success", Body: body} - json.NewEncoder(w).Encode(result) - - } - } - - - - return data - }).Catch(func(error error) error { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusNotFound) - json.NewEncoder(w).Encode(error) - return error - }) - p.Await() - break - case "rejected": - p := object.GetCOCbyRejectTxn(GObj.RejectTxn) - p.Then(func(data interface{}) interface{} { - selection = data.(model.COCCollectionBody) - display := &builder.AbstractTDPInsert{XDR: GObj.RejectXdr} - response := display.TDPInsert() - - if response.Error.Code == 404 { - w.WriteHeader(response.Error.Code) - result = apiModel.InsertCOCCollectionResponse{ - Message: "Failed"} - json.NewEncoder(w).Encode(result) - }else{ - selection.TxnHash=response.TXNID - err1 := object.UpdateCOC(selection, GObj) - if err1 != nil { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusNotFound) - result = apiModel.InsertCOCCollectionResponse{ - Message: "Failed"} - json.NewEncoder(w).Encode(result) - - } else { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusOK) - body:=selection - body.RejectTxn=GObj.RejectTxn - body.RejectXdr=GObj.RejectXdr - body.Status=GObj.Status - result = apiModel.InsertCOCCollectionResponse{ - Message: "Success", Body: body} - json.NewEncoder(w).Encode(result) - - } - } - - - - return data - }).Catch(func(error error) error { - w.Header().Set("Content-Type", "application/json; charset=UTF-8") - w.WriteHeader(http.StatusNotFound) - json.NewEncoder(w).Encode(error) - return error - }) - p.Await() - break - } - - - - // err1 := object.UpdateCOC(selection, GObj) - // if err1 != nil { - // w.Header().Set("Content-Type", "application/json; charset=UTF-8") - // w.WriteHeader(http.StatusNotFound) - // result := apiModel.InsertCOCCollectionResponse{ - // Message: "Failed"} - // json.NewEncoder(w).Encode(result) - // return - // } else { - // w.Header().Set("Content-Type", "application/json; charset=UTF-8") - // w.WriteHeader(http.StatusOK) - // result := apiModel.InsertCOCCollectionResponse{ - // Message: "Success", Body: GObj} - // json.NewEncoder(w).Encode(result) - // return - // } - return -} - -// func InsertTransactionCollection(w http.ResponseWriter, r *http.Request) { -// w.Header().Set("Content-Type", "application/json; charset=UTF-8") -// var GObj model.TransactionCollectionBody -// err := json.NewDecoder(r.Body).Decode(&GObj) -// if err != nil { -// w.WriteHeader(http.StatusBadRequest) -// json.NewEncoder(w).Encode("Error while Decoding the body") -// fmt.Println(err) -// return -// } - -// fmt.Println(GObj) -// object := dao.Connection{} -// err1 := object.InsertTransaction(GObj) - -// if err1 != nil { -// w.Header().Set("Content-Type", "application/json; charset=UTF-8") -// w.WriteHeader(http.StatusNotFound) -// result := apiModel.InsertTransactionCollectionResponse{ -// Message: "Failed"} -// json.NewEncoder(w).Encode(result) -// return -// } else { -// w.Header().Set("Content-Type", "application/json; charset=UTF-8") -// w.WriteHeader(http.StatusOK) -// result := apiModel.InsertTransactionCollectionResponse{ -// Message: "Success", Body: GObj} -// json.NewEncoder(w).Encode(result) -// return -// } -// } -// func UpdateTransactionCollection(w http.ResponseWriter, r *http.Request) { -// w.Header().Set("Content-Type", "application/json; charset=UTF-8") -// var GObj model.TransactionUpdate -// err := json.NewDecoder(r.Body).Decode(&GObj) -// if err != nil { -// w.WriteHeader(http.StatusBadRequest) -// json.NewEncoder(w).Encode("Error while Decoding the body") -// fmt.Println(err) -// return -// } - -// fmt.Println(GObj) -// object := dao.Connection{} -// err1 := object.UpdateTransaction(GObj.Selector,GObj.Update) - -// if err1 != nil { -// w.Header().Set("Content-Type", "application/json; charset=UTF-8") -// w.WriteHeader(http.StatusNotFound) -// result := apiModel.InsertTransactionCollectionResponse{ -// Message: "Failed"} -// json.NewEncoder(w).Encode(result) -// return -// } else { -// w.Header().Set("Content-Type", "application/json; charset=UTF-8") -// w.WriteHeader(http.StatusOK) -// result := apiModel.InsertTransactionCollectionResponse{ -// Message: "Success", Body: GObj.Update} -// json.NewEncoder(w).Encode(result) -// return -// } -// } diff --git a/api/businessFacades/proofHandlers.go b/api/businessFacades/proofHandlers.go index e1396f1e..2aa8d7fb 100644 --- a/api/businessFacades/proofHandlers.go +++ b/api/businessFacades/proofHandlers.go @@ -1,9 +1,9 @@ package businessFacades import ( - "github.com/tracified-gateway/dao" + "github.com/dileepaj/tracified-gateway/dao" - // "github.com/tracified-gateway/proofs/retriever/stellarRetriever" + // "github.com/dileepaj/tracified-gateway/proofs/retriever/stellarRetriever" "crypto/sha256" "net/http" @@ -17,11 +17,11 @@ import ( "github.com/gorilla/mux" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" - // "github.com/tracified-gateway/proofs/builder" - "github.com/tracified-gateway/proofs/interpreter" + // "github.com/dileepaj/tracified-gateway/proofs/builder" + "github.com/dileepaj/tracified-gateway/proofs/interpreter" ) // func CheckPOC(w http.ResponseWriter, r *http.Request) { diff --git a/api/businessFacades/test.json b/api/businessFacades/test.json deleted file mode 100644 index e69de29b..00000000 diff --git a/api/businessFacades/transactionHandlers.go b/api/businessFacades/transactionHandlers.go index a8537eb7..eb19c227 100644 --- a/api/businessFacades/transactionHandlers.go +++ b/api/businessFacades/transactionHandlers.go @@ -7,10 +7,10 @@ import ( "strings" "github.com/gorilla/mux" "github.com/stellar/go/xdr" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/dao" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/builder" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/dao" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/builder" ) func Transaction(w http.ResponseWriter, r *http.Request) { @@ -274,8 +274,7 @@ func SubmitXDR(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) result := apiModel.SubmitXDRSuccess{ - Message: "Success, Please check each transaction status below", - Txns: TDP, + Status: "Success", } json.NewEncoder(w).Encode(result) return @@ -305,3 +304,76 @@ func LastTxn(w http.ResponseWriter, r *http.Request) { p.Await() } +// func SplitXDR(w http.ResponseWriter, r *http.Request) { +// w.Header().Set("Content-Type", "application/json; charset=UTF-8") +// var TDP []model.TransactionCollectionBody +// object := dao.Connection{} +// var copy model.TransactionCollectionBody + +// if r.Header == nil { +// w.WriteHeader(http.StatusBadRequest) +// json.NewEncoder(w).Encode("No Header present!") +// return +// } + +// if r.Header.Get("Content-Type") == "" { +// w.WriteHeader(http.StatusBadRequest) +// json.NewEncoder(w).Encode("No Content-Type present!") +// return +// } + +// err := json.NewDecoder(r.Body).Decode(&TDP) +// if err != nil { +// w.WriteHeader(http.StatusBadRequest) +// json.NewEncoder(w).Encode("Error while Decoding the body") +// // fmt.Println(err) +// return +// } +// for i := 0; i < len(TDP); i++ { +// TDP[i].Status = "Pending" +// var txe xdr.Transaction +// err = xdr.SafeUnmarshalBase64(TDP[i].XDR, &txe) +// if err != nil { +// fmt.Println(err) +// } + +// TDP[i].PublicKey = txe.SourceAccount.Address() +// TxnType := strings.TrimLeft(fmt.Sprintf("%s", txe.Operations[0].Body.ManageDataOp.DataValue), "&") +// TDP[i].TxnType = TxnType +// TDP[i].Status = "pending" + +// copy=TDP[i] +// err1 := object.InsertTransaction(TDP[i]) +// if err1 != nil { +// TDP[i].Status = "failed" +// } + +// } +// for i := 0; i < len(TDP); i++ { +// display := &builder.AbstractTDPInsert{XDR: TDP[i].XDR} +// response := display.TDPInsert() +// if response.Error.Code == 503 { +// TDP[i].Status = "pending" +// } else { +// TDP[i].TxnHash = response.TXNID + +// upd := model.TransactionCollectionBody{TxnHash: response.TXNID, Status: "done"} +// err2 := object.UpdateTransaction(copy, upd) +// if err2 != nil { +// TDP[i].Status = "pending" +// } else { +// TDP[i].Status = "done" +// } +// } +// } + +// w.WriteHeader(http.StatusOK) +// result := apiModel.SubmitXDRSuccess{ +// Message: "Success, Please check each transaction status below", +// Txns: TDP, +// } +// json.NewEncoder(w).Encode(result) +// return +// } + + diff --git a/api/logger.go b/api/routes/logger.go similarity index 95% rename from api/logger.go rename to api/routes/logger.go index fa35a6de..1226d64f 100644 --- a/api/logger.go +++ b/api/routes/logger.go @@ -1,4 +1,4 @@ -package api +package routes import ( "log" diff --git a/api/routes/router.go b/api/routes/router.go index 3529727c..abb6a35b 100644 --- a/api/routes/router.go +++ b/api/routes/router.go @@ -5,7 +5,7 @@ import ( "github.com/gorilla/mux" - "github.com/tracified-gateway/api" + // "github.com/dileepaj/tracified-gateway/api" ) func NewRouter() *mux.Router { @@ -15,7 +15,7 @@ func NewRouter() *mux.Router { var handler http.Handler handler = route.HandlerFunc - handler = api.Logger(handler, route.Name) + handler = Logger(handler, route.Name) router. Methods(route.Method). diff --git a/api/routes/routes.go b/api/routes/routes.go index ebfd347b..c449f579 100644 --- a/api/routes/routes.go +++ b/api/routes/routes.go @@ -2,8 +2,7 @@ package routes import ( "net/http" - - "github.com/tracified-gateway/api/businessFacades" + "github.com/dileepaj/tracified-gateway/api/businessFacades" ) type Route struct { @@ -81,7 +80,7 @@ var routes = Routes{ "POST", "/COCLink/Transaction", businessFacades.COCLink, - },Route{ + }, Route{ "POCDeveloperRetriever", "get", "/pocbctree/{Txn}", @@ -92,7 +91,7 @@ var routes = Routes{ "get", "/getcocbysender/{Sender}", businessFacades.GetCocBySender, - },Route{ + }, Route{ "GetCOCCollectionByReceiver", "get", "/getcocbyreceiver/{Receiver}", @@ -125,12 +124,33 @@ var routes = Routes{ Route{ "SubmitXDR", "POST", - "/submitxdr", + "/transaction/dataPacket", + businessFacades.SubmitXDR, + }, + Route{ + "SubmitSplit", + "POST", + "/transaction/split", businessFacades.SubmitXDR, },Route{ + "SubmitGenesis", + "POST", + "/transaction/genesis", + businessFacades.SubmitXDR, + },Route{ + "SubmitTransformation", + "POST", + "/transaction/transformation", + businessFacades.SubmitXDR, + },Route{ + "SubmitMerge", + "POST", + "/transaction/merge", + businessFacades.SubmitXDR, + }, Route{ "LastTxn", "GET", - "/lastTxn/{Identifier}", + "/transaction/lastTxn/{Identifier}", businessFacades.LastTxn, }, } diff --git a/dao/insert.go b/dao/insert.go index b292038c..7eb089f3 100644 --- a/dao/insert.go +++ b/dao/insert.go @@ -3,7 +3,7 @@ package dao import ( "fmt" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/model" ) func (cd *Connection) InsertCoc(Coc model.COCCollectionBody) error { diff --git a/dao/retrieve.go b/dao/retrieve.go index 3e06f5e7..2a99e926 100644 --- a/dao/retrieve.go +++ b/dao/retrieve.go @@ -1,7 +1,7 @@ package dao import ( - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/model" "gopkg.in/mgo.v2/bson" @@ -130,6 +130,35 @@ func (cd *Connection) GetCOCbyRejectTxn(rejecttxn string) *promise.Promise { } +func (cd *Connection) GetCOCbyStatus(status string) *promise.Promise { + result := []model.COCCollectionBody{} + // p := promise.NewPromise() + + var p = promise.New(func(resolve func(interface{}), reject func(error)) { + // Do something asynchronously. + session, err := cd.connect() + + if err != nil { + fmt.Println(err) + reject(err) + + } + defer session.Close() + + c := session.DB("tracified-gateway").C("COC") + err1 := c.Find(bson.M{"status": status}).All(&result) + if err1 != nil || len(result) == 0 { + fmt.Println(err1) + reject(err1) + + } + resolve(result) + + }) + + return p + +} func (cd *Connection) GetLastTransactionbyIdentifier(identifier string) *promise.Promise { result := []model.TransactionCollectionBody{} diff --git a/dao/update.go b/dao/update.go index c84963c8..a8ea133f 100644 --- a/dao/update.go +++ b/dao/update.go @@ -3,7 +3,7 @@ package dao import ( "fmt" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/model" ) func (cd *Connection) UpdateTransaction(selector model.TransactionCollectionBody, update model.TransactionCollectionBody) error { @@ -45,6 +45,7 @@ func (cd *Connection) UpdateCOC(selector model.COCCollectionBody, update model.C } defer session.Close() + fmt.Println(update.Status) switch update.Status { case "accepted": up := model.COCCollectionBody{ @@ -63,6 +64,8 @@ func (cd *Connection) UpdateCOC(selector model.COCCollectionBody, update model.C err1 := c.Update(selector, up) if err1 != nil { fmt.Println(err1) + return err1 + } break case "rejected": @@ -82,10 +85,33 @@ func (cd *Connection) UpdateCOC(selector model.COCCollectionBody, update model.C err1 := c.Update(selector, up) if err1 != nil { fmt.Println(err1) + return err1 + } break + case "expired": + up := model.COCCollectionBody{ + TxnHash: selector.TxnHash, + Sender: selector.Sender, + Receiver: selector.Receiver, + AcceptXdr: selector.AcceptXdr, + RejectXdr: selector.RejectXdr, + AcceptTxn: selector.AcceptTxn, + RejectTxn: selector.RejectTxn, + Identifier: selector.Identifier, + Status: update.Status, + } + + c := session.DB("tracified-gateway").C("COC") + err1 := c.Update(selector, up) + if err1 != nil { + fmt.Println(err1) + return err1 + } + + break } return err diff --git a/main.go b/main.go index 4a28d58e..ea99ddbc 100644 --- a/main.go +++ b/main.go @@ -1,30 +1,41 @@ package main import ( - // "fmt" - "fmt" // "log" - "github.com/tracified-gateway/api/routes" "net/http" - // "github.com/robfig/cron" - "github.com/gorilla/handlers" + "os" + "github.com/dileepaj/tracified-gateway/api/routes" + // "github.com/dileepaj/tracified-gateway/services" + "github.com/gorilla/handlers" + // "github.com/joho/godotenv" + // "github.com/robfig/cron" ) +func getPort() string { + p := os.Getenv("PORT") + if p != "" { + return ":" + p + } + return ":8000" +} + + func main() { - + port := getPort() headersOk := handlers.AllowedHeaders([]string{"Content-Type"}) originsOk := handlers.AllowedOrigins([]string{"*"}) methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"}) // c := cron.New() - // // c.AddFunc("0 30 * * * *", func() { fmt.Println("Every hour on the half hour") }) - // // c.AddFunc("@hourly", func() { fmt.Println("Every hour") }) - // c.AddFunc("@every 30s", func() { fmt.Println("Every thirty") }) + // c.AddFunc("@every 30s", func() { + // services.CheckCOCStatus() + // }) // c.Start() - router := routes.NewRouter() - fmt.Println("Gateway Started @port :8030...!") - http.ListenAndServe(":8030", handlers.CORS(originsOk, headersOk, methodsOk)(router)) + + router := routes.NewRouter() + fmt.Println("Gateway Started @port " + port) + http.ListenAndServe(port, handlers.CORS(originsOk, headersOk, methodsOk)(router)) } diff --git a/model/daoModel.go b/model/daoModel.go index fab3fb9f..64e9648b 100644 --- a/model/daoModel.go +++ b/model/daoModel.go @@ -7,6 +7,8 @@ import( type COCCollectionBody struct { TxnHash string Sender string + SubAccount string + SequenceNo int Receiver string AcceptXdr string RejectXdr string diff --git a/proofs/builder/POATransactionBuild.go b/proofs/builder/POATransactionBuild.go index d7360317..641d73d6 100644 --- a/proofs/builder/POATransactionBuild.go +++ b/proofs/builder/POATransactionBuild.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) // type InsertPOA struct{} diff --git a/proofs/builder/POCertBuild.go b/proofs/builder/POCertBuild.go index 83267b2a..73747041 100644 --- a/proofs/builder/POCertBuild.go +++ b/proofs/builder/POCertBuild.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) // type InsertPOA struct{} diff --git a/proofs/builder/appointRegistrar.go b/proofs/builder/appointRegistrar.go index d7dcd242..e472c40c 100644 --- a/proofs/builder/appointRegistrar.go +++ b/proofs/builder/appointRegistrar.go @@ -1,9 +1,10 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) type AppointRegistrarInterface interface { diff --git a/proofs/builder/assetTransfer.go b/proofs/builder/assetTransfer.go index cd017883..91e65025 100644 --- a/proofs/builder/assetTransfer.go +++ b/proofs/builder/assetTransfer.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) type assetTransferInterface interface { diff --git a/proofs/builder/cocLink.go b/proofs/builder/cocLink.go index 6516a6bf..ab3e2b92 100644 --- a/proofs/builder/cocLink.go +++ b/proofs/builder/cocLink.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) type cocLinkInterface interface { diff --git a/proofs/builder/cocTransaction.go b/proofs/builder/cocTransaction.go index 9924bab7..c20cdf3c 100644 --- a/proofs/builder/cocTransaction.go +++ b/proofs/builder/cocTransaction.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) type cocTransactionInterface interface { diff --git a/proofs/builder/createRegistrarAcc.go b/proofs/builder/createRegistrarAcc.go index 22d0bfbc..19044e57 100644 --- a/proofs/builder/createRegistrarAcc.go +++ b/proofs/builder/createRegistrarAcc.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) type createRegistrarAccInterface interface { diff --git a/proofs/builder/insertData.go b/proofs/builder/insertData.go index 836fbabe..d92e1632 100644 --- a/proofs/builder/insertData.go +++ b/proofs/builder/insertData.go @@ -1,9 +1,9 @@ package builder import ( - // "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + // "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) // type InsertData struct{} diff --git a/proofs/builder/insertGenesis.go b/proofs/builder/insertGenesis.go index 173ef37c..ec3765f8 100644 --- a/proofs/builder/insertGenesis.go +++ b/proofs/builder/insertGenesis.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) type GenesisInsertInterface interface { diff --git a/proofs/builder/insertProfile.go b/proofs/builder/insertProfile.go index 4fa12378..7ab70f77 100644 --- a/proofs/builder/insertProfile.go +++ b/proofs/builder/insertProfile.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) // type InsertProfile struct{} diff --git a/proofs/builder/mergeBuilder.go b/proofs/builder/mergeBuilder.go index a4059b29..63ad24a1 100644 --- a/proofs/builder/mergeBuilder.go +++ b/proofs/builder/mergeBuilder.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) // type struct{} diff --git a/proofs/builder/splitBuilder.go b/proofs/builder/splitBuilder.go index 2c8e6bb6..51b59673 100644 --- a/proofs/builder/splitBuilder.go +++ b/proofs/builder/splitBuilder.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) // type struct{} diff --git a/proofs/builder/transformAssets.go b/proofs/builder/transformAssets.go index 596a9ca6..51c52aca 100644 --- a/proofs/builder/transformAssets.go +++ b/proofs/builder/transformAssets.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) type transformAssetsInterface interface { diff --git a/proofs/builder/trustLine.go b/proofs/builder/trustLine.go index 0c8167b2..9d80b0d4 100644 --- a/proofs/builder/trustLine.go +++ b/proofs/builder/trustLine.go @@ -1,9 +1,9 @@ package builder import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/executer/stellarExecuter" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/executer/stellarExecuter" ) type TrustlineInterface interface { diff --git a/proofs/executer/stellarExecuter/POATransactionExec.go b/proofs/executer/stellarExecuter/POATransactionExec.go index 7d02b51a..fc65972f 100644 --- a/proofs/executer/stellarExecuter/POATransactionExec.go +++ b/proofs/executer/stellarExecuter/POATransactionExec.go @@ -7,8 +7,8 @@ import ( "github.com/stellar/go/build" "github.com/stellar/go/clients/horizon" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" ) type ConcreteInsertPOA struct { diff --git a/proofs/executer/stellarExecuter/POCertExec.go b/proofs/executer/stellarExecuter/POCertExec.go index 4584e1b1..fe0a641f 100644 --- a/proofs/executer/stellarExecuter/POCertExec.go +++ b/proofs/executer/stellarExecuter/POCertExec.go @@ -7,8 +7,8 @@ import ( "github.com/stellar/go/build" "github.com/stellar/go/clients/horizon" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" ) type ConcreteInsertPOCert struct { diff --git a/proofs/executer/stellarExecuter/RegistrarRequest.go b/proofs/executer/stellarExecuter/RegistrarRequest.go index b97e4ed4..afb7ce47 100644 --- a/proofs/executer/stellarExecuter/RegistrarRequest.go +++ b/proofs/executer/stellarExecuter/RegistrarRequest.go @@ -3,7 +3,7 @@ package stellarExecuter import ( "fmt" "log" - "github.com/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/api/apiModel" "strconv" "github.com/stellar/go/build" diff --git a/proofs/executer/stellarExecuter/changeOfCustody.go b/proofs/executer/stellarExecuter/changeOfCustody.go index c62f7289..e1d5dccb 100644 --- a/proofs/executer/stellarExecuter/changeOfCustody.go +++ b/proofs/executer/stellarExecuter/changeOfCustody.go @@ -3,8 +3,8 @@ package stellarExecuter import ( "net/http" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" "github.com/stellar/go/build" "github.com/stellar/go/clients/horizon" diff --git a/proofs/executer/stellarExecuter/cocLinkage.go b/proofs/executer/stellarExecuter/cocLinkage.go index f95be870..8e0d87bd 100644 --- a/proofs/executer/stellarExecuter/cocLinkage.go +++ b/proofs/executer/stellarExecuter/cocLinkage.go @@ -3,7 +3,7 @@ package stellarExecuter import ( "log" - "github.com/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/api/apiModel" "github.com/stellar/go/build" "github.com/stellar/go/clients/horizon" diff --git a/proofs/executer/stellarExecuter/createTrustLine.go b/proofs/executer/stellarExecuter/createTrustLine.go index 1b13e11e..4a47c07b 100644 --- a/proofs/executer/stellarExecuter/createTrustLine.go +++ b/proofs/executer/stellarExecuter/createTrustLine.go @@ -3,7 +3,7 @@ package stellarExecuter import ( "log" - "github.com/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/api/apiModel" "github.com/stellar/go/build" "github.com/stellar/go/clients/horizon" diff --git a/proofs/executer/stellarExecuter/genesisCreation.go b/proofs/executer/stellarExecuter/genesisCreation.go index 1262e6d7..37a7f0fa 100644 --- a/proofs/executer/stellarExecuter/genesisCreation.go +++ b/proofs/executer/stellarExecuter/genesisCreation.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" "github.com/stellar/go/build" "github.com/stellar/go/clients/horizon" diff --git a/proofs/executer/stellarExecuter/insertData.go b/proofs/executer/stellarExecuter/insertData.go index 88b4fb9c..8fecd105 100644 --- a/proofs/executer/stellarExecuter/insertData.go +++ b/proofs/executer/stellarExecuter/insertData.go @@ -6,8 +6,8 @@ import ( "github.com/stellar/go/clients/horizon" - // "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + // "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" ) type ConcreteInsertData struct { diff --git a/proofs/executer/stellarExecuter/mergeExecuter.go b/proofs/executer/stellarExecuter/mergeExecuter.go index b8eee956..39e05669 100644 --- a/proofs/executer/stellarExecuter/mergeExecuter.go +++ b/proofs/executer/stellarExecuter/mergeExecuter.go @@ -6,8 +6,8 @@ import ( "fmt" "net/http" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" "github.com/stellar/go/build" "github.com/stellar/go/clients/horizon" diff --git a/proofs/executer/stellarExecuter/profileGeneration.go b/proofs/executer/stellarExecuter/profileGeneration.go index 623e04e1..a489fdee 100644 --- a/proofs/executer/stellarExecuter/profileGeneration.go +++ b/proofs/executer/stellarExecuter/profileGeneration.go @@ -4,8 +4,8 @@ import ( "fmt" "net/http" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" "github.com/stellar/go/build" "github.com/stellar/go/clients/horizon" diff --git a/proofs/executer/stellarExecuter/registrarAcc.go b/proofs/executer/stellarExecuter/registrarAcc.go index 1cef735b..13066b8a 100644 --- a/proofs/executer/stellarExecuter/registrarAcc.go +++ b/proofs/executer/stellarExecuter/registrarAcc.go @@ -3,7 +3,7 @@ package stellarExecuter import ( "fmt" "log" - "github.com/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/api/apiModel" "strconv" "github.com/stellar/go/build" diff --git a/proofs/executer/stellarExecuter/sendAsset.go b/proofs/executer/stellarExecuter/sendAsset.go index 1c2cb984..56806ef2 100644 --- a/proofs/executer/stellarExecuter/sendAsset.go +++ b/proofs/executer/stellarExecuter/sendAsset.go @@ -1,8 +1,8 @@ package stellarExecuter import ( - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" "net/http" "github.com/stellar/go/build" diff --git a/proofs/executer/stellarExecuter/splitExecuter.go b/proofs/executer/stellarExecuter/splitExecuter.go index 1f3f3646..efc9d026 100644 --- a/proofs/executer/stellarExecuter/splitExecuter.go +++ b/proofs/executer/stellarExecuter/splitExecuter.go @@ -6,8 +6,8 @@ import ( "fmt" "net/http" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" "github.com/stellar/go/build" "github.com/stellar/go/clients/horizon" diff --git a/proofs/executer/stellarExecuter/submitXDR.go b/proofs/executer/stellarExecuter/submitXDR.go index e10a5611..b652df26 100644 --- a/proofs/executer/stellarExecuter/submitXDR.go +++ b/proofs/executer/stellarExecuter/submitXDR.go @@ -6,8 +6,8 @@ import ( "github.com/stellar/go/clients/horizon" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" ) type ConcreteSubmitXDR struct { diff --git a/proofs/executer/stellarExecuter/transformation.go b/proofs/executer/stellarExecuter/transformation.go index 60694b1f..9789a077 100644 --- a/proofs/executer/stellarExecuter/transformation.go +++ b/proofs/executer/stellarExecuter/transformation.go @@ -3,7 +3,7 @@ package stellarExecuter import ( "fmt" "log" - "github.com/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/api/apiModel" "github.com/stellar/go/build" "github.com/stellar/go/clients/horizon" diff --git a/proofs/interpreter/fullPOCInterpreter.go b/proofs/interpreter/fullPOCInterpreter.go index b6a72c45..8e427c1c 100644 --- a/proofs/interpreter/fullPOCInterpreter.go +++ b/proofs/interpreter/fullPOCInterpreter.go @@ -2,8 +2,8 @@ package interpreter import ( "fmt" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/retriever/stellarRetriever" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/retriever/stellarRetriever" "net/http" ) diff --git a/proofs/interpreter/pocInterpreter.go b/proofs/interpreter/pocInterpreter.go index a4ea1fd3..04803cc0 100644 --- a/proofs/interpreter/pocInterpreter.go +++ b/proofs/interpreter/pocInterpreter.go @@ -2,9 +2,9 @@ package interpreter import ( // "fmt" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/retriever/stellarRetriever" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/retriever/stellarRetriever" "net/http" ) diff --git a/proofs/interpreter/poeInterpreter.go b/proofs/interpreter/poeInterpreter.go index 192ff047..8d9d73b3 100644 --- a/proofs/interpreter/poeInterpreter.go +++ b/proofs/interpreter/poeInterpreter.go @@ -2,9 +2,9 @@ package interpreter import ( "fmt" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/retriever/stellarRetriever" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/retriever/stellarRetriever" "net/http" ) diff --git a/proofs/interpreter/pogInterpreter.go b/proofs/interpreter/pogInterpreter.go index 8c1d465b..cdaf4c5a 100644 --- a/proofs/interpreter/pogInterpreter.go +++ b/proofs/interpreter/pogInterpreter.go @@ -2,9 +2,9 @@ package interpreter import ( "fmt" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" - "github.com/tracified-gateway/proofs/retriever/stellarRetriever" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/proofs/retriever/stellarRetriever" ) type POGInterface interface { diff --git a/proofs/retriever/stellarRetriever/fullPOCRetriever.go b/proofs/retriever/stellarRetriever/fullPOCRetriever.go index 54a9a4b5..95e7c1e4 100644 --- a/proofs/retriever/stellarRetriever/fullPOCRetriever.go +++ b/proofs/retriever/stellarRetriever/fullPOCRetriever.go @@ -4,8 +4,8 @@ import ( "encoding/json" "fmt" "io/ioutil" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" "net/http" ) diff --git a/proofs/retriever/stellarRetriever/pocRetriever.go b/proofs/retriever/stellarRetriever/pocRetriever.go index 930e348f..d28b0def 100644 --- a/proofs/retriever/stellarRetriever/pocRetriever.go +++ b/proofs/retriever/stellarRetriever/pocRetriever.go @@ -5,8 +5,8 @@ import ( "encoding/json" // "fmt" "io/ioutil" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" "net/http" ) diff --git a/proofs/retriever/stellarRetriever/poeRetriever.go b/proofs/retriever/stellarRetriever/poeRetriever.go index 875ea165..833fda57 100644 --- a/proofs/retriever/stellarRetriever/poeRetriever.go +++ b/proofs/retriever/stellarRetriever/poeRetriever.go @@ -7,8 +7,8 @@ import ( "io/ioutil" "net/http" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" ) type PublicKey struct { diff --git a/proofs/retriever/stellarRetriever/pogRetriever.go b/proofs/retriever/stellarRetriever/pogRetriever.go index b85c4e44..5aafde89 100644 --- a/proofs/retriever/stellarRetriever/pogRetriever.go +++ b/proofs/retriever/stellarRetriever/pogRetriever.go @@ -6,8 +6,8 @@ import ( "io/ioutil" "net/http" - "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" ) type ConcretePOG struct { diff --git a/proofs/retriever/stellarRetriever/previousTransactionValidator.go b/proofs/retriever/stellarRetriever/previousTransactionValidator.go index d66fde81..bfd71dbf 100644 --- a/proofs/retriever/stellarRetriever/previousTransactionValidator.go +++ b/proofs/retriever/stellarRetriever/previousTransactionValidator.go @@ -3,8 +3,8 @@ package stellarRetriever import ( "encoding/json" "io/ioutil" - // "github.com/tracified-gateway/api/apiModel" - "github.com/tracified-gateway/model" + // "github.com/dileepaj/tracified-gateway/api/apiModel" + "github.com/dileepaj/tracified-gateway/model" "net/http" ) diff --git a/services/cocCron.go b/services/cocCron.go new file mode 100644 index 00000000..40c7a63c --- /dev/null +++ b/services/cocCron.go @@ -0,0 +1,91 @@ +package services + +import ( + "time" + "fmt" + "github.com/stellar/go/xdr" + // "github.com/stellar/go/clients/horizon" + + "github.com/dileepaj/tracified-gateway/dao" + "github.com/dileepaj/tracified-gateway/model" +) + +func CheckCOCStatus() { + fmt.Println("NEW STUFF") + object := dao.Connection{} + p := object.GetCOCbyStatus("pending") + p.Then(func(data interface{}) interface{} { + result := data.([]model.COCCollectionBody) + // temp:=result + var temp model.COCCollectionBody + temp.Status="expired" + for i := 0; i < len(result); i++ { + // fmt.Println(temp[i]) + + if result[i].Status == "pending" { + var txe xdr.Transaction + err := xdr.SafeUnmarshalBase64(result[i].AcceptXdr, &txe) + if err != nil { + fmt.Println(err) + } + // fmt.Println(i) + // fmt.Println(txe.TimeBounds.MaxTime) + if int64(txe.TimeBounds.MaxTime) < time.Now().Unix() { + // result[i].Status="expired" + err1:=object.UpdateCOC(result[i],temp) + if err1!= nil{ + fmt.Println(err1) + } + // fmt.Println("Expired") + }else{ + // fmt.Println("Not Expired") + } + + } + } + return nil + }).Catch(func(error error) error { + return error + }) + p.Await() +} + +func CheckCOCExpired() { + fmt.Println("NEW STUFF") + object := dao.Connection{} + p := object.GetCOCbyStatus("pending") + p.Then(func(data interface{}) interface{} { + result := data.([]model.COCCollectionBody) + // temp:=result + var temp model.COCCollectionBody + temp.Status="expired" + for i := 0; i < len(result); i++ { + // fmt.Println(temp[i]) + + if result[i].Status == "pending" { + var txe xdr.Transaction + err := xdr.SafeUnmarshalBase64(result[i].AcceptXdr, &txe) + if err != nil { + fmt.Println(err) + } + // fmt.Println(i) + // fmt.Println(txe.TimeBounds.MaxTime) + if int64(txe.TimeBounds.MaxTime) < time.Now().Unix() { + // result[i].Status="expired" + err1:=object.UpdateCOC(result[i],temp) + if err1!= nil{ + fmt.Println(err1) + } + // fmt.Println("Expired") + }else{ + // fmt.Println("Not Expired") + } + + } + } + return nil + }).Catch(func(error error) error { + return error + }) + p.Await() +}