-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
430 additions
and
19 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
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,20 @@ | ||
package multisig | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-pg/pg/v10" | ||
) | ||
|
||
type MultisigTaskResult struct { | ||
TransactionModel MultisigTransactionList | ||
} | ||
|
||
func (m *MultisigTaskResult) Persist(ctx context.Context, db *pg.DB) error { | ||
return db.RunInTransaction(ctx, func(tx *pg.Tx) error { | ||
if len(m.TransactionModel) > 0 { | ||
return m.TransactionModel.PersistWithTx(ctx, tx) | ||
} | ||
return nil | ||
}) | ||
} |
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,54 @@ | ||
package multisig | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/go-pg/pg/v10" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
type MultisigTransaction struct { | ||
MultisigID string `pg:",pk,notnull"` | ||
StateRoot string `pg:",pk,notnull"` | ||
Height int64 `pg:",pk,notnull,use_zero"` | ||
TransactionID int64 `pg:",pk,notnull,use_zero"` | ||
|
||
// Transaction State | ||
To string `pg:",notnull"` | ||
Value string `pg:",notnull"` | ||
Method uint64 `pg:",notnull,use_zero"` | ||
Params []byte | ||
Approved []string `pg:",notnull"` | ||
} | ||
|
||
func (m *MultisigTransaction) PersistWithTx(ctx context.Context, tx *pg.Tx) error { | ||
if _, err := tx.ModelContext(ctx, m). | ||
OnConflict("do nothing"). | ||
Insert(); err != nil { | ||
return xerrors.Errorf("persisting multisig transaction: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func (m *MultisigTransaction) Persist(ctx context.Context, db *pg.DB) error { | ||
return db.RunInTransaction(ctx, func(tx *pg.Tx) error { | ||
return m.PersistWithTx(ctx, tx) | ||
}) | ||
} | ||
|
||
type MultisigTransactionList []*MultisigTransaction | ||
|
||
func (ml MultisigTransactionList) PersistWithTx(ctx context.Context, tx *pg.Tx) error { | ||
if _, err := tx.ModelContext(ctx, ml). | ||
OnConflict("do nothing"). | ||
Insert(); err != nil { | ||
return xerrors.Errorf("persisting multisig transaction list: %w", err) | ||
} | ||
return nil | ||
} | ||
|
||
func (ml MultisigTransactionList) Persist(ctx context.Context, db *pg.DB) error { | ||
return db.RunInTransaction(ctx, func(tx *pg.Tx) error { | ||
return ml.PersistWithTx(ctx, tx) | ||
}) | ||
} |
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,31 @@ | ||
package migrations | ||
|
||
import ( | ||
"github.com/go-pg/migrations/v8" | ||
) | ||
|
||
// Schema version 17 adds multisig transactions | ||
|
||
func init() { | ||
up := batch(` | ||
CREATE TABLE IF NOT EXISTS "multisig_transactions" ( | ||
"height" bigint not null, | ||
"multisig_id" text not null, | ||
"state_root" text not null, | ||
"transaction_id" text not null, | ||
"to" text not null, | ||
"value" text not null, | ||
"method" bigint not null, | ||
"params" bytea not null, | ||
"approved" json not null, | ||
PRIMARY KEY ("height", "state_root", "multisig_id", "transaction_id") | ||
); | ||
`) | ||
|
||
down := batch(` | ||
DROP TABLE IF EXISTS public.multisig_transactions; | ||
`) | ||
|
||
migrations.MustRegisterTx(up, down) | ||
} |
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.