-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
store incoming transactions in a database #1828
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ type Config struct { | |
DBType string | ||
DBConnectionURL string | ||
TenChainID int | ||
StoreIncomingTxs bool | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
This is a migration file for MariaDB that creates transactions table for storing incoming transactions | ||
*/ | ||
|
||
CREATE TABLE IF NOT EXISTS ogdb.transactions ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
user_id varbinary(20), | ||
tx TEXT, | ||
tx_time DATETIME DEFAULT CURRENT_TIMESTAMP | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,6 +142,20 @@ func (w *WalletExtension) ProxyEthRequest(request *common.RPCRequest, conn userc | |
} | ||
} | ||
|
||
// check if user is sending a new transaction and if we should store it in the database for debugging purposes | ||
if request.Method == rpc.SendRawTransaction && w.config.StoreIncomingTxs { | ||
userIDBytes, err := common.GetUserIDbyte(hexUserID) | ||
if err != nil { | ||
w.Logger().Error(fmt.Errorf("error decoding string (%s), %w", hexUserID[2:], err).Error()) | ||
return nil, errors.New("error decoding userID. It should be in hex format") | ||
} | ||
err = w.storage.StoreTransaction(request.Params[0].(string), userIDBytes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we 100% certain that the first param exists, can be cast to a string and will have "0x" as the first two characters so you can strip them off? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Things are checked in a function that calls that function, but added additional check there to avoid an edge case that might happen. |
||
if err != nil { | ||
w.Logger().Error(fmt.Errorf("error storing transaction in the database: %w", err).Error()) | ||
return nil, err | ||
} | ||
} | ||
|
||
// get account manager for current user (if there is no users in the query parameters - use defaultUser for WE endpoints) | ||
selectedAccountManager, err := w.userAccountManager.GetUserAccountManager(hexUserID) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonder if it be possible to store the tx hash as well or is that going to be too expensive to figure out on the fly? Just thinking about being able to do lookups if investigating an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added tx_hash