This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement validation for Stellar deposits (#86)
- Loading branch information
Showing
8 changed files
with
226 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package controllers | ||
|
||
import ( | ||
"database/sql" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/stellar/go/support/render/problem" | ||
"github.com/stellar/starbridge/store" | ||
) | ||
|
||
var ( | ||
InvalidStellarTxHash = problem.P{ | ||
Type: "invalid_stellar_tx_hash", | ||
Title: "Invalid Stellar Transaction Hash", | ||
Status: http.StatusBadRequest, | ||
Detail: "The transaction hash of the Stellar transaction is invalid.", | ||
} | ||
StellarTxHashNotFound = problem.P{ | ||
Type: "stellar_tx_hash_not_found", | ||
Title: "Stellar Transaction Hash Not Found", | ||
Status: http.StatusNotFound, | ||
Detail: "The stellar transaction cannot be found.", | ||
} | ||
InvalidEthereumRecipient = problem.P{ | ||
Type: "invalid_ethereum_recipient", | ||
Title: "Invalid Ethereum Recipient", | ||
Status: http.StatusUnprocessableEntity, | ||
Detail: "The recipient of the deposit is not a valid Ethereum address.", | ||
} | ||
// TODO: remove this once getStellarDeposit is used | ||
_ = getStellarDeposit | ||
) | ||
|
||
func getStellarDeposit(depositStore *store.DB, r *http.Request) (store.StellarDeposit, error) { | ||
txHash := strings.TrimPrefix(r.PostFormValue("transaction_hash"), "0x") | ||
if !validTxHash.MatchString(txHash) { | ||
return store.StellarDeposit{}, InvalidStellarTxHash | ||
} | ||
|
||
deposit, err := depositStore.GetStellarDeposit(r.Context(), txHash) | ||
if err == sql.ErrNoRows { | ||
return store.StellarDeposit{}, StellarTxHashNotFound | ||
} | ||
return deposit, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.