From 709e70ef112a56fc847aa1f2f3b8527d5b839244 Mon Sep 17 00:00:00 2001 From: Lucas Menendez Date: Wed, 25 Sep 2024 16:02:24 +0200 Subject: [PATCH] Revert "Squashed commit of the following:" This reverts commit a2078a24b1cfb559dc06ca9addf7dc67fa7b5bff. --- api/transaction.go | 126 ++++----------------------------------------- go.mod | 2 +- go.sum | 4 +- 3 files changed, 12 insertions(+), 120 deletions(-) diff --git a/api/transaction.go b/api/transaction.go index 242a832..e37a1f4 100644 --- a/api/transaction.go +++ b/api/transaction.go @@ -68,21 +68,21 @@ func (a *API) signTxHandler(w http.ResponseWriter, r *http.Request) { ErrInvalidTxFormat.Write(w) return } - // check if the api is not in transparent mode + // check the tx payload if !a.transparentMode { switch tx.Payload.(type) { case *models.Tx_SetAccount: + // check the account is the same as the user txSetAccount := tx.GetSetAccount() - // check the tx fields if txSetAccount == nil || txSetAccount.Account == nil || txSetAccount.InfoURI == nil { ErrInvalidTxFormat.With("missing fields").Write(w) return } - // check the account is the same as the user if !bytes.Equal(txSetAccount.GetAccount(), organizationSigner.Address().Bytes()) { ErrUnauthorized.With("invalid account").Write(w) return } + log.Infow("signing SetAccount transaction", "user", user.Email, "type", txSetAccount.Txtype.String()) // check the tx subtype switch txSetAccount.Txtype { case models.TxType_CREATE_ACCOUNT: @@ -101,127 +101,19 @@ func (a *API) signTxHandler(w http.ResponseWriter, r *http.Request) { } } } - case *models.Tx_NewProcess: - txNewProcess := tx.GetNewProcess() - // check the tx fields - if txNewProcess == nil || txNewProcess.Process == nil || txNewProcess.Nonce == 0 { - ErrInvalidTxFormat.With("missing fields").Write(w) - return - } - // check the tx subtype - switch txNewProcess.Txtype { - case models.TxType_NEW_PROCESS: - // generate a new faucet package if it's not present and include it in the tx - if txNewProcess.FaucetPackage == nil { - faucetPkg, err := a.account.FaucetPackage(organizationSigner.AddressString(), bootStrapFaucetAmount) - if err != nil { - ErrCouldNotCreateFaucetPackage.WithErr(err).Write(w) - return - } - txNewProcess.FaucetPackage = faucetPkg - tx = &models.Tx{ - Payload: &models.Tx_NewProcess{ - NewProcess: txNewProcess, - }, - } - } - } case *models.Tx_SetProcess: - txSetProcess := tx.GetSetProcess() - // check the tx fields - if txSetProcess == nil || txSetProcess.ProcessId == nil { - ErrInvalidTxFormat.With("missing fields").Write(w) - return - } - // check the tx subtype - switch txSetProcess.Txtype { - case models.TxType_SET_PROCESS_STATUS: - // check if the process status is in the tx - if txSetProcess.Status == nil { - ErrInvalidTxFormat.With("missing status field").Write(w) - return - } - case models.TxType_SET_PROCESS_CENSUS: - // check if the process census is in the tx - if (txSetProcess.CensusRoot == nil || txSetProcess.CensusURI == nil) && txSetProcess.CensusSize == nil { - ErrInvalidTxFormat.With("missing census fields").Write(w) - return - } - case models.TxType_SET_PROCESS_QUESTION_INDEX: - // check if the process question index is in the tx - if txSetProcess.QuestionIndex == nil { - ErrInvalidTxFormat.With("missing question index field").Write(w) - return - } - case models.TxType_SET_PROCESS_RESULTS: - // check if the process results are in the tx - if txSetProcess.Results == nil { - ErrInvalidTxFormat.With("missing results field").Write(w) - return - } - case models.TxType_SET_PROCESS_DURATION: - // check if the process duration is in the tx - if txSetProcess.Duration == nil { - ErrInvalidTxFormat.With("missing duration field").Write(w) - return - } - } - // include the faucet package in the tx if it's not present - if txSetProcess.FaucetPackage == nil { - faucetPkg, err := a.account.FaucetPackage(organizationSigner.AddressString(), bootStrapFaucetAmount) - if err != nil { - ErrCouldNotCreateFaucetPackage.WithErr(err).Write(w) - return - } - txSetProcess.FaucetPackage = faucetPkg - tx = &models.Tx{ - Payload: &models.Tx_SetProcess{ - SetProcess: txSetProcess, - }, - } - } - case *models.Tx_SetSIK, *models.Tx_DelSIK: - txSetSIK := tx.GetSetSIK() - // check the tx fields - if txSetSIK == nil || txSetSIK.SIK == nil { - ErrInvalidTxFormat.With("missing fields").Write(w) - return - } - // include the faucet package in the tx if it's not present - if txSetSIK.FaucetPackage == nil { - faucetPkg, err := a.account.FaucetPackage(organizationSigner.AddressString(), bootStrapFaucetAmount) - if err != nil { - ErrCouldNotCreateFaucetPackage.WithErr(err).Write(w) - return - } - txSetSIK.FaucetPackage = faucetPkg - tx = &models.Tx{ - Payload: &models.Tx_SetSIK{ - SetSIK: txSetSIK, - }, - } - } + log.Infow("signing SetProcess transaction", "user", user.Email) case *models.Tx_CollectFaucet: - txCollectFaucet := tx.GetCollectFaucet() - // include the faucet package in the tx if it's not present - if txCollectFaucet.FaucetPackage == nil { - faucetPkg, err := a.account.FaucetPackage(organizationSigner.AddressString(), bootStrapFaucetAmount) - if err != nil { - ErrCouldNotCreateFaucetPackage.WithErr(err).Write(w) - return - } - txCollectFaucet.FaucetPackage = faucetPkg - tx = &models.Tx{ - Payload: &models.Tx_CollectFaucet{ - CollectFaucet: txCollectFaucet, - }, - } - } + log.Infow("signing CollectFaucet transaction", "user", user.Email) + case *models.Tx_NewProcess: + log.Infow("signing NewProcess transaction", "user", user.Email) default: log.Warnw("transaction type not allowed", "user", user.Email, "type", fmt.Sprintf("%T", tx.Payload)) ErrTxTypeNotAllowed.Write(w) return } + } else { + log.Infow("signing transaction in full transparent mode", "user", user.Email, "type", fmt.Sprintf("%T", tx.Payload)) } // sign the tx stx, err := a.account.SignTransaction(tx, organizationSigner) diff --git a/go.mod b/go.mod index 74b45cc..26be066 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/twilio/twilio-go v1.23.0 go.mongodb.org/mongo-driver v1.14.0 go.vocdoni.io/dvote v1.10.2-0.20240726114655-b510ac8a7e42 - go.vocdoni.io/proto v1.15.10 + go.vocdoni.io/proto v1.15.8 google.golang.org/protobuf v1.34.0 ) diff --git a/go.sum b/go.sum index a9b2b71..0ac0384 100644 --- a/go.sum +++ b/go.sum @@ -1664,8 +1664,8 @@ go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= go.vocdoni.io/dvote v1.10.2-0.20240726114655-b510ac8a7e42 h1:w7Yp/IzkGNKuXKWRPyQoVasOjwNIadQOS9o3RQqJyF4= go.vocdoni.io/dvote v1.10.2-0.20240726114655-b510ac8a7e42/go.mod h1:NvAi97FrSOJBX45H9SntOjoj28bA2lX+Qh26F40hPY4= -go.vocdoni.io/proto v1.15.10 h1:AMMpfLp5+hCaOFMaylwbhJE2uieWno4d+iSNkXEDtDQ= -go.vocdoni.io/proto v1.15.10/go.mod h1:oi/WtiBFJ6QwNDv2aUQYwOnUKzYuS/fBqXF8xDNwcGo= +go.vocdoni.io/proto v1.15.8 h1:I5HVHffQwXyp0jootnCVj83+PoJ8L703RJ2CFSPTa2Q= +go.vocdoni.io/proto v1.15.8/go.mod h1:oi/WtiBFJ6QwNDv2aUQYwOnUKzYuS/fBqXF8xDNwcGo= go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE= go4.org v0.0.0-20200411211856-f5505b9728dd/go.mod h1:CIiUVy99QCPfoE13bO4EZaz5GZMZXMSBGhxRdsvzbkg= go4.org v0.0.0-20230225012048-214862532bf5 h1:nifaUDeh+rPaBCMPMQHZmvJf+QdpLFnuQPwx+LxVmtc=