54 lines
2.0 KiB
Go
54 lines
2.0 KiB
Go
// Code generated by zi2go from node_nonce.zi. DO NOT EDIT.
|
|
package main
|
|
|
|
import sql "database/sql"
|
|
|
|
// #import go_types
|
|
type zir_b5da7444bda7630d_TransactionResult struct {
|
|
Value *Transaction
|
|
Error Error
|
|
}
|
|
|
|
type zir_39ef582091ea3a89_ExecResult struct {
|
|
Value Result
|
|
Error Error
|
|
}
|
|
|
|
func NodeNonce_Begin(Database *Database, Context Context, Options *TransactionOptions) zir_b5da7444bda7630d_TransactionResult {
|
|
var result zir_b5da7444bda7630d_TransactionResult
|
|
result.Value, result.Error = (*sql.DB).BeginTx(Database, Context, Options)
|
|
return result
|
|
}
|
|
|
|
func NodeNonce_DeleteExpired(Transaction *Transaction, Context Context, Query string, Now int64) zir_39ef582091ea3a89_ExecResult {
|
|
var result zir_39ef582091ea3a89_ExecResult
|
|
result.Value, result.Error = (*sql.Tx).ExecContext(Transaction, Context, Query, Now)
|
|
return result
|
|
}
|
|
|
|
func NodeNonce_Insert(Transaction *Transaction, Context Context, Query string, NodeID string, Nonce string, ExpiresAt int64) zir_39ef582091ea3a89_ExecResult {
|
|
var result zir_39ef582091ea3a89_ExecResult
|
|
result.Value, result.Error = (*sql.Tx).ExecContext(Transaction, Context, Query, NodeID, Nonce, ExpiresAt)
|
|
return result
|
|
}
|
|
|
|
func NodeNonce_Consume(database *Database, context Context, nodeID string, nonce string, expiresAt int64) Error {
|
|
begun := NodeNonce_Begin(database, context, nil)
|
|
if begun.Error != nil {
|
|
return begun.Error
|
|
}
|
|
transaction := begun.Value
|
|
defer (*sql.Tx).Rollback(transaction)
|
|
var value_0 zir_39ef582091ea3a89_ExecResult = NodeNonce_DeleteExpired(transaction, context, "DELETE FROM node_request_nonces WHERE expires_at<?1", int64(TimeGo_Unix(TimeGo_Now())))
|
|
deleted := value_0
|
|
if deleted.Error != nil {
|
|
return deleted.Error
|
|
}
|
|
var value_1 zir_39ef582091ea3a89_ExecResult = NodeNonce_Insert(transaction, context, "INSERT INTO node_request_nonces(node_id,nonce,expires_at) VALUES(?1,?2,?3)", nodeID, nonce, int64(expiresAt))
|
|
inserted := value_1
|
|
if inserted.Error != nil {
|
|
return ErrorsGo_New("node request replayed")
|
|
}
|
|
return SqlGo_Commit(transaction)
|
|
}
|