This repository was archived by the owner on Feb 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
⚡️ Add rebroadcast functionality #167
Open
garry-sharp
wants to merge
1
commit into
fees-v3-post
Choose a base branch
from
fees-v3-rebroadcast
base: fees-v3-post
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,9 +3,11 @@ package postgres | |||||||||||||||||||||
| import ( | ||||||||||||||||||||||
| "context" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| "github.com/ethereum/go-ethereum/common/hexutil" | ||||||||||||||||||||||
| "github.com/google/uuid" | ||||||||||||||||||||||
| "github.com/jackc/pgx/v5" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| etypes "github.com/ethereum/go-ethereum/core/types" | ||||||||||||||||||||||
| "github.com/vultisig/plugin/internal/types" | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -84,3 +86,35 @@ func (p *PostgresBackend) SetFeeBatchSent(ctx context.Context, tx pgx.Tx, txHash | |||||||||||||||||||||
| _, err := tx.Exec(ctx, query, types.FeeBatchStateSent, txHash, batchId) | ||||||||||||||||||||||
| return err | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| func (p *PostgresBackend) InsertTx(ctx context.Context, tx pgx.Tx, rawTx string) error { | ||||||||||||||||||||||
| txBytes, err := hexutil.Decode(rawTx) | ||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||
| return err | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| var transaction etypes.Transaction | ||||||||||||||||||||||
| if err := transaction.UnmarshalBinary(txBytes); err != nil { | ||||||||||||||||||||||
| return err | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| _, err = tx.Exec(ctx, `insert into fee_tx (hash, raw_tx) values ($1, $2)`, transaction.Hash().Hex(), rawTx) | ||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||
| return err | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return nil | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| func (p *PostgresBackend) GetTx(ctx context.Context, txHash string) (string, error) { | ||||||||||||||||||||||
| query := `select raw_tx from fee_tx where hash = $1` | ||||||||||||||||||||||
| rows, err := p.pool.Query(ctx, query, txHash) | ||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||
| return "", err | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| var rawTx string | ||||||||||||||||||||||
| defer rows.Close() | ||||||||||||||||||||||
| if err := rows.Scan(&rawTx); err != nil { | ||||||||||||||||||||||
|
Comment on lines
+110
to
+116
|
||||||||||||||||||||||
| rows, err := p.pool.Query(ctx, query, txHash) | |
| if err != nil { | |
| return "", err | |
| } | |
| var rawTx string | |
| defer rows.Close() | |
| if err := rows.Scan(&rawTx); err != nil { | |
| row := p.pool.QueryRow(ctx, query, txHash) | |
| var rawTx string | |
| if err := row.Scan(&rawTx); err != nil { |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,147 +1 @@ | ||
|
|
||
| CREATE TYPE "fee_batch_status" AS ENUM ( | ||
| 'draft', | ||
| 'sent', | ||
| 'completed', | ||
| 'failed' | ||
| ); | ||
|
|
||
| CREATE TYPE "plugin_id" AS ENUM ( | ||
| 'vultisig-dca-0000', | ||
| 'vultisig-payroll-0000', | ||
| 'vultisig-fees-feee', | ||
| 'vultisig-copytrader-0000' | ||
| ); | ||
|
|
||
| CREATE TYPE "tx_indexer_status" AS ENUM ( | ||
| 'PROPOSED', | ||
| 'VERIFIED', | ||
| 'SIGNED' | ||
| ); | ||
|
|
||
| CREATE TYPE "tx_indexer_status_onchain" AS ENUM ( | ||
| 'PENDING', | ||
| 'SUCCESS', | ||
| 'FAIL' | ||
| ); | ||
|
|
||
| CREATE FUNCTION "prevent_insert_if_policy_deleted"() RETURNS "trigger" | ||
| LANGUAGE "plpgsql" | ||
| AS $$ | ||
| BEGIN | ||
| IF NEW.deleted = true THEN | ||
| RAISE EXCEPTION 'Cannot insert a deleted policy'; | ||
| END IF; | ||
| RETURN NEW; | ||
| END; | ||
| $$; | ||
|
|
||
| CREATE FUNCTION "prevent_update_if_policy_deleted"() RETURNS "trigger" | ||
| LANGUAGE "plpgsql" | ||
| AS $$ | ||
| BEGIN | ||
| IF OLD.deleted = true THEN | ||
| RAISE EXCEPTION 'Cannot update a deleted policy'; | ||
| END IF; | ||
| RETURN NEW; | ||
| END; | ||
| $$; | ||
|
|
||
| CREATE FUNCTION "set_policy_inactive_on_delete"() RETURNS "trigger" | ||
| LANGUAGE "plpgsql" | ||
| AS $$ | ||
| BEGIN | ||
| IF NEW.deleted = true THEN | ||
| NEW.active := false; | ||
| END IF; | ||
| RETURN NEW; | ||
| END; | ||
| $$; | ||
|
|
||
| CREATE FUNCTION "update_updated_at_column"() RETURNS "trigger" | ||
| LANGUAGE "plpgsql" | ||
| AS $$ | ||
| BEGIN | ||
| NEW.updated_at = NOW(); | ||
| RETURN NEW; | ||
| END; | ||
| $$; | ||
|
|
||
| CREATE TABLE "fee_batch" ( | ||
| "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL, | ||
| "batch_id" "uuid" NOT NULL, | ||
| "public_key" character varying(66) NOT NULL, | ||
| "status" "fee_batch_status" DEFAULT 'draft'::"public"."fee_batch_status" NOT NULL, | ||
| "amount" bigint NOT NULL, | ||
| "created_at" timestamp with time zone DEFAULT "now"(), | ||
| "updated_at" timestamp with time zone DEFAULT "now"(), | ||
| "tx_hash" character varying(66) | ||
| ); | ||
|
|
||
| CREATE TABLE "plugin_policies" ( | ||
| "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL, | ||
| "public_key" "text" NOT NULL, | ||
| "plugin_id" "plugin_id" NOT NULL, | ||
| "plugin_version" "text" NOT NULL, | ||
| "policy_version" integer NOT NULL, | ||
| "signature" "text" NOT NULL, | ||
| "recipe" "text" NOT NULL, | ||
| "active" boolean DEFAULT true NOT NULL, | ||
| "created_at" timestamp with time zone DEFAULT "now"() NOT NULL, | ||
| "updated_at" timestamp with time zone DEFAULT "now"() NOT NULL, | ||
| "deleted" boolean DEFAULT false NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE "scheduler" ( | ||
| "policy_id" "uuid" NOT NULL, | ||
| "next_execution" timestamp without time zone NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE "tx_indexer" ( | ||
| "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL, | ||
| "plugin_id" character varying(255) NOT NULL, | ||
| "tx_hash" character varying(255), | ||
| "chain_id" integer NOT NULL, | ||
| "policy_id" "uuid" NOT NULL, | ||
| "token_id" character varying(255) NOT NULL, | ||
| "from_public_key" character varying(255) NOT NULL, | ||
| "to_public_key" character varying(255) NOT NULL, | ||
| "proposed_tx_hex" "text" NOT NULL, | ||
| "status" "tx_indexer_status" DEFAULT 'PROPOSED'::"public"."tx_indexer_status" NOT NULL, | ||
| "status_onchain" "tx_indexer_status_onchain", | ||
| "lost" boolean DEFAULT false NOT NULL, | ||
| "broadcasted_at" timestamp without time zone, | ||
| "created_at" timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
| "updated_at" timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL | ||
| ); | ||
|
|
||
| ALTER TABLE ONLY "fee_batch" | ||
| ADD CONSTRAINT "fee_batch_pkey" PRIMARY KEY ("id"); | ||
|
|
||
| ALTER TABLE ONLY "plugin_policies" | ||
| ADD CONSTRAINT "plugin_policies_pkey" PRIMARY KEY ("id"); | ||
|
|
||
| ALTER TABLE ONLY "scheduler" | ||
| ADD CONSTRAINT "scheduler_pkey" PRIMARY KEY ("policy_id"); | ||
|
|
||
| ALTER TABLE ONLY "tx_indexer" | ||
| ADD CONSTRAINT "tx_indexer_pkey" PRIMARY KEY ("id"); | ||
|
|
||
| CREATE INDEX "idx_plugin_policies_active" ON "plugin_policies" USING "btree" ("active"); | ||
|
|
||
| CREATE INDEX "idx_plugin_policies_plugin_id" ON "plugin_policies" USING "btree" ("plugin_id"); | ||
|
|
||
| CREATE INDEX "idx_plugin_policies_public_key" ON "plugin_policies" USING "btree" ("public_key"); | ||
|
|
||
| CREATE INDEX "idx_scheduler_next_execution" ON "scheduler" USING "btree" ("next_execution"); | ||
|
|
||
| CREATE INDEX "idx_tx_indexer_key" ON "tx_indexer" USING "btree" ("chain_id", "plugin_id", "policy_id", "token_id", "to_public_key", "created_at"); | ||
|
|
||
| CREATE INDEX "idx_tx_indexer_status_onchain_lost" ON "tx_indexer" USING "btree" ("status_onchain", "lost"); | ||
|
|
||
| CREATE TRIGGER "trg_prevent_insert_if_policy_deleted" BEFORE INSERT ON "plugin_policies" FOR EACH ROW EXECUTE FUNCTION "public"."prevent_insert_if_policy_deleted"(); | ||
|
|
||
| CREATE TRIGGER "trg_prevent_update_if_policy_deleted" BEFORE UPDATE ON "plugin_policies" FOR EACH ROW WHEN (("old"."deleted" = true)) EXECUTE FUNCTION "public"."prevent_update_if_policy_deleted"(); | ||
|
|
||
| CREATE TRIGGER "trg_set_policy_inactive_on_delete" BEFORE INSERT OR UPDATE ON "plugin_policies" FOR EACH ROW WHEN (("new"."deleted" = true)) EXECUTE FUNCTION "public"."set_policy_inactive_on_delete"(); | ||
|
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Missing rows.Next() call before scanning. This will always fail with 'no rows in result set' error. Add 'if !rows.Next() { return "", pgx.ErrNoRows }' before the Scan call.