mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 04:04:21 +01:00
Ark Notes (#379)
* ark credits * rename "ecash" --> "ark credit" * rework note_test.go * NewFromString * create several notes * note repo: rename "push" to "add" * RegisterInputsForNextRoundRequest: move "notes" to field #3 * use uint64 as note ID * rename to voucher * add nostr notification * nostr notification test and fixes * bump badger to 4.3 * allow npub to be registered * rename poolTxID * add default relays * Update server/internal/config/config.go Co-authored-by: Marco Argentieri <3596602+tiero@users.noreply.github.com> * fix RedeemVouchers test * notification = voucher * WASM wrappers * fix arkd voucher cmd * test_utils.go ignore gosec rule G101 * fix permissions * rename ALL to notes * add URI prefix * note.go : fix signature encoding * fix decode note.Data * Update server/internal/infrastructure/notifier/nostr/nostr.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> * Update pkg/client-sdk/wasm/browser/wrappers.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> * Update server/internal/infrastructure/notifier/nostr/nostr.go Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> * rework note and entity db + sqlite implementations * NOTIFICATION_PREFIX -> NOTE_URI_PREFIX * validate NOTE_URI_PREFIX * Update defaults to convenant-less mainnet (#2) * config: defaults to convenant-less tx builder * Drop env var for blockchain scanner --------- Co-authored-by: altafan <18440657+altafan@users.noreply.github.com> * add // before URI prefix * add URI prefix in admin CreateNote * Fixes * rework nonces encoding (#4) * rework nonces encoding * add a check in Musig2Nonce decode function * musig2_test: increase number of signers to 20 * musig2.json: add a test case with a 35 leaves tree * GetEventStream REST rework * fix round phases time intervals * [SDK] Use server-side streams in rest client * Fix history * make the URI optional * Updates * Fix settled txs in history * fix e2e test * go work sync in sdk unit test * fix signMessage in btc and liquid sdk wallets --------- Co-authored-by: Marco Argentieri <3596602+tiero@users.noreply.github.com> Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com>
This commit is contained in:
@@ -10,6 +10,44 @@ import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
const containsNote = `-- name: ContainsNote :one
|
||||
SELECT EXISTS(SELECT 1 FROM note WHERE id = ?)
|
||||
`
|
||||
|
||||
func (q *Queries) ContainsNote(ctx context.Context, id int64) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, containsNote, id)
|
||||
var column_1 int64
|
||||
err := row.Scan(&column_1)
|
||||
return column_1, err
|
||||
}
|
||||
|
||||
const deleteEntity = `-- name: DeleteEntity :exec
|
||||
DELETE FROM entity WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteEntity(ctx context.Context, id int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteEntity, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteEntityVtxo = `-- name: DeleteEntityVtxo :exec
|
||||
DELETE FROM entity_vtxo WHERE entity_id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteEntityVtxo(ctx context.Context, entityID int64) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteEntityVtxo, entityID)
|
||||
return err
|
||||
}
|
||||
|
||||
const insertNote = `-- name: InsertNote :exec
|
||||
INSERT INTO note (id) VALUES (?)
|
||||
`
|
||||
|
||||
func (q *Queries) InsertNote(ctx context.Context, id int64) error {
|
||||
_, err := q.db.ExecContext(ctx, insertNote, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const markVtxoAsRedeemed = `-- name: MarkVtxoAsRedeemed :exec
|
||||
UPDATE vtxo SET redeemed = true WHERE txid = ? AND vout = ?
|
||||
`
|
||||
@@ -53,6 +91,48 @@ func (q *Queries) MarkVtxoAsSwept(ctx context.Context, arg MarkVtxoAsSweptParams
|
||||
return err
|
||||
}
|
||||
|
||||
const selectEntitiesByVtxo = `-- name: SelectEntitiesByVtxo :many
|
||||
SELECT entity_vw.id, entity_vw.nostr_recipient, entity_vw.vtxo_txid, entity_vw.vtxo_vout FROM entity_vw
|
||||
WHERE vtxo_txid = ? AND vtxo_vout = ?
|
||||
`
|
||||
|
||||
type SelectEntitiesByVtxoParams struct {
|
||||
VtxoTxid sql.NullString
|
||||
VtxoVout sql.NullInt64
|
||||
}
|
||||
|
||||
type SelectEntitiesByVtxoRow struct {
|
||||
EntityVw EntityVw
|
||||
}
|
||||
|
||||
func (q *Queries) SelectEntitiesByVtxo(ctx context.Context, arg SelectEntitiesByVtxoParams) ([]SelectEntitiesByVtxoRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, selectEntitiesByVtxo, arg.VtxoTxid, arg.VtxoVout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []SelectEntitiesByVtxoRow
|
||||
for rows.Next() {
|
||||
var i SelectEntitiesByVtxoRow
|
||||
if err := rows.Scan(
|
||||
&i.EntityVw.ID,
|
||||
&i.EntityVw.NostrRecipient,
|
||||
&i.EntityVw.VtxoTxid,
|
||||
&i.EntityVw.VtxoVout,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const selectNotRedeemedVtxos = `-- name: SelectNotRedeemedVtxos :many
|
||||
SELECT vtxo.txid, vtxo.vout, vtxo.pubkey, vtxo.amount, vtxo.pool_tx, vtxo.spent_by, vtxo.spent, vtxo.redeemed, vtxo.swept, vtxo.expire_at, vtxo.created_at, vtxo.payment_id, vtxo.redeem_tx FROM vtxo
|
||||
WHERE redeemed = false
|
||||
@@ -705,6 +785,39 @@ func (q *Queries) UpdateVtxoPaymentId(ctx context.Context, arg UpdateVtxoPayment
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertEntity = `-- name: UpsertEntity :one
|
||||
INSERT INTO entity (nostr_recipient)
|
||||
VALUES (?)
|
||||
ON CONFLICT(nostr_recipient) DO UPDATE SET
|
||||
nostr_recipient = EXCLUDED.nostr_recipient
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
func (q *Queries) UpsertEntity(ctx context.Context, nostrRecipient string) (int64, error) {
|
||||
row := q.db.QueryRowContext(ctx, upsertEntity, nostrRecipient)
|
||||
var id int64
|
||||
err := row.Scan(&id)
|
||||
return id, err
|
||||
}
|
||||
|
||||
const upsertEntityVtxo = `-- name: UpsertEntityVtxo :exec
|
||||
INSERT INTO entity_vtxo (entity_id, vtxo_txid, vtxo_vout)
|
||||
VALUES (?, ?, ?)
|
||||
ON CONFLICT(entity_id, vtxo_txid, vtxo_vout) DO UPDATE SET
|
||||
entity_id = EXCLUDED.entity_id
|
||||
`
|
||||
|
||||
type UpsertEntityVtxoParams struct {
|
||||
EntityID int64
|
||||
VtxoTxid string
|
||||
VtxoVout int64
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertEntityVtxo(ctx context.Context, arg UpsertEntityVtxoParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertEntityVtxo, arg.EntityID, arg.VtxoTxid, arg.VtxoVout)
|
||||
return err
|
||||
}
|
||||
|
||||
const upsertPayment = `-- name: UpsertPayment :exec
|
||||
INSERT INTO payment (id, round_id) VALUES (?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET round_id = EXCLUDED.round_id
|
||||
|
||||
Reference in New Issue
Block a user