diff --git a/address/event.go b/address/event.go index 4f94123fa..bbe03d500 100644 --- a/address/event.go +++ b/address/event.go @@ -58,7 +58,7 @@ type EventQueryParams struct { // multiple events. type Event struct { // ID is the database primary key ID of the address event. - ID int32 + ID int64 // CreationTime is the time the event was first created. CreationTime time.Time diff --git a/rpcserver.go b/rpcserver.go index 0edbe6f3e..a337bb4c0 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3177,10 +3177,10 @@ func (r *rpcServer) ListFederationServers(ctx context.Context, }, nil } -func unmarshalUniverseServer(server *unirpc.UniverseFederationServer, -) universe.ServerAddr { +func unmarshalUniverseServer( + server *unirpc.UniverseFederationServer) universe.ServerAddr { - return universe.NewServerAddr(uint32(server.Id), server.Host) + return universe.NewServerAddr(int64(server.Id), server.Host) } // AddFederationServer adds a new server to the federation of the local diff --git a/tapdb/addrs.go b/tapdb/addrs.go index da4cfdce8..12780efe9 100644 --- a/tapdb/addrs.go +++ b/tapdb/addrs.go @@ -90,14 +90,14 @@ type AddrBook interface { arg []byte) (AddrByTaprootOutput, error) // InsertAddr inserts a new address into the database. - InsertAddr(ctx context.Context, arg NewAddr) (int32, error) + InsertAddr(ctx context.Context, arg NewAddr) (int64, error) // UpsertInternalKey inserts a new or updates an existing internal key // into the database and returns the primary key. - UpsertInternalKey(ctx context.Context, arg InternalKey) (int32, error) + UpsertInternalKey(ctx context.Context, arg InternalKey) (int64, error) // UpsertScriptKey inserts a new script key on disk into the DB. - UpsertScriptKey(context.Context, NewScriptKey) (int32, error) + UpsertScriptKey(context.Context, NewScriptKey) (int64, error) // SetAddrManaged sets an address as being managed by the internal // wallet. @@ -105,20 +105,20 @@ type AddrBook interface { // UpsertManagedUTXO inserts a new or updates an existing managed UTXO // to disk and returns the primary key. - UpsertManagedUTXO(ctx context.Context, arg RawManagedUTXO) (int32, + UpsertManagedUTXO(ctx context.Context, arg RawManagedUTXO) (int64, error) // UpsertChainTx inserts a new or updates an existing chain tx into the // DB. - UpsertChainTx(ctx context.Context, arg ChainTxParams) (int32, error) + UpsertChainTx(ctx context.Context, arg ChainTxParams) (int64, error) // UpsertAddrEvent inserts a new or updates an existing address event // and returns the primary key. - UpsertAddrEvent(ctx context.Context, arg UpsertAddrEvent) (int32, error) + UpsertAddrEvent(ctx context.Context, arg UpsertAddrEvent) (int64, error) // FetchAddrEvent returns a single address event based on its primary // key. - FetchAddrEvent(ctx context.Context, id int32) (AddrEvent, error) + FetchAddrEvent(ctx context.Context, id int64) (AddrEvent, error) // QueryEventIDs returns a list of event IDs and their corresponding // address IDs that match the given query parameters. @@ -193,7 +193,7 @@ func NewTapAddressBook(db BatchedAddrBook, params *address.ChainParams, // insertInternalKey inserts a new internal key into the DB and returns the // primary key of the internal key. func insertInternalKey(ctx context.Context, a AddrBook, - desc keychain.KeyDescriptor) (int32, error) { + desc keychain.KeyDescriptor) (int64, error) { return a.UpsertInternalKey(ctx, InternalKey{ RawKey: desc.PubKey.SerializeCompressed(), @@ -844,7 +844,7 @@ func (t *TapAddressBook) QueryAddrEvents( // fetchEvent fetches a single address event identified by its primary ID and // address. -func fetchEvent(ctx context.Context, db AddrBook, eventID int32, +func fetchEvent(ctx context.Context, db AddrBook, eventID int64, addr *address.AddrWithKeyInfo) (*address.Event, error) { dbEvent, err := db.FetchAddrEvent(ctx, eventID) @@ -901,8 +901,8 @@ func (t *TapAddressBook) CompleteEvent(ctx context.Context, Status: int16(status), Txid: anchorPoint.Hash[:], ChainTxnOutputIndex: int32(anchorPoint.Index), - AssetProofID: sqlInt32(proofData.ProofID), - AssetID: sqlInt32(proofData.AssetID), + AssetProofID: sqlInt64(proofData.ProofID), + AssetID: sqlInt64(proofData.AssetID), }) return err }) diff --git a/tapdb/asset_minting.go b/tapdb/asset_minting.go index 6c28c7a40..e63522170 100644 --- a/tapdb/asset_minting.go +++ b/tapdb/asset_minting.go @@ -166,12 +166,12 @@ type PendingAssetStore interface { // FetchSeedlingID is used to look up the ID of a specific seedling // in a batch. - FetchSeedlingID(ctx context.Context, arg AssetSeedlingTuple) (int32, + FetchSeedlingID(ctx context.Context, arg AssetSeedlingTuple) (int64, error) // FetchSeedlingByID is used to look up a specific seedling. FetchSeedlingByID(ctx context.Context, - seedlingID int32) (AssetSeedling, error) + seedlingID int64) (AssetSeedling, error) // BindMintingBatchWithTx adds the minting transaction to an existing // batch. @@ -183,7 +183,7 @@ type PendingAssetStore interface { // UpsertManagedUTXO inserts a new or updates an existing managed UTXO // to disk and returns the primary key. - UpsertManagedUTXO(ctx context.Context, arg RawManagedUTXO) (int32, + UpsertManagedUTXO(ctx context.Context, arg RawManagedUTXO) (int64, error) // AnchorPendingAssets associated an asset on disk with the transaction @@ -192,7 +192,7 @@ type PendingAssetStore interface { // UpsertChainTx inserts a new or updates an existing chain tx into the // DB. - UpsertChainTx(ctx context.Context, arg ChainTxParams) (int32, error) + UpsertChainTx(ctx context.Context, arg ChainTxParams) (int64, error) // ConfirmChainTx confirms an existing chain tx. ConfirmChainTx(ctx context.Context, arg ChainTxConf) error @@ -334,7 +334,7 @@ func (a *AssetMintingStore) CommitMintingBatch(ctx context.Context, return err } - dbSeedling.GroupGenesisID = sqlInt32(genesisID) + dbSeedling.GroupGenesisID = sqlInt64(genesisID) } // If this seedling is being issued to a group being @@ -349,7 +349,7 @@ func (a *AssetMintingStore) CommitMintingBatch(ctx context.Context, return err } - dbSeedling.GroupAnchorID = sqlInt32(anchorID) + dbSeedling.GroupAnchorID = sqlInt64(anchorID) } err = q.InsertAssetSeedling(ctx, dbSeedling) @@ -407,7 +407,7 @@ func (a *AssetMintingStore) AddSeedlingsToBatch(ctx context.Context, return err } - dbSeedling.GroupGenesisID = sqlInt32(genesisID) + dbSeedling.GroupGenesisID = sqlInt64(genesisID) } // If this seedling is being issued to a group being @@ -422,7 +422,7 @@ func (a *AssetMintingStore) AddSeedlingsToBatch(ctx context.Context, return err } - dbSeedling.GroupAnchorID = sqlInt32(anchorID) + dbSeedling.GroupAnchorID = sqlInt64(anchorID) } err = q.InsertAssetSeedlingIntoBatch(ctx, dbSeedling) @@ -439,7 +439,7 @@ func (a *AssetMintingStore) AddSeedlingsToBatch(ctx context.Context, // fetchSeedlingID attempts to fetch the ID for a seedling from a specific // batch. This is performed within the context of a greater DB transaction. func fetchSeedlingID(ctx context.Context, q PendingAssetStore, - batchKey []byte, seedlingName string) (int32, error) { + batchKey []byte, seedlingName string) (int64, error) { seedlingParams := AssetSeedlingTuple{ SeedlingName: seedlingName, @@ -479,7 +479,7 @@ func fetchAssetSeedlings(ctx context.Context, q PendingAssetStore, // Fetch the group info for seedlings with a specific group. // There can only be one group per genesis. if dbSeedling.GroupGenesisID.Valid { - genID := extractSqlInt32[int32]( + genID := extractSqlInt64[int64]( dbSeedling.GroupGenesisID, ) seedlingGroup, err := fetchGroupByGenesis(ctx, q, genID) @@ -496,7 +496,7 @@ func fetchAssetSeedlings(ctx context.Context, q PendingAssetStore, // Fetch the group anchor for seedlings with a group anchor set. if dbSeedling.GroupAnchorID.Valid { - anchorID := extractSqlInt32[int32]( + anchorID := extractSqlInt64[int64]( dbSeedling.GroupAnchorID, ) seedlingAnchor, err := q.FetchSeedlingByID(ctx, anchorID) @@ -982,7 +982,7 @@ func (a *AssetMintingStore) AddSproutsToBatch(ctx context.Context, ChangeOutputIndex: sqlInt32( genesisPacket.ChangeOutputIndex, ), - GenesisID: sqlInt32(genesisPointID), + GenesisID: sqlInt64(genesisPointID), }) if err != nil { return fmt.Errorf("unable to add batch tx: %w", err) @@ -1093,7 +1093,7 @@ func (a *AssetMintingStore) CommitSignedGenesisTx(ctx context.Context, // managed UTXO. err = q.AnchorPendingAssets(ctx, AssetAnchor{ PrevOut: genesisOutpoint, - AnchorUtxoID: sqlInt32(utxoID), + AnchorUtxoID: sqlInt64(utxoID), }) if err != nil { return fmt.Errorf("unable to anchor pending assets: %v", err) @@ -1103,7 +1103,7 @@ func (a *AssetMintingStore) CommitSignedGenesisTx(ctx context.Context, // transaction we inserted above. if err := q.AnchorGenesisPoint(ctx, GenesisPointAnchor{ PrevOut: genesisOutpoint, - AnchorTxID: sqlInt32(chainTXID), + AnchorTxID: sqlInt64(chainTXID), }); err != nil { return fmt.Errorf("unable to anchor genesis tx: %w", err) } @@ -1167,7 +1167,7 @@ func (a *AssetMintingStore) MarkBatchConfirmed(ctx context.Context, // FetchGroupByGenesis fetches the asset group created by the genesis referenced // by the given ID. func (a *AssetMintingStore) FetchGroupByGenesis(ctx context.Context, - genesisID int32) (*asset.AssetGroup, error) { + genesisID int64) (*asset.AssetGroup, error) { var ( dbGroup *asset.AssetGroup diff --git a/tapdb/asset_minting_test.go b/tapdb/asset_minting_test.go index 7c771bade..96c6320fa 100644 --- a/tapdb/asset_minting_test.go +++ b/tapdb/asset_minting_test.go @@ -656,7 +656,7 @@ func TestCommitBatchChainActions(t *testing.T) { // above, we'll use that to confirm that the managed UTXO has been // updated accordingly. managedUTXO, err := db.FetchManagedUTXO(ctx, sqlc.FetchManagedUTXOParams{ - TxnID: sqlInt32(dbGenTx.TxnID), + TxnID: sqlInt64(dbGenTx.TxnID), }) require.NoError(t, err) require.Equal(t, scriptRoot, managedUTXO.MerkleRoot) @@ -664,14 +664,14 @@ func TestCommitBatchChainActions(t *testing.T) { // Next, we'll confirm that all the assets inserted previously now are // able to be queried according to the anchor UTXO primary key. anchoredAssets, err := db.FetchAssetsByAnchorTx( - ctx, sqlInt32(managedUTXO.UtxoID), + ctx, sqlInt64(managedUTXO.UtxoID), ) require.NoError(t, err) require.Equal(t, numSeedlings, len(anchoredAssets)) // Finally, we'll verify that the genesis point also points to the // inserted chain transaction. - _, err = db.FetchGenesisPointByAnchorTx(ctx, sqlInt32(dbGenTx.TxnID)) + _, err = db.FetchGenesisPointByAnchorTx(ctx, sqlInt64(dbGenTx.TxnID)) require.NoError(t, err) // For each asset created above, we'll make a fake proof file for it. @@ -889,7 +889,7 @@ func TestGroupStore(t *testing.T) { for i, groupInfo := range mintGroups { genID, err := fetchGenesisID(ctx, q, *groupInfo.Genesis) require.NoError(t, err) - expectedID := int32(i + 1) + expectedID := int64(i + 1) require.Equal(t, expectedID, genID) } @@ -914,7 +914,7 @@ func TestGroupStore(t *testing.T) { // We should also be able to look up each asset group with a genesis ID. fetchGroupByGenID := func(q PendingAssetStore) error { for i, groupInfo := range mintGroups { - genID := int32(i + 1) + genID := int64(i + 1) dbGroup, err := fetchGroupByGenesis(ctx, q, genID) require.NoError(t, err) assertGroupEqual(t, groupInfo, dbGroup) @@ -922,8 +922,8 @@ func TestGroupStore(t *testing.T) { // The returned group for the group anchor asset and reissued // asset should be the same. - anchorGenID := int32(1) - reissueGenID := int32(3) + anchorGenID := int64(1) + reissueGenID := int64(3) anchorGroup, err := fetchGroupByGenesis(ctx, q, anchorGenID) require.NoError(t, err) reissueGroup, err := fetchGroupByGenesis(ctx, q, reissueGenID) @@ -948,7 +948,7 @@ func TestGroupStore(t *testing.T) { _ = assetStore.db.ExecTx(ctx, &writeTxOpts, fetchGroupByGenID) // Lookup of an invalid genesis ID should return a wrapped error. - invalidGenID := int32(len(mintGroups) + 1) + invalidGenID := int64(len(mintGroups) + 1) fetchInvalidGenID := func(q PendingAssetStore) error { dbGroup, err := fetchGroupByGenesis(ctx, q, invalidGenID) require.Nil(t, dbGroup) diff --git a/tapdb/assets_common.go b/tapdb/assets_common.go index 37b3a7809..d131b3586 100644 --- a/tapdb/assets_common.go +++ b/tapdb/assets_common.go @@ -21,7 +21,7 @@ import ( type UpsertAssetStore interface { // UpsertGenesisPoint inserts a new or updates an existing genesis point // on disk, and returns the primary key. - UpsertGenesisPoint(ctx context.Context, prevOut []byte) (int32, error) + UpsertGenesisPoint(ctx context.Context, prevOut []byte) (int64, error) // AnchorGenesisPoint associates a genesis point with the transaction // that mints the associated assets on disk. @@ -29,7 +29,7 @@ type UpsertAssetStore interface { // UpsertChainTx inserts a new or updates an existing chain tx into the // DB. - UpsertChainTx(ctx context.Context, arg ChainTxParams) (int32, error) + UpsertChainTx(ctx context.Context, arg ChainTxParams) (int64, error) // UpsertGenesisAsset inserts a new or updates an existing genesis asset // (the base asset info) in the DB, and returns the primary key. @@ -38,51 +38,51 @@ type UpsertAssetStore interface { // accept two diff storage interfaces? // // * or use a sort of mix-in type? - UpsertGenesisAsset(ctx context.Context, arg GenesisAsset) (int32, error) + UpsertGenesisAsset(ctx context.Context, arg GenesisAsset) (int64, error) // FetchGenesisID is used to fetch the database ID of asset genesis // information already in the DB. FetchGenesisID(ctx context.Context, - arg sqlc.FetchGenesisIDParams) (int32, error) + arg sqlc.FetchGenesisIDParams) (int64, error) // FetchScriptKeyIDByTweakedKey determines the database ID of a script // key by querying it by the tweaked key. FetchScriptKeyIDByTweakedKey(ctx context.Context, - tweakedScriptKey []byte) (int32, error) + tweakedScriptKey []byte) (int64, error) // UpsertInternalKey inserts a new or updates an existing internal key // into the database. - UpsertInternalKey(ctx context.Context, arg InternalKey) (int32, error) + UpsertInternalKey(ctx context.Context, arg InternalKey) (int64, error) // UpsertScriptKey inserts a new script key on disk into the DB. - UpsertScriptKey(context.Context, NewScriptKey) (int32, error) + UpsertScriptKey(context.Context, NewScriptKey) (int64, error) // UpsertAssetGroupWitness inserts a new asset group witness into the DB. UpsertAssetGroupWitness(ctx context.Context, - arg AssetGroupWitness) (int32, error) + arg AssetGroupWitness) (int64, error) // UpsertAssetGroupKey inserts a new or updates an existing group key // on disk, and returns the primary key. - UpsertAssetGroupKey(ctx context.Context, arg AssetGroupKey) (int32, + UpsertAssetGroupKey(ctx context.Context, arg AssetGroupKey) (int64, error) // InsertNewAsset inserts a new asset on disk. InsertNewAsset(ctx context.Context, - arg sqlc.InsertNewAssetParams) (int32, error) + arg sqlc.InsertNewAssetParams) (int64, error) // UpsertAssetMeta inserts a new asset meta into the DB. - UpsertAssetMeta(ctx context.Context, arg NewAssetMeta) (int32, error) + UpsertAssetMeta(ctx context.Context, arg NewAssetMeta) (int64, error) // SetAssetSpent marks an asset as being spent in the database. The // updated asset's database ID is returned. - SetAssetSpent(ctx context.Context, arg SetAssetSpentParams) (int32, + SetAssetSpent(ctx context.Context, arg SetAssetSpentParams) (int64, error) } // upsertGenesis imports a new genesis point into the database or returns the // existing ID if that point already exists. func upsertGenesisPoint(ctx context.Context, q UpsertAssetStore, - genesisOutpoint wire.OutPoint) (int32, error) { + genesisOutpoint wire.OutPoint) (int64, error) { genesisPoint, err := encodeOutpoint(genesisOutpoint) if err != nil { @@ -102,7 +102,7 @@ func upsertGenesisPoint(ctx context.Context, q UpsertAssetStore, // upsertGenesis imports a new genesis record into the database or returns the // existing ID of the genesis if it already exists. func upsertGenesis(ctx context.Context, q UpsertAssetStore, - genesisPointID int32, genesis asset.Genesis) (int32, error) { + genesisPointID int64, genesis asset.Genesis) (int64, error) { // Then we'll insert the genesis_assets row which tracks all the // information that uniquely derives a given asset ID. @@ -125,7 +125,7 @@ func upsertGenesis(ctx context.Context, q UpsertAssetStore, // fetchGenesisID fetches the primary key ID for a genesis record already // in the database. func fetchGenesisID(ctx context.Context, q UpsertAssetStore, - genesis asset.Genesis) (int32, error) { + genesis asset.Genesis) (int64, error) { genPoint, err := encodeOutpoint(genesis.FirstPrevOut) if err != nil { @@ -152,7 +152,7 @@ func fetchGenesisID(ctx context.Context, q UpsertAssetStore, // the database. func upsertAssetsWithGenesis(ctx context.Context, q UpsertAssetStore, genesisOutpoint wire.OutPoint, assets []*asset.Asset, - anchorUtxoIDs []sql.NullInt32) (int32, []int32, error) { + anchorUtxoIDs []sql.NullInt64) (int64, []int64, error) { // First, we'll insert the component that ties together all the assets // in a batch: the genesis point. @@ -165,7 +165,7 @@ func upsertAssetsWithGenesis(ctx context.Context, q UpsertAssetStore, // We'll now insert each asset into the database. Some assets have a key // group, so we'll need to insert them before we can insert the asset // itself. - assetIDs := make([]int32, len(assets)) + assetIDs := make([]int64, len(assets)) for idx, a := range assets { // First, we make sure the genesis asset information exists in // the database. @@ -195,7 +195,7 @@ func upsertAssetsWithGenesis(ctx context.Context, q UpsertAssetStore, } // Is the asset anchored already? - var anchorUtxoID sql.NullInt32 + var anchorUtxoID sql.NullInt64 if len(anchorUtxoIDs) > 0 { anchorUtxoID = anchorUtxoIDs[idx] } @@ -227,11 +227,11 @@ func upsertAssetsWithGenesis(ctx context.Context, q UpsertAssetStore, // upsertGroupKey inserts or updates a group key and its associated internal // key. func upsertGroupKey(ctx context.Context, groupKey *asset.GroupKey, - q UpsertAssetStore, genesisPointID, genAssetID int32) (sql.NullInt32, + q UpsertAssetStore, genesisPointID, genAssetID int64) (sql.NullInt64, error) { // No group key, this asset is not re-issuable. - var nullID sql.NullInt32 + var nullID sql.NullInt64 if groupKey == nil { return nullID, nil } @@ -302,13 +302,13 @@ func upsertGroupKey(ctx context.Context, groupKey *asset.GroupKey, return nullID, fmt.Errorf("unable to insert group sig: %w", err) } - return sqlInt32(groupWitnessID), nil + return sqlInt64(groupWitnessID), nil } // upsertScriptKey inserts or updates a script key and its associated internal // key. func upsertScriptKey(ctx context.Context, scriptKey asset.ScriptKey, - q UpsertAssetStore) (int32, error) { + q UpsertAssetStore) (int64, error) { if scriptKey.TweakedScriptKey != nil { rawScriptKeyID, err := q.UpsertInternalKey(ctx, InternalKey{ @@ -370,13 +370,13 @@ func upsertScriptKey(ctx context.Context, scriptKey asset.ScriptKey, type FetchGenesisStore interface { // FetchGenesisByID returns a single genesis asset by its primary key // ID. - FetchGenesisByID(ctx context.Context, assetID int32) (Genesis, error) + FetchGenesisByID(ctx context.Context, assetID int64) (Genesis, error) } // fetchGenesis returns a fully populated genesis record from the database, // identified by its primary key ID. func fetchGenesis(ctx context.Context, q FetchGenesisStore, - assetID int32) (asset.Genesis, error) { + assetID int64) (asset.Genesis, error) { // Now we fetch the genesis information that so far we only have the ID // for in the address record. @@ -415,7 +415,7 @@ type GroupStore interface { // FetchGroupByGenesis fetches information on the asset group created // with the asset genesis referenced by a specific genesis ID. FetchGroupByGenesis(ctx context.Context, - genesisID int32) (sqlc.FetchGroupByGenesisRow, error) + genesisID int64) (sqlc.FetchGroupByGenesisRow, error) // FetchGroupByGroupKey fetches information on the asset group with // a matching group key. @@ -426,7 +426,7 @@ type GroupStore interface { // fetchGroupByGenesis fetches the asset group created by the genesis referenced // by the given ID. func fetchGroupByGenesis(ctx context.Context, q GroupStore, - genID int32) (*asset.AssetGroup, error) { + genID int64) (*asset.AssetGroup, error) { groupInfo, err := q.FetchGroupByGenesis(ctx, genID) switch { @@ -532,7 +532,7 @@ func parseGroupKeyInfo(tweakedKey, rawKey, witness, tapscriptRoot []byte, // maybeUpsertAssetMeta inserts a meta on disk and returns the primary key of // that meta if metaReveal is non nil. func maybeUpsertAssetMeta(ctx context.Context, db UpsertAssetStore, - assetGen *asset.Genesis, metaReveal *proof.MetaReveal) (int32, error) { + assetGen *asset.Genesis, metaReveal *proof.MetaReveal) (int64, error) { var ( metaHash [32]byte diff --git a/tapdb/assets_store.go b/tapdb/assets_store.go index 669000d45..84256f99e 100644 --- a/tapdb/assets_store.go +++ b/tapdb/assets_store.go @@ -174,14 +174,14 @@ type ActiveAssetsStore interface { // UpsertChainTx inserts a new or updates an existing chain tx into the // DB. - UpsertChainTx(ctx context.Context, arg ChainTxParams) (int32, error) + UpsertChainTx(ctx context.Context, arg ChainTxParams) (int64, error) // FetchChainTx fetches a chain tx from the DB. FetchChainTx(ctx context.Context, txid []byte) (ChainTx, error) // UpsertManagedUTXO inserts a new or updates an existing managed UTXO // to disk and returns the primary key. - UpsertManagedUTXO(ctx context.Context, arg RawManagedUTXO) (int32, + UpsertManagedUTXO(ctx context.Context, arg RawManagedUTXO) (int64, error) // UpsertAssetProof inserts a new or updates an existing asset proof on @@ -195,7 +195,7 @@ type ActiveAssetsStore interface { // FetchAssetWitnesses attempts to fetch either all the asset witnesses // on disk (NULL param), or the witness for a given asset ID. - FetchAssetWitnesses(context.Context, sql.NullInt32) ([]AssetWitness, + FetchAssetWitnesses(context.Context, sql.NullInt64) ([]AssetWitness, error) // FetchManagedUTXO fetches a managed UTXO based on either the outpoint @@ -207,7 +207,7 @@ type ActiveAssetsStore interface { // ApplyPendingOutput applies a transfer output (new amount and script // key) based on the existing script key of an asset. - ApplyPendingOutput(ctx context.Context, arg ApplyPendingOutput) (int32, + ApplyPendingOutput(ctx context.Context, arg ApplyPendingOutput) (int64, error) // DeleteManagedUTXO deletes the managed utxo identified by the passed @@ -231,7 +231,7 @@ type ActiveAssetsStore interface { // InsertAssetTransfer inserts a new asset transfer into the DB. InsertAssetTransfer(ctx context.Context, - arg NewAssetTransfer) (int32, error) + arg NewAssetTransfer) (int64, error) // InsertAssetTransferInput inserts a new asset transfer input into the // DB. @@ -245,11 +245,11 @@ type ActiveAssetsStore interface { // FetchTransferInputs fetches the inputs to a given asset transfer. FetchTransferInputs(ctx context.Context, - transferID int32) ([]TransferInputRow, error) + transferID int64) ([]TransferInputRow, error) // FetchTransferOutputs fetches the outputs to a given asset transfer. FetchTransferOutputs(ctx context.Context, - transferID int32) ([]TransferOutputRow, error) + transferID int64) ([]TransferOutputRow, error) // QueryAssetTransfers queries for a set of asset transfers in the db. QueryAssetTransfers(ctx context.Context, @@ -258,7 +258,7 @@ type ActiveAssetsStore interface { // DeleteAssetWitnesses deletes the witnesses on disk associated with a // given asset ID. - DeleteAssetWitnesses(ctx context.Context, assetID int32) error + DeleteAssetWitnesses(ctx context.Context, assetID int64) error // InsertReceiverProofTransferAttempt inserts a new receiver proof // transfer attempt record. @@ -277,7 +277,7 @@ type ActiveAssetsStore interface { // QueryPassiveAssets returns the data required to re-anchor // pending passive assets that are anchored at the given outpoint. QueryPassiveAssets(ctx context.Context, - transferID int32) ([]PassiveAsset, error) + transferID int64) ([]PassiveAsset, error) // ReAnchorPassiveAssets re-anchors the passive assets identified by // the passed params. @@ -459,17 +459,17 @@ type AssetHumanReadable struct { // assetWitnesses maps the primary key of an asset to a slice of its previous // input (witness) information. -type assetWitnesses map[int32][]AssetWitness +type assetWitnesses map[int64][]AssetWitness // fetchAssetWitnesses attempts to fetch all the asset witnesses that belong to // the set of passed asset IDs. func fetchAssetWitnesses(ctx context.Context, db ActiveAssetsStore, - assetIDs []int32) (assetWitnesses, error) { + assetIDs []int64) (assetWitnesses, error) { - assetWitnesses := make(map[int32][]AssetWitness) + assetWitnesses := make(map[int64][]AssetWitness) for _, assetID := range assetIDs { witnesses, err := db.FetchAssetWitnesses( - ctx, sqlInt32(assetID), + ctx, sqlInt64(assetID), ) if err != nil { return nil, err @@ -859,7 +859,7 @@ func fetchAssetsWithWitness(ctx context.Context, q ActiveAssetsStore, return nil, nil, fmt.Errorf("unable to read db assets: %v", err) } - assetIDs := fMap(dbAssets, func(a ConfirmedAsset) int32 { + assetIDs := fMap(dbAssets, func(a ConfirmedAsset) int64 { return a.AssetPrimaryKey }) @@ -1042,7 +1042,7 @@ func (a *AssetStore) FetchAllAssets(ctx context.Context, includeSpent, var ( dbAssets []ConfirmedAsset - assetWitnesses map[int32][]AssetWitness + assetWitnesses map[int64][]AssetWitness err error ) @@ -1292,7 +1292,7 @@ func (a *AssetStore) FetchProofs(ctx context.Context, // // TODO(ffranr): Change insert function into an upsert. func (a *AssetStore) insertAssetWitnesses(ctx context.Context, - db ActiveAssetsStore, assetID int32, inputs []asset.Witness) error { + db ActiveAssetsStore, assetID int64, inputs []asset.Witness) error { var buf [8]byte for idx := range inputs { @@ -1438,7 +1438,7 @@ func (a *AssetStore) importAssetFromProof(ctx context.Context, // Insert/update the asset information in the database now. _, assetIDs, err := upsertAssetsWithGenesis( ctx, db, newAsset.Genesis.FirstPrevOut, - []*asset.Asset{newAsset}, []sql.NullInt32{sqlInt32(utxoID)}, + []*asset.Asset{newAsset}, []sql.NullInt64{sqlInt64(utxoID)}, ) if err != nil { return fmt.Errorf("error inserting asset with genesis: %w", err) @@ -1968,7 +1968,7 @@ func (a *AssetStore) LogPendingParcel(ctx context.Context, // insertAssetTransferInput inserts a new asset transfer input into the DB. func insertAssetTransferInput(ctx context.Context, q ActiveAssetsStore, - transferID int32, input tapfreighter.TransferInput, + transferID int64, input tapfreighter.TransferInput, finalLeaseOwner [32]byte, finalLeaseExpiry time.Time) error { anchorPointBytes, err := encodeOutpoint(input.OutPoint) @@ -2002,7 +2002,7 @@ func insertAssetTransferInput(ctx context.Context, q ActiveAssetsStore, // fetchAssetTransferInputs fetches all the inputs for a given transfer ID. func fetchAssetTransferInputs(ctx context.Context, q ActiveAssetsStore, - transferID int32) ([]tapfreighter.TransferInput, error) { + transferID int64) ([]tapfreighter.TransferInput, error) { dbInputs, err := q.FetchTransferInputs(ctx, transferID) if err != nil { @@ -2042,7 +2042,7 @@ func fetchAssetTransferInputs(ctx context.Context, q ActiveAssetsStore, // insertAssetTransferOutput inserts a new asset transfer output into the DB // and returns its ID. func insertAssetTransferOutput(ctx context.Context, q ActiveAssetsStore, - transferID, txnID int32, output tapfreighter.TransferOutput, + transferID, txnID int64, output tapfreighter.TransferOutput, passiveAssets []*tapfreighter.PassiveAssetReAnchor) error { anchor := output.Anchor @@ -2165,7 +2165,7 @@ func insertAssetTransferOutput(ctx context.Context, q ActiveAssetsStore, // fetchAssetTransferOutputs fetches all the outputs for a given transfer ID. func fetchAssetTransferOutputs(ctx context.Context, q ActiveAssetsStore, - transferID int32) ([]tapfreighter.TransferOutput, error) { + transferID int64) ([]tapfreighter.TransferOutput, error) { dbOutputs, err := q.FetchTransferOutputs(ctx, transferID) if err != nil { @@ -2283,7 +2283,7 @@ func fetchAssetTransferOutputs(ctx context.Context, q ActiveAssetsStore, // logPendingPassiveAssets logs passive assets re-anchoring data to disk. func logPendingPassiveAssets(ctx context.Context, - q ActiveAssetsStore, transferID, newUtxoID int32, + q ActiveAssetsStore, transferID, newUtxoID int64, passiveAssets []*tapfreighter.PassiveAssetReAnchor) error { for idx := range passiveAssets { @@ -2434,7 +2434,7 @@ func (a *AssetStore) ConfirmParcelDelivery(ctx context.Context, // We'll keep around the IDs of the assets that we set to being // spent. We'll need one of them as our template to create the // new assets. - spentAssetIDs := make([]int32, len(inputs)) + spentAssetIDs := make([]int64, len(inputs)) for idx := range inputs { spentAssetIDs[idx], err = q.SetAssetSpent( ctx, SetAssetSpentParams{ @@ -2511,7 +2511,7 @@ func (a *AssetStore) ConfirmParcelDelivery(ctx context.Context, templateID := spentAssetIDs[0] params := ApplyPendingOutput{ ScriptKeyID: out.ScriptKeyID, - AnchorUtxoID: sqlInt32( + AnchorUtxoID: sqlInt64( out.AnchorUtxoID, ), Amount: out.Amount, @@ -2612,7 +2612,7 @@ func (a *AssetStore) ConfirmParcelDelivery(ctx context.Context, // reAnchorPassiveAssets re-anchors all passive assets that were anchored by // the given transfer output. func (a *AssetStore) reAnchorPassiveAssets(ctx context.Context, - q ActiveAssetsStore, transferID int32, + q ActiveAssetsStore, transferID int64, proofFiles map[[32]byte]proof.Blob) error { passiveAssets, err := q.QueryPassiveAssets(ctx, transferID) @@ -2675,7 +2675,7 @@ func (a *AssetStore) reAnchorPassiveAssets(ctx context.Context, // Update the asset proof. err = q.UpsertAssetProof(ctx, ProofUpdate{ - AssetID: sqlInt32(passiveAsset.AssetID), + AssetID: sqlInt64(passiveAsset.AssetID), ProofFile: proofFile, }) if err != nil { @@ -2685,7 +2685,7 @@ func (a *AssetStore) reAnchorPassiveAssets(ctx context.Context, // And finally, update the anchor UTXO of the asset in question. err = q.ReAnchorPassiveAssets(ctx, ReAnchorParams{ - NewAnchorUtxoID: sqlInt32(passiveAsset.NewAnchorUtxo), + NewAnchorUtxoID: sqlInt64(passiveAsset.NewAnchorUtxo), AssetID: passiveAsset.AssetID, }) if err != nil { diff --git a/tapdb/interfaces_test.go b/tapdb/interfaces_test.go index 1cf7b6962..33a10b061 100644 --- a/tapdb/interfaces_test.go +++ b/tapdb/interfaces_test.go @@ -1,6 +1,7 @@ package tapdb import ( + "encoding/hex" "testing" "github.com/stretchr/testify/require" @@ -28,3 +29,43 @@ func TestExecutorOptionRetryDelay(t *testing.T) { // Expect the value to be capped at the maximum delay. require.Equal(t, opts.maxRetryDelay, opts.randRetryDelay(100)) } + +// TestInt64PrimaryKey makes sure that we can actually store proper int64 +// numbers as the primary key in our database. +func TestInt64PrimaryKey(t *testing.T) { + t.Parallel() + + db := NewTestDB(t) + t.Cleanup(func() { + require.NoError(t, db.Close()) + }) + + testHash, err := hex.DecodeString( + "d6c3887fbb041e5ce486e12f7bd8cf2131b3f0705d116bf2c893ee946158" + + "fe80", + ) + require.NoError(t, err) + testID := int64(9223372036854775807) + + // Insert a row with a large int64 primary key. + _, err = db.Exec(` + INSERT INTO assets_meta (meta_id, meta_data_hash) + VALUES ($1, $2); + `, testID, testHash) + require.NoError(t, err) + + // Query the row and make sure we get the correct value back. + var ( + storedID int64 + storedHash []byte + ) + err = db.QueryRow(` + SELECT meta_id, meta_data_hash + FROM assets_meta + WHERE meta_id = $1; + `, testID).Scan(&storedID, &storedHash) + require.NoError(t, err) + + require.Equal(t, testID, storedID) + require.Equal(t, testHash, storedHash) +} diff --git a/tapdb/postgres.go b/tapdb/postgres.go index 167a5a6e0..0670e4982 100644 --- a/tapdb/postgres.go +++ b/tapdb/postgres.go @@ -98,6 +98,7 @@ func NewPostgresStore(cfg *PostgresConfig) (*PostgresStore, error) { postgresFS := newReplacerFS(sqlSchemas, map[string]string{ "BLOB": "BYTEA", "INTEGER PRIMARY KEY": "SERIAL PRIMARY KEY", + "BIGINT PRIMARY KEY": "BIGSERIAL PRIMARY KEY", "TIMESTAMP": "TIMESTAMP WITHOUT TIME ZONE", }) diff --git a/tapdb/sqlc/addrs.sql.go b/tapdb/sqlc/addrs.sql.go index 47fe76a7c..ceb4b67c9 100644 --- a/tapdb/sqlc/addrs.sql.go +++ b/tapdb/sqlc/addrs.sql.go @@ -37,7 +37,7 @@ WHERE taproot_output_key = $1 type FetchAddrByTaprootOutputKeyRow struct { Version int16 AssetVersion int16 - GenesisAssetID int32 + GenesisAssetID int64 GroupKey []byte TapscriptSibling []byte TaprootOutputKey []byte @@ -105,8 +105,8 @@ WHERE id = $1 type FetchAddrEventRow struct { CreationTime time.Time Status int16 - AssetProofID sql.NullInt32 - AssetID sql.NullInt32 + AssetProofID sql.NullInt64 + AssetID sql.NullInt64 Txid []byte ConfirmationHeight sql.NullInt32 OutputIndex int32 @@ -115,7 +115,7 @@ type FetchAddrEventRow struct { InternalKey []byte } -func (q *Queries) FetchAddrEvent(ctx context.Context, id int32) (FetchAddrEventRow, error) { +func (q *Queries) FetchAddrEvent(ctx context.Context, id int64) (FetchAddrEventRow, error) { row := q.db.QueryRowContext(ctx, fetchAddrEvent, id) var i FetchAddrEventRow err := row.Scan( @@ -172,7 +172,7 @@ type FetchAddrsParams struct { type FetchAddrsRow struct { Version int16 AssetVersion int16 - GenesisAssetID int32 + GenesisAssetID int64 GroupKey []byte TapscriptSibling []byte TaprootOutputKey []byte @@ -251,10 +251,10 @@ INSERT INTO addrs ( type InsertAddrParams struct { Version int16 AssetVersion int16 - GenesisAssetID int32 + GenesisAssetID int64 GroupKey []byte - ScriptKeyID int32 - TaprootKeyID int32 + ScriptKeyID int64 + TaprootKeyID int64 TapscriptSibling []byte TaprootOutputKey []byte Amount int64 @@ -263,7 +263,7 @@ type InsertAddrParams struct { ProofCourierAddr []byte } -func (q *Queries) InsertAddr(ctx context.Context, arg InsertAddrParams) (int32, error) { +func (q *Queries) InsertAddr(ctx context.Context, arg InsertAddrParams) (int64, error) { row := q.db.QueryRowContext(ctx, insertAddr, arg.Version, arg.AssetVersion, @@ -278,7 +278,7 @@ func (q *Queries) InsertAddr(ctx context.Context, arg InsertAddrParams) (int32, arg.CreationTime, arg.ProofCourierAddr, ) - var id int32 + var id int64 err := row.Scan(&id) return id, err } @@ -302,7 +302,7 @@ type QueryEventIDsParams struct { } type QueryEventIDsRow struct { - EventID int32 + EventID int64 TaprootOutputKey []byte } @@ -380,12 +380,12 @@ type UpsertAddrEventParams struct { CreationTime time.Time Status int16 ChainTxnOutputIndex int32 - ManagedUtxoID int32 - AssetProofID sql.NullInt32 - AssetID sql.NullInt32 + ManagedUtxoID int64 + AssetProofID sql.NullInt64 + AssetID sql.NullInt64 } -func (q *Queries) UpsertAddrEvent(ctx context.Context, arg UpsertAddrEventParams) (int32, error) { +func (q *Queries) UpsertAddrEvent(ctx context.Context, arg UpsertAddrEventParams) (int64, error) { row := q.db.QueryRowContext(ctx, upsertAddrEvent, arg.TaprootOutputKey, arg.Txid, @@ -396,7 +396,7 @@ func (q *Queries) UpsertAddrEvent(ctx context.Context, arg UpsertAddrEventParams arg.AssetProofID, arg.AssetID, ) - var id int32 + var id int64 err := row.Scan(&id) return id, err } diff --git a/tapdb/sqlc/assets.sql.go b/tapdb/sqlc/assets.sql.go index f9e43e532..754b818db 100644 --- a/tapdb/sqlc/assets.sql.go +++ b/tapdb/sqlc/assets.sql.go @@ -94,14 +94,14 @@ ON asset_minting_batches.batch_id = internal_keys.key_id ` type AllMintingBatchesRow struct { - BatchID int32 + BatchID int64 BatchState int16 MintingTxPsbt []byte ChangeOutputIndex sql.NullInt32 - GenesisID sql.NullInt32 + GenesisID sql.NullInt64 HeightHint int32 CreationTimeUnix time.Time - KeyID int32 + KeyID int64 RawKey []byte KeyFamily int32 KeyIndex int32 @@ -155,7 +155,7 @@ WHERE genesis_id in (SELECT genesis_id FROM target_point) type AnchorGenesisPointParams struct { PrevOut []byte - AnchorTxID sql.NullInt32 + AnchorTxID sql.NullInt64 } func (q *Queries) AnchorGenesisPoint(ctx context.Context, arg AnchorGenesisPointParams) error { @@ -180,7 +180,7 @@ WHERE script_key_id in (SELECT script_key_id FROM assets_to_update) type AnchorPendingAssetsParams struct { PrevOut []byte - AnchorUtxoID sql.NullInt32 + AnchorUtxoID sql.NullInt64 } func (q *Queries) AnchorPendingAssets(ctx context.Context, arg AnchorPendingAssetsParams) error { @@ -199,29 +199,29 @@ WHERE prev_out = $1 ` type AssetsByGenesisPointRow struct { - AssetID int32 - GenesisID int32 + AssetID int64 + GenesisID int64 Version int32 - ScriptKeyID int32 - AssetGroupWitnessID sql.NullInt32 + ScriptKeyID int64 + AssetGroupWitnessID sql.NullInt64 ScriptVersion int32 Amount int64 LockTime sql.NullInt32 RelativeLockTime sql.NullInt32 SplitCommitmentRootHash []byte SplitCommitmentRootValue sql.NullInt64 - AnchorUtxoID sql.NullInt32 + AnchorUtxoID sql.NullInt64 Spent bool - GenAssetID int32 + GenAssetID int64 AssetID_2 []byte AssetTag string - MetaDataID sql.NullInt32 + MetaDataID sql.NullInt64 OutputIndex int32 AssetType int16 - GenesisPointID int32 - GenesisID_2 int32 + GenesisPointID int64 + GenesisID_2 int64 PrevOut []byte - AnchorTxID sql.NullInt32 + AnchorTxID sql.NullInt64 } func (q *Queries) AssetsByGenesisPoint(ctx context.Context, prevOut []byte) ([]AssetsByGenesisPointRow, error) { @@ -288,7 +288,7 @@ WHERE keys.raw_key = $1 ` type AssetsInBatchRow struct { - GenAssetID int32 + GenAssetID int64 AssetID []byte AssetTag string MetaDataHash []byte @@ -345,7 +345,7 @@ type BindMintingBatchWithTxParams struct { RawKey []byte MintingTxPsbt []byte ChangeOutputIndex sql.NullInt32 - GenesisID sql.NullInt32 + GenesisID sql.NullInt64 } func (q *Queries) BindMintingBatchWithTx(ctx context.Context, arg BindMintingBatchWithTxParams) error { @@ -459,7 +459,7 @@ type FetchAssetMetaRow struct { MetaDataType sql.NullInt16 } -func (q *Queries) FetchAssetMeta(ctx context.Context, metaID int32) (FetchAssetMetaRow, error) { +func (q *Queries) FetchAssetMeta(ctx context.Context, metaID int64) (FetchAssetMetaRow, error) { row := q.db.QueryRowContext(ctx, fetchAssetMeta, metaID) var i FetchAssetMetaRow err := row.Scan(&i.MetaDataHash, &i.MetaDataBlob, &i.MetaDataType) @@ -524,8 +524,8 @@ JOIN asset_info type FetchAssetProofRow struct { ScriptKey []byte ProofFile []byte - AssetID int32 - ProofID int32 + AssetID int64 + ProofID int64 } func (q *Queries) FetchAssetProof(ctx context.Context, tweakedScriptKey []byte) (FetchAssetProofRow, error) { @@ -638,7 +638,7 @@ WHERE ( ` type FetchAssetWitnessesRow struct { - AssetID int32 + AssetID int64 PrevOutPoint []byte PrevAssetID []byte PrevScriptKey []byte @@ -646,7 +646,7 @@ type FetchAssetWitnessesRow struct { SplitCommitmentProof []byte } -func (q *Queries) FetchAssetWitnesses(ctx context.Context, assetID sql.NullInt32) ([]FetchAssetWitnessesRow, error) { +func (q *Queries) FetchAssetWitnesses(ctx context.Context, assetID sql.NullInt64) ([]FetchAssetWitnessesRow, error) { rows, err := q.db.QueryContext(ctx, fetchAssetWitnesses, assetID) if err != nil { return nil, err @@ -682,7 +682,7 @@ FROM assets WHERE anchor_utxo_id = $1 ` -func (q *Queries) FetchAssetsByAnchorTx(ctx context.Context, anchorUtxoID sql.NullInt32) ([]Asset, error) { +func (q *Queries) FetchAssetsByAnchorTx(ctx context.Context, anchorUtxoID sql.NullInt64) ([]Asset, error) { rows, err := q.db.QueryContext(ctx, fetchAssetsByAnchorTx, anchorUtxoID) if err != nil { return nil, err @@ -930,7 +930,7 @@ type FetchGenesisByIDRow struct { PrevOut []byte } -func (q *Queries) FetchGenesisByID(ctx context.Context, genAssetID int32) (FetchGenesisByIDRow, error) { +func (q *Queries) FetchGenesisByID(ctx context.Context, genAssetID int64) (FetchGenesisByIDRow, error) { row := q.db.QueryRowContext(ctx, fetchGenesisByID, genAssetID) var i FetchGenesisByIDRow err := row.Scan( @@ -973,7 +973,7 @@ type FetchGenesisIDParams struct { PrevOut []byte } -func (q *Queries) FetchGenesisID(ctx context.Context, arg FetchGenesisIDParams) (int32, error) { +func (q *Queries) FetchGenesisID(ctx context.Context, arg FetchGenesisIDParams) (int64, error) { row := q.db.QueryRowContext(ctx, fetchGenesisID, arg.AssetID, arg.AssetTag, @@ -982,7 +982,7 @@ func (q *Queries) FetchGenesisID(ctx context.Context, arg FetchGenesisIDParams) arg.AssetType, arg.PrevOut, ) - var gen_asset_id int32 + var gen_asset_id int64 err := row.Scan(&gen_asset_id) return gen_asset_id, err } @@ -993,7 +993,7 @@ FROM genesis_points WHERE anchor_tx_id = $1 ` -func (q *Queries) FetchGenesisPointByAnchorTx(ctx context.Context, anchorTxID sql.NullInt32) (GenesisPoint, error) { +func (q *Queries) FetchGenesisPointByAnchorTx(ctx context.Context, anchorTxID sql.NullInt64) (GenesisPoint, error) { row := q.db.QueryRowContext(ctx, fetchGenesisPointByAnchorTx, anchorTxID) var i GenesisPoint err := row.Scan(&i.GenesisID, &i.PrevOut, &i.AnchorTxID) @@ -1023,7 +1023,7 @@ type FetchGroupByGenesisRow struct { WitnessStack []byte } -func (q *Queries) FetchGroupByGenesis(ctx context.Context, genesisID int32) (FetchGroupByGenesisRow, error) { +func (q *Queries) FetchGroupByGenesis(ctx context.Context, genesisID int64) (FetchGroupByGenesisRow, error) { row := q.db.QueryRowContext(ctx, fetchGroupByGenesis, genesisID) var i FetchGroupByGenesisRow err := row.Scan( @@ -1054,7 +1054,7 @@ LIMIT 1 ` type FetchGroupByGroupKeyRow struct { - GenAssetID int32 + GenAssetID int64 RawKey []byte KeyIndex int32 KeyFamily int32 @@ -1095,7 +1095,7 @@ WHERE spent = false ` type FetchGroupedAssetsRow struct { - AssetPrimaryKey int32 + AssetPrimaryKey int64 Amount int64 LockTime sql.NullInt32 RelativeLockTime sql.NullInt32 @@ -1153,22 +1153,22 @@ WHERE ( ` type FetchManagedUTXOParams struct { - TxnID sql.NullInt32 + TxnID sql.NullInt64 Outpoint []byte } type FetchManagedUTXORow struct { - UtxoID int32 + UtxoID int64 Outpoint []byte AmtSats int64 - InternalKeyID int32 + InternalKeyID int64 TaprootAssetRoot []byte TapscriptSibling []byte MerkleRoot []byte - TxnID int32 + TxnID int64 LeaseOwner []byte LeaseExpiry sql.NullTime - KeyID int32 + KeyID int64 RawKey []byte KeyFamily int32 KeyIndex int32 @@ -1204,17 +1204,17 @@ JOIN internal_keys keys ` type FetchManagedUTXOsRow struct { - UtxoID int32 + UtxoID int64 Outpoint []byte AmtSats int64 - InternalKeyID int32 + InternalKeyID int64 TaprootAssetRoot []byte TapscriptSibling []byte MerkleRoot []byte - TxnID int32 + TxnID int64 LeaseOwner []byte LeaseExpiry sql.NullTime - KeyID int32 + KeyID int64 RawKey []byte KeyFamily int32 KeyIndex int32 @@ -1278,14 +1278,14 @@ WHERE batch_id in (SELECT batch_id FROM target_batch) ` type FetchMintingBatchRow struct { - BatchID int32 + BatchID int64 BatchState int16 MintingTxPsbt []byte ChangeOutputIndex sql.NullInt32 - GenesisID sql.NullInt32 + GenesisID sql.NullInt64 HeightHint int32 CreationTimeUnix time.Time - KeyID int32 + KeyID int64 RawKey []byte KeyFamily int32 KeyIndex int32 @@ -1319,14 +1319,14 @@ WHERE batches.batch_state != $1 ` type FetchMintingBatchesByInverseStateRow struct { - BatchID int32 + BatchID int64 BatchState int16 MintingTxPsbt []byte ChangeOutputIndex sql.NullInt32 - GenesisID sql.NullInt32 + GenesisID sql.NullInt64 HeightHint int32 CreationTimeUnix time.Time - KeyID int32 + KeyID int64 RawKey []byte KeyFamily int32 KeyIndex int32 @@ -1400,9 +1400,9 @@ FROM script_keys WHERE tweaked_script_key = $1 ` -func (q *Queries) FetchScriptKeyIDByTweakedKey(ctx context.Context, tweakedScriptKey []byte) (int32, error) { +func (q *Queries) FetchScriptKeyIDByTweakedKey(ctx context.Context, tweakedScriptKey []byte) (int64, error) { row := q.db.QueryRowContext(ctx, fetchScriptKeyIDByTweakedKey, tweakedScriptKey) - var script_key_id int32 + var script_key_id int64 err := row.Scan(&script_key_id) return script_key_id, err } @@ -1413,7 +1413,7 @@ FROM asset_seedlings WHERE seedling_id = $1 ` -func (q *Queries) FetchSeedlingByID(ctx context.Context, seedlingID int32) (AssetSeedling, error) { +func (q *Queries) FetchSeedlingByID(ctx context.Context, seedlingID int64) (AssetSeedling, error) { row := q.db.QueryRowContext(ctx, fetchSeedlingByID, seedlingID) var i AssetSeedling err := row.Scan( @@ -1453,9 +1453,9 @@ type FetchSeedlingIDParams struct { BatchKey []byte } -func (q *Queries) FetchSeedlingID(ctx context.Context, arg FetchSeedlingIDParams) (int32, error) { +func (q *Queries) FetchSeedlingID(ctx context.Context, arg FetchSeedlingIDParams) (int64, error) { row := q.db.QueryRowContext(ctx, fetchSeedlingID, arg.SeedlingName, arg.BatchKey) - var seedling_id int32 + var seedling_id int64 err := row.Scan(&seedling_id) return seedling_id, err } @@ -1479,7 +1479,7 @@ WHERE asset_seedlings.batch_id in (SELECT batch_id FROM target_batch) ` type FetchSeedlingsForBatchRow struct { - SeedlingID int32 + SeedlingID int64 AssetName string AssetType int16 AssetSupply int64 @@ -1487,9 +1487,9 @@ type FetchSeedlingsForBatchRow struct { MetaDataType sql.NullInt16 MetaDataBlob []byte EmissionEnabled bool - BatchID int32 - GroupGenesisID sql.NullInt32 - GroupAnchorID sql.NullInt32 + BatchID int64 + GroupGenesisID sql.NullInt64 + GroupAnchorID sql.NullInt64 } func (q *Queries) FetchSeedlingsForBatch(ctx context.Context, rawKey []byte) ([]FetchSeedlingsForBatchRow, error) { @@ -1605,11 +1605,11 @@ type InsertAssetSeedlingParams struct { AssetName string AssetType int16 AssetSupply int64 - AssetMetaID int32 + AssetMetaID int64 EmissionEnabled bool - BatchID int32 - GroupGenesisID sql.NullInt32 - GroupAnchorID sql.NullInt32 + BatchID int64 + GroupGenesisID sql.NullInt64 + GroupAnchorID sql.NullInt64 } func (q *Queries) InsertAssetSeedling(ctx context.Context, arg InsertAssetSeedlingParams) error { @@ -1652,10 +1652,10 @@ type InsertAssetSeedlingIntoBatchParams struct { AssetName string AssetType int16 AssetSupply int64 - AssetMetaID int32 + AssetMetaID int64 EmissionEnabled bool - GroupGenesisID sql.NullInt32 - GroupAnchorID sql.NullInt32 + GroupGenesisID sql.NullInt64 + GroupAnchorID sql.NullInt64 } func (q *Queries) InsertAssetSeedlingIntoBatch(ctx context.Context, arg InsertAssetSeedlingIntoBatchParams) error { @@ -1682,7 +1682,7 @@ INSERT INTO asset_witnesses ( ` type InsertAssetWitnessParams struct { - AssetID int32 + AssetID int64 PrevOutPoint []byte PrevAssetID []byte PrevScriptKey []byte @@ -1712,19 +1712,19 @@ INSERT INTO assets ( ` type InsertNewAssetParams struct { - GenesisID int32 + GenesisID int64 Version int32 - ScriptKeyID int32 - AssetGroupWitnessID sql.NullInt32 + ScriptKeyID int64 + AssetGroupWitnessID sql.NullInt64 ScriptVersion int32 Amount int64 LockTime sql.NullInt32 RelativeLockTime sql.NullInt32 - AnchorUtxoID sql.NullInt32 + AnchorUtxoID sql.NullInt64 Spent bool } -func (q *Queries) InsertNewAsset(ctx context.Context, arg InsertNewAssetParams) (int32, error) { +func (q *Queries) InsertNewAsset(ctx context.Context, arg InsertNewAssetParams) (int64, error) { row := q.db.QueryRowContext(ctx, insertNewAsset, arg.GenesisID, arg.Version, @@ -1737,7 +1737,7 @@ func (q *Queries) InsertNewAsset(ctx context.Context, arg InsertNewAssetParams) arg.AnchorUtxoID, arg.Spent, ) - var asset_id int32 + var asset_id int64 err := row.Scan(&asset_id) return asset_id, err } @@ -1749,7 +1749,7 @@ INSERT INTO asset_minting_batches ( ` type NewMintingBatchParams struct { - BatchID int32 + BatchID int64 HeightHint int32 CreationTimeUnix time.Time } @@ -1951,8 +1951,8 @@ type QueryAssetsParams struct { } type QueryAssetsRow struct { - AssetPrimaryKey int32 - GenesisID int32 + AssetPrimaryKey int64 + GenesisID int64 Version int32 Spent bool ScriptKeyTweak []byte @@ -2096,9 +2096,9 @@ type SetAssetSpentParams struct { GenAssetID []byte } -func (q *Queries) SetAssetSpent(ctx context.Context, arg SetAssetSpentParams) (int32, error) { +func (q *Queries) SetAssetSpent(ctx context.Context, arg SetAssetSpentParams) (int64, error) { row := q.db.QueryRowContext(ctx, setAssetSpent, arg.ScriptKey, arg.GenAssetID) - var asset_id int32 + var asset_id int64 err := row.Scan(&asset_id) return asset_id, err } @@ -2185,18 +2185,18 @@ RETURNING group_id type UpsertAssetGroupKeyParams struct { TweakedGroupKey []byte TapscriptRoot []byte - InternalKeyID int32 - GenesisPointID int32 + InternalKeyID int64 + GenesisPointID int64 } -func (q *Queries) UpsertAssetGroupKey(ctx context.Context, arg UpsertAssetGroupKeyParams) (int32, error) { +func (q *Queries) UpsertAssetGroupKey(ctx context.Context, arg UpsertAssetGroupKeyParams) (int64, error) { row := q.db.QueryRowContext(ctx, upsertAssetGroupKey, arg.TweakedGroupKey, arg.TapscriptRoot, arg.InternalKeyID, arg.GenesisPointID, ) - var group_id int32 + var group_id int64 err := row.Scan(&group_id) return group_id, err } @@ -2214,13 +2214,13 @@ RETURNING witness_id type UpsertAssetGroupWitnessParams struct { WitnessStack []byte - GenAssetID int32 - GroupKeyID int32 + GenAssetID int64 + GroupKeyID int64 } -func (q *Queries) UpsertAssetGroupWitness(ctx context.Context, arg UpsertAssetGroupWitnessParams) (int32, error) { +func (q *Queries) UpsertAssetGroupWitness(ctx context.Context, arg UpsertAssetGroupWitnessParams) (int64, error) { row := q.db.QueryRowContext(ctx, upsertAssetGroupWitness, arg.WitnessStack, arg.GenAssetID, arg.GroupKeyID) - var witness_id int32 + var witness_id int64 err := row.Scan(&witness_id) return witness_id, err } @@ -2246,9 +2246,9 @@ type UpsertAssetMetaParams struct { MetaDataType sql.NullInt16 } -func (q *Queries) UpsertAssetMeta(ctx context.Context, arg UpsertAssetMetaParams) (int32, error) { +func (q *Queries) UpsertAssetMeta(ctx context.Context, arg UpsertAssetMetaParams) (int64, error) { row := q.db.QueryRowContext(ctx, upsertAssetMeta, arg.MetaDataHash, arg.MetaDataBlob, arg.MetaDataType) - var meta_id int32 + var meta_id int64 err := row.Scan(&meta_id) return meta_id, err } @@ -2280,7 +2280,7 @@ INSERT INTO asset_proofs ( type UpsertAssetProofParams struct { ProofFile []byte TweakedScriptKey []byte - AssetID sql.NullInt32 + AssetID sql.NullInt64 } func (q *Queries) UpsertAssetProof(ctx context.Context, arg UpsertAssetProofParams) error { @@ -2312,7 +2312,7 @@ type UpsertChainTxParams struct { TxIndex sql.NullInt32 } -func (q *Queries) UpsertChainTx(ctx context.Context, arg UpsertChainTxParams) (int32, error) { +func (q *Queries) UpsertChainTx(ctx context.Context, arg UpsertChainTxParams) (int64, error) { row := q.db.QueryRowContext(ctx, upsertChainTx, arg.Txid, arg.RawTx, @@ -2321,7 +2321,7 @@ func (q *Queries) UpsertChainTx(ctx context.Context, arg UpsertChainTxParams) (i arg.BlockHash, arg.TxIndex, ) - var txn_id int32 + var txn_id int64 err := row.Scan(&txn_id) return txn_id, err } @@ -2348,10 +2348,10 @@ type UpsertGenesisAssetParams struct { AssetTag string OutputIndex int32 AssetType int16 - GenesisPointID int32 + GenesisPointID int64 } -func (q *Queries) UpsertGenesisAsset(ctx context.Context, arg UpsertGenesisAssetParams) (int32, error) { +func (q *Queries) UpsertGenesisAsset(ctx context.Context, arg UpsertGenesisAssetParams) (int64, error) { row := q.db.QueryRowContext(ctx, upsertGenesisAsset, arg.MetaDataHash, arg.AssetID, @@ -2360,7 +2360,7 @@ func (q *Queries) UpsertGenesisAsset(ctx context.Context, arg UpsertGenesisAsset arg.AssetType, arg.GenesisPointID, ) - var gen_asset_id int32 + var gen_asset_id int64 err := row.Scan(&gen_asset_id) return gen_asset_id, err } @@ -2376,9 +2376,9 @@ INSERT INTO genesis_points( RETURNING genesis_id ` -func (q *Queries) UpsertGenesisPoint(ctx context.Context, prevOut []byte) (int32, error) { +func (q *Queries) UpsertGenesisPoint(ctx context.Context, prevOut []byte) (int64, error) { row := q.db.QueryRowContext(ctx, upsertGenesisPoint, prevOut) - var genesis_id int32 + var genesis_id int64 err := row.Scan(&genesis_id) return genesis_id, err } @@ -2400,9 +2400,9 @@ type UpsertInternalKeyParams struct { KeyIndex int32 } -func (q *Queries) UpsertInternalKey(ctx context.Context, arg UpsertInternalKeyParams) (int32, error) { +func (q *Queries) UpsertInternalKey(ctx context.Context, arg UpsertInternalKeyParams) (int64, error) { row := q.db.QueryRowContext(ctx, upsertInternalKey, arg.RawKey, arg.KeyFamily, arg.KeyIndex) - var key_id int32 + var key_id int64 err := row.Scan(&key_id) return key_id, err } @@ -2431,11 +2431,11 @@ type UpsertManagedUTXOParams struct { AmtSats int64 TapscriptSibling []byte MerkleRoot []byte - TxnID int32 + TxnID int64 TaprootAssetRoot []byte } -func (q *Queries) UpsertManagedUTXO(ctx context.Context, arg UpsertManagedUTXOParams) (int32, error) { +func (q *Queries) UpsertManagedUTXO(ctx context.Context, arg UpsertManagedUTXOParams) (int64, error) { row := q.db.QueryRowContext(ctx, upsertManagedUTXO, arg.RawKey, arg.Outpoint, @@ -2445,7 +2445,7 @@ func (q *Queries) UpsertManagedUTXO(ctx context.Context, arg UpsertManagedUTXOPa arg.TxnID, arg.TaprootAssetRoot, ) - var utxo_id int32 + var utxo_id int64 err := row.Scan(&utxo_id) return utxo_id, err } @@ -2463,14 +2463,14 @@ RETURNING script_key_id ` type UpsertScriptKeyParams struct { - InternalKeyID int32 + InternalKeyID int64 TweakedScriptKey []byte Tweak []byte } -func (q *Queries) UpsertScriptKey(ctx context.Context, arg UpsertScriptKeyParams) (int32, error) { +func (q *Queries) UpsertScriptKey(ctx context.Context, arg UpsertScriptKeyParams) (int64, error) { row := q.db.QueryRowContext(ctx, upsertScriptKey, arg.InternalKeyID, arg.TweakedScriptKey, arg.Tweak) - var script_key_id int32 + var script_key_id int64 err := row.Scan(&script_key_id) return script_key_id, err } diff --git a/tapdb/sqlc/migrations/000002_assets.up.sql b/tapdb/sqlc/migrations/000002_assets.up.sql index 8ed93d4cf..ac990a07d 100644 --- a/tapdb/sqlc/migrations/000002_assets.up.sql +++ b/tapdb/sqlc/migrations/000002_assets.up.sql @@ -3,7 +3,7 @@ -- information, along with indexing information is stored. -- TODO(roasbeef): also store SPV proof? CREATE TABLE IF NOT EXISTS chain_txns ( - txn_id INTEGER PRIMARY KEY, + txn_id BIGINT PRIMARY KEY, txid BLOB UNIQUE NOT NULL, @@ -23,19 +23,19 @@ CREATE TABLE IF NOT EXISTS chain_txns ( -- outpoint itself, and also a references to the transaction that _spends_ that -- outpoint. CREATE TABLE IF NOT EXISTS genesis_points ( - genesis_id INTEGER PRIMARY KEY, + genesis_id BIGINT PRIMARY KEY, -- TODO(roasbeef): just need the input index here instead? prev_out BLOB UNIQUE NOT NULL, - anchor_tx_id INTEGER REFERENCES chain_txns(txn_id) + anchor_tx_id BIGINT REFERENCES chain_txns(txn_id) ); -- assets_meta is a table that holds all the metadata information for genesis -- assets that we either created, or bootstrapped from the relevant Base -- Universe. CREATE TABLE IF NOT EXISTS assets_meta ( - meta_id INTEGER PRIMARY KEY, + meta_id BIGINT PRIMARY KEY, meta_data_hash BLOB UNIQUE CHECK(length(meta_data_hash) = 32), @@ -50,13 +50,13 @@ CREATE TABLE IF NOT EXISTS assets_meta ( -- reference the genesis point which is also a necessary component for -- computing an asset ID. CREATE TABLE IF NOT EXISTS genesis_assets ( - gen_asset_id INTEGER PRIMARY KEY, + gen_asset_id BIGINT PRIMARY KEY, asset_id BLOB UNIQUE, asset_tag TEXT NOT NULL, - meta_data_id INTEGER REFERENCES assets_meta(meta_id), + meta_data_id BIGINT REFERENCES assets_meta(meta_id), output_index INTEGER NOT NULL, @@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS genesis_assets ( -- BIP PR asset_type SMALLINT NOT NULL, - genesis_point_id INTEGER NOT NULL REFERENCES genesis_points(genesis_id) + genesis_point_id BIGINT NOT NULL REFERENCES genesis_points(genesis_id) ); CREATE INDEX IF NOT EXISTS asset_ids on genesis_assets(asset_id); @@ -72,7 +72,7 @@ CREATE INDEX IF NOT EXISTS asset_ids on genesis_assets(asset_id); -- full KeyLocator is stored so we can use these keys without actually storing -- the private keys on disk. CREATE TABLE IF NOT EXISTS internal_keys ( - key_id INTEGER PRIMARY KEY, + key_id BIGINT PRIMARY KEY, -- We'll always store the full 33-byte key on disk, to make sure we're -- retaining full information. @@ -88,7 +88,7 @@ CREATE TABLE IF NOT EXISTS internal_keys ( -- tweaking the base group key by the associated genesis point. This table -- references the set of internal keys, and also the genesis_points table. CREATE TABLE IF NOT EXISTS asset_groups ( - group_id INTEGER PRIMARY KEY, + group_id BIGINT PRIMARY KEY, tweaked_group_key BLOB UNIQUE NOT NULL CHECK(length(tweaked_group_key) = 33), @@ -96,9 +96,9 @@ CREATE TABLE IF NOT EXISTS asset_groups ( -- TODO(roasbeef): also need to mix in output index here? to derive the -- genesis key? - internal_key_id INTEGER NOT NULL REFERENCES internal_keys(key_id), + internal_key_id BIGINT NOT NULL REFERENCES internal_keys(key_id), - genesis_point_id INTEGER NOT NULL REFERENCES genesis_points(genesis_id) + genesis_point_id BIGINT NOT NULL REFERENCES genesis_points(genesis_id) ); -- asset_group_witnesses stores the set of signatures/witness stacks for an @@ -107,16 +107,16 @@ CREATE TABLE IF NOT EXISTS asset_groups ( -- asset ID must also be included. This table reference the asset ID it's used -- to create as well as the group key that signed the asset in the first place. CREATE TABLE IF NOT EXISTS asset_group_witnesses ( - witness_id INTEGER PRIMARY KEY, + witness_id BIGINT PRIMARY KEY, -- The witness stack can contain either a single Schnorr signature for key -- spends of the tweaked group key, or a more complex script witness. witness_stack BLOB NOT NULL, -- TODO(roasbeef): not needed since already in assets row? - gen_asset_id INTEGER NOT NULL REFERENCES genesis_assets(gen_asset_id) UNIQUE, + gen_asset_id BIGINT NOT NULL REFERENCES genesis_assets(gen_asset_id) UNIQUE, - group_key_id INTEGER NOT NULL REFERENCES asset_groups(group_id) + group_key_id BIGINT NOT NULL REFERENCES asset_groups(group_id) ); -- managed_utxos is the set of UTXOs managed by tapd. These UTXOs may commit @@ -124,7 +124,7 @@ CREATE TABLE IF NOT EXISTS asset_group_witnesses ( -- wallet, so the wallet is able to keep track of the amount of sats that are -- used to anchor Taproot assets. CREATE TABLE IF NOT EXISTS managed_utxos ( - utxo_id INTEGER PRIMARY KEY, + utxo_id BIGINT PRIMARY KEY, outpoint BLOB UNIQUE NOT NULL, @@ -132,7 +132,7 @@ CREATE TABLE IF NOT EXISTS managed_utxos ( -- 64 bit issues? amt_sats BIGINT NOT NULL, - internal_key_id INTEGER NOT NULL REFERENCES internal_keys(key_id), + internal_key_id BIGINT NOT NULL REFERENCES internal_keys(key_id), -- The Taproot Asset root commitment hash. taproot_asset_root BLOB NOT NULL CHECK(length(taproot_asset_root) = 32), @@ -147,7 +147,7 @@ CREATE TABLE IF NOT EXISTS managed_utxos ( -- TODO(roasbeef): can then reconstruct on start up to ensure matches up merkle_root BLOB NOT NULL CHECK(length(merkle_root) = 32), - txn_id INTEGER NOT NULL REFERENCES chain_txns(txn_id), + txn_id BIGINT NOT NULL REFERENCES chain_txns(txn_id), -- The identity of the application that currently has a lease on this UTXO. -- If NULL, then the UTXO is not currently leased. A lease means that the @@ -163,11 +163,11 @@ CREATE TABLE IF NOT EXISTS managed_utxos ( ); CREATE TABLE IF NOT EXISTS script_keys ( - script_key_id INTEGER PRIMARY KEY, + script_key_id BIGINT PRIMARY KEY, -- The actual internal key here that we hold the private key for. Applying -- the tweak to this gives us the tweaked_script_key. - internal_key_id INTEGER NOT NULL REFERENCES internal_keys(key_id), + internal_key_id BIGINT NOT NULL REFERENCES internal_keys(key_id), -- The script key after applying the tweak. This is what goes directly in -- the asset TLV. @@ -184,16 +184,16 @@ CREATE TABLE IF NOT EXISTS script_keys ( -- asset, along with the sibling taproot hash needed to properly reveal and -- spend the asset. CREATE TABLE IF NOT EXISTS assets ( - asset_id INTEGER PRIMARY KEY, + asset_id BIGINT PRIMARY KEY, - genesis_id INTEGER NOT NULL REFERENCES genesis_assets(gen_asset_id), + genesis_id BIGINT NOT NULL REFERENCES genesis_assets(gen_asset_id), version INTEGER NOT NULL, - script_key_id INTEGER NOT NULL REFERENCES script_keys(script_key_id), + script_key_id BIGINT NOT NULL REFERENCES script_keys(script_key_id), -- TODO(roasbeef): don't need this after all? - asset_group_witness_id INTEGER REFERENCES asset_group_witnesses(witness_id), + asset_group_witness_id BIGINT REFERENCES asset_group_witnesses(witness_id), -- TODO(roasbeef): make into enum? script_version INTEGER NOT NULL, @@ -210,7 +210,7 @@ CREATE TABLE IF NOT EXISTS assets ( split_commitment_root_value BIGINT, - anchor_utxo_id INTEGER REFERENCES managed_utxos(utxo_id), + anchor_utxo_id BIGINT REFERENCES managed_utxos(utxo_id), -- A boolean that indicates that the asset was spent. This is only -- set for assets that were transferred in an active manner (as part of an @@ -225,9 +225,9 @@ CREATE TABLE IF NOT EXISTS assets ( -- asset. This then references the script key of an asset, creation a one to -- many relationship. CREATE TABLE IF NOT EXISTS asset_witnesses ( - witness_id INTEGER PRIMARY KEY, + witness_id BIGINT PRIMARY KEY, - asset_id INTEGER NOT NULL REFERENCES assets(asset_id) ON DELETE CASCADE, + asset_id BIGINT NOT NULL REFERENCES assets(asset_id) ON DELETE CASCADE, prev_out_point BLOB NOT NULL, @@ -243,11 +243,11 @@ CREATE TABLE IF NOT EXISTS asset_witnesses ( ); CREATE TABLE IF NOT EXISTS asset_proofs ( - proof_id INTEGER PRIMARY KEY, + proof_id BIGINT PRIMARY KEY, -- We enforce that this value is unique so we can use an UPSERT to update a -- proof file that already exists. - asset_id INTEGER NOT NULL REFERENCES assets(asset_id) UNIQUE, + asset_id BIGINT NOT NULL REFERENCES assets(asset_id) UNIQUE, -- TODO(roasbef): store the merkle root separately? then can refer back to -- for all other files @@ -260,7 +260,7 @@ CREATE TABLE IF NOT EXISTS asset_proofs ( -- minting transaction which once signed and broadcast will actually create the -- assets. CREATE TABLE IF NOT EXISTS asset_minting_batches ( - batch_id INTEGER PRIMARY KEY REFERENCES internal_keys(key_id), + batch_id BIGINT PRIMARY KEY REFERENCES internal_keys(key_id), -- TODO(roasbeef): make into proper enum table or use check to ensure -- proper values @@ -270,7 +270,7 @@ CREATE TABLE IF NOT EXISTS asset_minting_batches ( change_output_index INTEGER, - genesis_id INTEGER REFERENCES genesis_points(genesis_id), + genesis_id BIGINT REFERENCES genesis_points(genesis_id), height_hint INTEGER NOT NULL, @@ -281,7 +281,7 @@ CREATE INDEX IF NOT EXISTS batch_state_lookup on asset_minting_batches (batch_st -- asset_seedlings are budding assets: the contain the base asset information -- need to create an asset, but doesn't yet have a genesis point. CREATE TABLE IF NOT EXISTS asset_seedlings ( - seedling_id INTEGER PRIMARY KEY, + seedling_id BIGINT PRIMARY KEY, -- TODO(roasbeef): data redundant w/ genesis_assets? -- move into asset details table? @@ -291,15 +291,15 @@ CREATE TABLE IF NOT EXISTS asset_seedlings ( asset_supply BIGINT NOT NULL, - asset_meta_id INTEGER NOT NULL REFERENCES assets_meta(meta_id), + asset_meta_id BIGINT NOT NULL REFERENCES assets_meta(meta_id), emission_enabled BOOLEAN NOT NULL, - batch_id INTEGER NOT NULL REFERENCES asset_minting_batches(batch_id), + batch_id BIGINT NOT NULL REFERENCES asset_minting_batches(batch_id), - group_genesis_id INTEGER REFERENCES genesis_assets(gen_asset_id), + group_genesis_id BIGINT REFERENCES genesis_assets(gen_asset_id), - group_anchor_id INTEGER REFERENCES asset_seedlings(seedling_id) + group_anchor_id BIGINT REFERENCES asset_seedlings(seedling_id) ); -- TODO(roasbeef): need on delete cascade for all these? diff --git a/tapdb/sqlc/migrations/000003_addrs.up.sql b/tapdb/sqlc/migrations/000003_addrs.up.sql index 6483c0e96..684ae96a7 100644 --- a/tapdb/sqlc/migrations/000003_addrs.up.sql +++ b/tapdb/sqlc/migrations/000003_addrs.up.sql @@ -2,7 +2,7 @@ -- a creation time and all the information needed to reconstruct the taproot -- output on chain we'll use to send/recv to/from this address. CREATE TABLE IF NOT EXISTS addrs ( - id INTEGER PRIMARY KEY, + id BIGINT PRIMARY KEY, -- version is the version of the Taproot Asset address format. version SMALLINT NOT NULL, @@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS addrs ( -- genesis_asset_id points to the asset genesis of the asset we want to -- send/recv. - genesis_asset_id INTEGER NOT NULL REFERENCES genesis_assets(gen_asset_id), + genesis_asset_id BIGINT NOT NULL REFERENCES genesis_assets(gen_asset_id), -- group_key is the raw blob of the group key. For assets w/o a group key, -- this field will be NULL. @@ -20,11 +20,11 @@ CREATE TABLE IF NOT EXISTS addrs ( -- script_key_id points to the internal key that we created to serve as the -- script key to be able to receive this asset. - script_key_id INTEGER NOT NULL REFERENCES script_keys(script_key_id), + script_key_id BIGINT NOT NULL REFERENCES script_keys(script_key_id), -- taproot_key_id points to the internal key that we'll use to serve as the -- taproot internal key to receive this asset. - taproot_key_id INTEGER NOT NULL REFERENCES internal_keys(key_id), + taproot_key_id BIGINT NOT NULL REFERENCES internal_keys(key_id), -- tapscript_sibling is the serialized tapscript sibling preimage that -- should be committed to in the taproot output alongside the Taproot Asset diff --git a/tapdb/sqlc/migrations/000005_transfers.up.sql b/tapdb/sqlc/migrations/000005_transfers.up.sql index b5148a288..7b0b523ac 100644 --- a/tapdb/sqlc/migrations/000005_transfers.up.sql +++ b/tapdb/sqlc/migrations/000005_transfers.up.sql @@ -1,9 +1,9 @@ CREATE TABLE IF NOT EXISTS asset_transfers ( - id INTEGER PRIMARY KEY, + id BIGINT PRIMARY KEY, height_hint INTEGER NOT NULL, - anchor_txn_id INTEGER NOT NULL REFERENCES chain_txns(txn_id), + anchor_txn_id BIGINT NOT NULL REFERENCES chain_txns(txn_id), transfer_time_unix TIMESTAMP NOT NULL ); @@ -13,9 +13,9 @@ CREATE INDEX IF NOT EXISTS transfer_txn_idx ON asset_transfers (anchor_txn_id); CREATE TABLE IF NOT EXISTS asset_transfer_inputs ( - input_id INTEGER PRIMARY KEY, + input_id BIGINT PRIMARY KEY, - transfer_id INTEGER NOT NULL REFERENCES asset_transfers(id), + transfer_id BIGINT NOT NULL REFERENCES asset_transfers(id), anchor_point BLOB NOT NULL, @@ -29,13 +29,13 @@ CREATE INDEX IF NOT EXISTS transfer_inputs_idx ON asset_transfer_inputs (transfer_id); CREATE TABLE IF NOT EXISTS asset_transfer_outputs ( - output_id INTEGER PRIMARY KEY, + output_id BIGINT PRIMARY KEY, - transfer_id INTEGER NOT NULL REFERENCES asset_transfers(id), + transfer_id BIGINT NOT NULL REFERENCES asset_transfers(id), - anchor_utxo INTEGER NOT NULL REFERENCES managed_utxos(utxo_id), + anchor_utxo BIGINT NOT NULL REFERENCES managed_utxos(utxo_id), - script_key INTEGER NOT NULL REFERENCES script_keys(script_key_id), + script_key BIGINT NOT NULL REFERENCES script_keys(script_key_id), script_key_local BOOL NOT NULL, @@ -72,13 +72,13 @@ CREATE INDEX IF NOT EXISTS proof_locator_hash_index -- passive_assets is a table that stores the information needed to -- re-anchor a passive asset. CREATE TABLE IF NOT EXISTS passive_assets ( - passive_id INTEGER PRIMARY KEY, + passive_id BIGINT PRIMARY KEY, - transfer_id INTEGER NOT NULL REFERENCES asset_transfers(id), + transfer_id BIGINT NOT NULL REFERENCES asset_transfers(id), - asset_id INTEGER NOT NULL REFERENCES assets(asset_id), + asset_id BIGINT NOT NULL REFERENCES assets(asset_id), - new_anchor_utxo INTEGER NOT NULL REFERENCES managed_utxos(utxo_id), + new_anchor_utxo BIGINT NOT NULL REFERENCES managed_utxos(utxo_id), script_key BLOB NOT NULL, diff --git a/tapdb/sqlc/migrations/000006_addr_event.up.sql b/tapdb/sqlc/migrations/000006_addr_event.up.sql index 3e3428d35..6f6b0adf8 100644 --- a/tapdb/sqlc/migrations/000006_addr_event.up.sql +++ b/tapdb/sqlc/migrations/000006_addr_event.up.sql @@ -1,20 +1,20 @@ -- addr_events stores all events related to inbound (received) assets for -- addresses. CREATE TABLE IF NOT EXISTS addr_events ( - id INTEGER PRIMARY KEY, + id BIGINT PRIMARY KEY, -- creation_time is the creation time of this event. creation_time TIMESTAMP NOT NULL, -- addr_id is the reference to the address this event was emitted for. - addr_id INTEGER NOT NULL REFERENCES addrs(id), + addr_id BIGINT NOT NULL REFERENCES addrs(id), -- status is the status of the inbound asset. status SMALLINT NOT NULL CHECK (status IN (0, 1, 2, 3)), -- chain_txn_id is a reference to the chain transaction that has the Taproot -- output for this event. - chain_txn_id INTEGER NOT NULL REFERENCES chain_txns(txn_id), + chain_txn_id BIGINT NOT NULL REFERENCES chain_txns(txn_id), -- chain_txn_output_index is the index of the on-chain output (of the -- transaction referenced by chain_txn_id) that houses the Taproot Asset @@ -23,16 +23,16 @@ CREATE TABLE IF NOT EXISTS addr_events ( -- managed_utxo_id is a reference to the managed UTXO the internal wallet -- tracks with on-chain funds that belong to us. - managed_utxo_id INTEGER NOT NULL REFERENCES managed_utxos(utxo_id), + managed_utxo_id BIGINT NOT NULL REFERENCES managed_utxos(utxo_id), -- asset_proof_id is a reference to the proof associated with this asset -- event. - asset_proof_id INTEGER REFERENCES asset_proofs(proof_id), + asset_proof_id BIGINT REFERENCES asset_proofs(proof_id), -- asset_id is a reference to the asset once we have taken custody of it. -- This will only be set once the proofs were imported successfully and the -- event is in the status complete. - asset_id INTEGER REFERENCES assets(asset_id), + asset_id BIGINT REFERENCES assets(asset_id), UNIQUE(addr_id, chain_txn_id, chain_txn_output_index) ); diff --git a/tapdb/sqlc/migrations/000007_universe.up.sql b/tapdb/sqlc/migrations/000007_universe.up.sql index 8ed70ec26..2cbaddd16 100644 --- a/tapdb/sqlc/migrations/000007_universe.up.sql +++ b/tapdb/sqlc/migrations/000007_universe.up.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS universe_roots ( - id INTEGER PRIMARY KEY, + id BIGINT PRIMARY KEY, -- For the namespace root, we set the foreign key constraint evaluation to -- be deferred until after the database transaction ends. Otherwise, if the @@ -19,15 +19,15 @@ CREATE INDEX IF NOT EXISTS universe_roots_asset_id_idx ON universe_roots(asset_i CREATE INDEX IF NOT EXISTS universe_roots_group_key_idx ON universe_roots(group_key); CREATE TABLE IF NOT EXISTS universe_leaves ( - id INTEGER PRIMARY KEY, + id BIGINT PRIMARY KEY, - asset_genesis_id INTEGER NOT NULL REFERENCES genesis_assets(gen_asset_id), + asset_genesis_id BIGINT NOT NULL REFERENCES genesis_assets(gen_asset_id), minting_point BLOB NOT NULL, script_key_bytes BLOB NOT NULL CHECK(LENGTH(script_key_bytes) = 32), - universe_root_id INTEGER NOT NULL REFERENCES universe_roots(id), + universe_root_id BIGINT NOT NULL REFERENCES universe_roots(id), leaf_node_key BLOB, @@ -40,7 +40,7 @@ CREATE INDEX IF NOT EXISTS universe_leaves_key_idx ON universe_leaves(leaf_node_ CREATE INDEX IF NOT EXISTS universe_leaves_namespace ON universe_leaves(leaf_node_namespace); CREATE TABLE IF NOT EXISTS universe_servers ( - id INTEGER PRIMARY KEY, + id BIGINT PRIMARY KEY, server_host TEXT UNIQUE NOT NULL, @@ -55,11 +55,11 @@ CREATE TABLE IF NOT EXISTS universe_servers ( CREATE INDEX IF NOT EXISTS universe_servers_host ON universe_servers(server_host); CREATE TABLE IF NOT EXISTS universe_events ( - event_id INTEGER PRIMARY KEY, + event_id BIGINT PRIMARY KEY, event_type VARCHAR NOT NULL CHECK (event_type IN ('SYNC', 'NEW_PROOF', 'NEW_ROOT')), - universe_root_id INTEGER NOT NULL REFERENCES universe_roots(id), + universe_root_id BIGINT NOT NULL REFERENCES universe_roots(id), -- TODO(roasbeef): also add which leaf was synced? diff --git a/tapdb/sqlc/models.go b/tapdb/sqlc/models.go index ab8b91a2b..fbf2febb3 100644 --- a/tapdb/sqlc/models.go +++ b/tapdb/sqlc/models.go @@ -10,13 +10,13 @@ import ( ) type Addr struct { - ID int32 + ID int64 Version int16 AssetVersion int16 - GenesisAssetID int32 + GenesisAssetID int64 GroupKey []byte - ScriptKeyID int32 - TaprootKeyID int32 + ScriptKeyID int64 + TaprootKeyID int64 TapscriptSibling []byte TaprootOutputKey []byte Amount int64 @@ -27,86 +27,86 @@ type Addr struct { } type AddrEvent struct { - ID int32 + ID int64 CreationTime time.Time - AddrID int32 + AddrID int64 Status int16 - ChainTxnID int32 + ChainTxnID int64 ChainTxnOutputIndex int32 - ManagedUtxoID int32 - AssetProofID sql.NullInt32 - AssetID sql.NullInt32 + ManagedUtxoID int64 + AssetProofID sql.NullInt64 + AssetID sql.NullInt64 } type Asset struct { - AssetID int32 - GenesisID int32 + AssetID int64 + GenesisID int64 Version int32 - ScriptKeyID int32 - AssetGroupWitnessID sql.NullInt32 + ScriptKeyID int64 + AssetGroupWitnessID sql.NullInt64 ScriptVersion int32 Amount int64 LockTime sql.NullInt32 RelativeLockTime sql.NullInt32 SplitCommitmentRootHash []byte SplitCommitmentRootValue sql.NullInt64 - AnchorUtxoID sql.NullInt32 + AnchorUtxoID sql.NullInt64 Spent bool } type AssetGroup struct { - GroupID int32 + GroupID int64 TweakedGroupKey []byte TapscriptRoot []byte - InternalKeyID int32 - GenesisPointID int32 + InternalKeyID int64 + GenesisPointID int64 } type AssetGroupWitness struct { - WitnessID int32 + WitnessID int64 WitnessStack []byte - GenAssetID int32 - GroupKeyID int32 + GenAssetID int64 + GroupKeyID int64 } type AssetMintingBatch struct { - BatchID int32 + BatchID int64 BatchState int16 MintingTxPsbt []byte ChangeOutputIndex sql.NullInt32 - GenesisID sql.NullInt32 + GenesisID sql.NullInt64 HeightHint int32 CreationTimeUnix time.Time } type AssetProof struct { - ProofID int32 - AssetID int32 + ProofID int64 + AssetID int64 ProofFile []byte } type AssetSeedling struct { - SeedlingID int32 + SeedlingID int64 AssetName string AssetType int16 AssetSupply int64 - AssetMetaID int32 + AssetMetaID int64 EmissionEnabled bool - BatchID int32 - GroupGenesisID sql.NullInt32 - GroupAnchorID sql.NullInt32 + BatchID int64 + GroupGenesisID sql.NullInt64 + GroupAnchorID sql.NullInt64 } type AssetTransfer struct { - ID int32 + ID int64 HeightHint int32 - AnchorTxnID int32 + AnchorTxnID int64 TransferTimeUnix time.Time } type AssetTransferInput struct { - InputID int32 - TransferID int32 + InputID int64 + TransferID int64 AnchorPoint []byte AssetID []byte ScriptKey []byte @@ -114,10 +114,10 @@ type AssetTransferInput struct { } type AssetTransferOutput struct { - OutputID int32 - TransferID int32 - AnchorUtxo int32 - ScriptKey int32 + OutputID int64 + TransferID int64 + AnchorUtxo int64 + ScriptKey int64 ScriptKeyLocal bool Amount int64 SerializedWitnesses []byte @@ -130,8 +130,8 @@ type AssetTransferOutput struct { } type AssetWitness struct { - WitnessID int32 - AssetID int32 + WitnessID int64 + AssetID int64 PrevOutPoint []byte PrevAssetID []byte PrevScriptKey []byte @@ -140,14 +140,14 @@ type AssetWitness struct { } type AssetsMetum struct { - MetaID int32 + MetaID int64 MetaDataHash []byte MetaDataBlob []byte MetaDataType sql.NullInt16 } type ChainTxn struct { - TxnID int32 + TxnID int64 Txid []byte ChainFees int64 RawTx []byte @@ -157,17 +157,17 @@ type ChainTxn struct { } type GenesisAsset struct { - GenAssetID int32 + GenAssetID int64 AssetID []byte AssetTag string - MetaDataID sql.NullInt32 + MetaDataID sql.NullInt64 OutputIndex int32 AssetType int16 - GenesisPointID int32 + GenesisPointID int64 } type GenesisInfoView struct { - GenAssetID int32 + GenAssetID int64 AssetID []byte AssetTag string MetaHash []byte @@ -178,21 +178,21 @@ type GenesisInfoView struct { } type GenesisPoint struct { - GenesisID int32 + GenesisID int64 PrevOut []byte - AnchorTxID sql.NullInt32 + AnchorTxID sql.NullInt64 } type InternalKey struct { - KeyID int32 + KeyID int64 RawKey []byte KeyFamily int32 KeyIndex int32 } type KeyGroupInfoView struct { - WitnessID int32 - GenAssetID int32 + WitnessID int64 + GenAssetID int64 WitnessStack []byte TapscriptRoot []byte TweakedGroupKey []byte @@ -207,14 +207,14 @@ type Macaroon struct { } type ManagedUtxo struct { - UtxoID int32 + UtxoID int64 Outpoint []byte AmtSats int64 - InternalKeyID int32 + InternalKeyID int64 TaprootAssetRoot []byte TapscriptSibling []byte MerkleRoot []byte - TxnID int32 + TxnID int64 LeaseOwner []byte LeaseExpiry sql.NullTime } @@ -235,10 +235,10 @@ type MssmtRoot struct { } type PassiveAsset struct { - PassiveID int32 - TransferID int32 - AssetID int32 - NewAnchorUtxo int32 + PassiveID int64 + TransferID int64 + AssetID int64 + NewAnchorUtxo int64 ScriptKey []byte NewWitnessStack []byte NewProof []byte @@ -250,39 +250,39 @@ type ReceiverProofTransferAttempt struct { } type ScriptKey struct { - ScriptKeyID int32 - InternalKeyID int32 + ScriptKeyID int64 + InternalKeyID int64 TweakedScriptKey []byte Tweak []byte } type UniverseEvent struct { - EventID int32 + EventID int64 EventType string - UniverseRootID int32 + UniverseRootID int64 EventTime time.Time EventTimestamp int64 } type UniverseLeafe struct { - ID int32 - AssetGenesisID int32 + ID int64 + AssetGenesisID int64 MintingPoint []byte ScriptKeyBytes []byte - UniverseRootID int32 + UniverseRootID int64 LeafNodeKey []byte LeafNodeNamespace string } type UniverseRoot struct { - ID int32 + ID int64 NamespaceRoot string AssetID []byte GroupKey []byte } type UniverseServer struct { - ID int32 + ID int64 ServerHost string LastSyncTime time.Time } diff --git a/tapdb/sqlc/querier.go b/tapdb/sqlc/querier.go index f19f684f0..f2793b016 100644 --- a/tapdb/sqlc/querier.go +++ b/tapdb/sqlc/querier.go @@ -16,14 +16,14 @@ type Querier interface { AllMintingBatches(ctx context.Context) ([]AllMintingBatchesRow, error) AnchorGenesisPoint(ctx context.Context, arg AnchorGenesisPointParams) error AnchorPendingAssets(ctx context.Context, arg AnchorPendingAssetsParams) error - ApplyPendingOutput(ctx context.Context, arg ApplyPendingOutputParams) (int32, error) + ApplyPendingOutput(ctx context.Context, arg ApplyPendingOutputParams) (int64, error) AssetsByGenesisPoint(ctx context.Context, prevOut []byte) ([]AssetsByGenesisPointRow, error) AssetsInBatch(ctx context.Context, rawKey []byte) ([]AssetsInBatchRow, error) BindMintingBatchWithTx(ctx context.Context, arg BindMintingBatchWithTxParams) error ConfirmChainAnchorTx(ctx context.Context, arg ConfirmChainAnchorTxParams) error ConfirmChainTx(ctx context.Context, arg ConfirmChainTxParams) error DeleteAllNodes(ctx context.Context, namespace string) (int64, error) - DeleteAssetWitnesses(ctx context.Context, assetID int32) error + DeleteAssetWitnesses(ctx context.Context, assetID int64) error DeleteExpiredUTXOLeases(ctx context.Context, now sql.NullTime) error DeleteManagedUTXO(ctx context.Context, outpoint []byte) error DeleteNode(ctx context.Context, arg DeleteNodeParams) (int64, error) @@ -34,17 +34,17 @@ type Querier interface { DeleteUniverseRoot(ctx context.Context, namespaceRoot string) error DeleteUniverseServer(ctx context.Context, arg DeleteUniverseServerParams) error FetchAddrByTaprootOutputKey(ctx context.Context, taprootOutputKey []byte) (FetchAddrByTaprootOutputKeyRow, error) - FetchAddrEvent(ctx context.Context, id int32) (FetchAddrEventRow, error) + FetchAddrEvent(ctx context.Context, id int64) (FetchAddrEventRow, error) FetchAddrs(ctx context.Context, arg FetchAddrsParams) ([]FetchAddrsRow, error) FetchAllNodes(ctx context.Context) ([]MssmtNode, error) - FetchAssetMeta(ctx context.Context, metaID int32) (FetchAssetMetaRow, error) + FetchAssetMeta(ctx context.Context, metaID int64) (FetchAssetMetaRow, error) FetchAssetMetaByHash(ctx context.Context, metaDataHash []byte) (FetchAssetMetaByHashRow, error) FetchAssetMetaForAsset(ctx context.Context, assetID []byte) (FetchAssetMetaForAssetRow, error) FetchAssetProof(ctx context.Context, tweakedScriptKey []byte) (FetchAssetProofRow, error) FetchAssetProofs(ctx context.Context) ([]FetchAssetProofsRow, error) FetchAssetProofsByAssetID(ctx context.Context, assetID []byte) ([]FetchAssetProofsByAssetIDRow, error) - FetchAssetWitnesses(ctx context.Context, assetID sql.NullInt32) ([]FetchAssetWitnessesRow, error) - FetchAssetsByAnchorTx(ctx context.Context, anchorUtxoID sql.NullInt32) ([]Asset, error) + FetchAssetWitnesses(ctx context.Context, assetID sql.NullInt64) ([]FetchAssetWitnessesRow, error) + FetchAssetsByAnchorTx(ctx context.Context, anchorUtxoID sql.NullInt64) ([]Asset, error) // We use a LEFT JOIN here as not every asset has a group key, so this'll // generate rows that have NULL values for the faily key fields if an asset // doesn't have a group key. See the comment in fetchAssetSprouts for a work @@ -54,10 +54,10 @@ type Querier interface { FetchChildren(ctx context.Context, arg FetchChildrenParams) ([]FetchChildrenRow, error) FetchChildrenSelfJoin(ctx context.Context, arg FetchChildrenSelfJoinParams) ([]FetchChildrenSelfJoinRow, error) FetchGenesisByAssetID(ctx context.Context, assetID []byte) (GenesisInfoView, error) - FetchGenesisByID(ctx context.Context, genAssetID int32) (FetchGenesisByIDRow, error) - FetchGenesisID(ctx context.Context, arg FetchGenesisIDParams) (int32, error) - FetchGenesisPointByAnchorTx(ctx context.Context, anchorTxID sql.NullInt32) (GenesisPoint, error) - FetchGroupByGenesis(ctx context.Context, genesisID int32) (FetchGroupByGenesisRow, error) + FetchGenesisByID(ctx context.Context, genAssetID int64) (FetchGenesisByIDRow, error) + FetchGenesisID(ctx context.Context, arg FetchGenesisIDParams) (int64, error) + FetchGenesisPointByAnchorTx(ctx context.Context, anchorTxID sql.NullInt64) (GenesisPoint, error) + FetchGroupByGenesis(ctx context.Context, genesisID int64) (FetchGroupByGenesisRow, error) // Sort and limit to return the genesis ID for initial genesis of the group. FetchGroupByGroupKey(ctx context.Context, groupKey []byte) (FetchGroupByGroupKeyRow, error) FetchGroupedAssets(ctx context.Context) ([]FetchGroupedAssetsRow, error) @@ -67,28 +67,28 @@ type Querier interface { FetchMintingBatchesByInverseState(ctx context.Context, batchState int16) ([]FetchMintingBatchesByInverseStateRow, error) FetchRootNode(ctx context.Context, namespace string) (MssmtNode, error) FetchScriptKeyByTweakedKey(ctx context.Context, tweakedScriptKey []byte) (FetchScriptKeyByTweakedKeyRow, error) - FetchScriptKeyIDByTweakedKey(ctx context.Context, tweakedScriptKey []byte) (int32, error) - FetchSeedlingByID(ctx context.Context, seedlingID int32) (AssetSeedling, error) - FetchSeedlingID(ctx context.Context, arg FetchSeedlingIDParams) (int32, error) + FetchScriptKeyIDByTweakedKey(ctx context.Context, tweakedScriptKey []byte) (int64, error) + FetchSeedlingByID(ctx context.Context, seedlingID int64) (AssetSeedling, error) + FetchSeedlingID(ctx context.Context, arg FetchSeedlingIDParams) (int64, error) FetchSeedlingsForBatch(ctx context.Context, rawKey []byte) ([]FetchSeedlingsForBatchRow, error) - FetchTransferInputs(ctx context.Context, transferID int32) ([]FetchTransferInputsRow, error) - FetchTransferOutputs(ctx context.Context, transferID int32) ([]FetchTransferOutputsRow, error) + FetchTransferInputs(ctx context.Context, transferID int64) ([]FetchTransferInputsRow, error) + FetchTransferOutputs(ctx context.Context, transferID int64) ([]FetchTransferOutputsRow, error) FetchUniverseKeys(ctx context.Context, namespace string) ([]FetchUniverseKeysRow, error) FetchUniverseRoot(ctx context.Context, namespace string) (FetchUniverseRootRow, error) GenesisAssets(ctx context.Context) ([]GenesisAsset, error) GenesisPoints(ctx context.Context) ([]GenesisPoint, error) GetRootKey(ctx context.Context, id []byte) (Macaroon, error) - InsertAddr(ctx context.Context, arg InsertAddrParams) (int32, error) + InsertAddr(ctx context.Context, arg InsertAddrParams) (int64, error) InsertAssetSeedling(ctx context.Context, arg InsertAssetSeedlingParams) error InsertAssetSeedlingIntoBatch(ctx context.Context, arg InsertAssetSeedlingIntoBatchParams) error - InsertAssetTransfer(ctx context.Context, arg InsertAssetTransferParams) (int32, error) + InsertAssetTransfer(ctx context.Context, arg InsertAssetTransferParams) (int64, error) InsertAssetTransferInput(ctx context.Context, arg InsertAssetTransferInputParams) error InsertAssetTransferOutput(ctx context.Context, arg InsertAssetTransferOutputParams) error InsertAssetWitness(ctx context.Context, arg InsertAssetWitnessParams) error InsertBranch(ctx context.Context, arg InsertBranchParams) error InsertCompactedLeaf(ctx context.Context, arg InsertCompactedLeafParams) error InsertLeaf(ctx context.Context, arg InsertLeafParams) error - InsertNewAsset(ctx context.Context, arg InsertNewAssetParams) (int32, error) + InsertNewAsset(ctx context.Context, arg InsertNewAssetParams) (int64, error) InsertNewProofEvent(ctx context.Context, arg InsertNewProofEventParams) error InsertNewSyncEvent(ctx context.Context, arg InsertNewSyncEventParams) error InsertPassiveAsset(ctx context.Context, arg InsertPassiveAssetParams) error @@ -121,7 +121,7 @@ type Querier interface { // specified. QueryAssets(ctx context.Context, arg QueryAssetsParams) ([]QueryAssetsRow, error) QueryEventIDs(ctx context.Context, arg QueryEventIDsParams) ([]QueryEventIDsRow, error) - QueryPassiveAssets(ctx context.Context, transferID int32) ([]QueryPassiveAssetsRow, error) + QueryPassiveAssets(ctx context.Context, transferID int64) ([]QueryPassiveAssetsRow, error) QueryReceiverProofTransferAttempt(ctx context.Context, proofLocatorHash []byte) ([]time.Time, error) // TODO(roasbeef): use the universe id instead for the grouping? so namespace // root, simplifies queries @@ -130,26 +130,26 @@ type Querier interface { QueryUniverseStats(ctx context.Context) (QueryUniverseStatsRow, error) ReAnchorPassiveAssets(ctx context.Context, arg ReAnchorPassiveAssetsParams) error SetAddrManaged(ctx context.Context, arg SetAddrManagedParams) error - SetAssetSpent(ctx context.Context, arg SetAssetSpentParams) (int32, error) + SetAssetSpent(ctx context.Context, arg SetAssetSpentParams) (int64, error) UniverseLeaves(ctx context.Context) ([]UniverseLeafe, error) UniverseRoots(ctx context.Context) ([]UniverseRootsRow, error) UpdateBatchGenesisTx(ctx context.Context, arg UpdateBatchGenesisTxParams) error UpdateMintingBatchState(ctx context.Context, arg UpdateMintingBatchStateParams) error UpdateUTXOLease(ctx context.Context, arg UpdateUTXOLeaseParams) error - UpsertAddrEvent(ctx context.Context, arg UpsertAddrEventParams) (int32, error) - UpsertAssetGroupKey(ctx context.Context, arg UpsertAssetGroupKeyParams) (int32, error) - UpsertAssetGroupWitness(ctx context.Context, arg UpsertAssetGroupWitnessParams) (int32, error) - UpsertAssetMeta(ctx context.Context, arg UpsertAssetMetaParams) (int32, error) + UpsertAddrEvent(ctx context.Context, arg UpsertAddrEventParams) (int64, error) + UpsertAssetGroupKey(ctx context.Context, arg UpsertAssetGroupKeyParams) (int64, error) + UpsertAssetGroupWitness(ctx context.Context, arg UpsertAssetGroupWitnessParams) (int64, error) + UpsertAssetMeta(ctx context.Context, arg UpsertAssetMetaParams) (int64, error) UpsertAssetProof(ctx context.Context, arg UpsertAssetProofParams) error - UpsertChainTx(ctx context.Context, arg UpsertChainTxParams) (int32, error) - UpsertGenesisAsset(ctx context.Context, arg UpsertGenesisAssetParams) (int32, error) - UpsertGenesisPoint(ctx context.Context, prevOut []byte) (int32, error) - UpsertInternalKey(ctx context.Context, arg UpsertInternalKeyParams) (int32, error) - UpsertManagedUTXO(ctx context.Context, arg UpsertManagedUTXOParams) (int32, error) + UpsertChainTx(ctx context.Context, arg UpsertChainTxParams) (int64, error) + UpsertGenesisAsset(ctx context.Context, arg UpsertGenesisAssetParams) (int64, error) + UpsertGenesisPoint(ctx context.Context, prevOut []byte) (int64, error) + UpsertInternalKey(ctx context.Context, arg UpsertInternalKeyParams) (int64, error) + UpsertManagedUTXO(ctx context.Context, arg UpsertManagedUTXOParams) (int64, error) UpsertRootNode(ctx context.Context, arg UpsertRootNodeParams) error - UpsertScriptKey(ctx context.Context, arg UpsertScriptKeyParams) (int32, error) + UpsertScriptKey(ctx context.Context, arg UpsertScriptKeyParams) (int64, error) UpsertUniverseLeaf(ctx context.Context, arg UpsertUniverseLeafParams) error - UpsertUniverseRoot(ctx context.Context, arg UpsertUniverseRootParams) (int32, error) + UpsertUniverseRoot(ctx context.Context, arg UpsertUniverseRootParams) (int64, error) } var _ Querier = (*Queries)(nil) diff --git a/tapdb/sqlc/transfers.sql.go b/tapdb/sqlc/transfers.sql.go index 9c89c4415..bb6e62623 100644 --- a/tapdb/sqlc/transfers.sql.go +++ b/tapdb/sqlc/transfers.sql.go @@ -36,16 +36,16 @@ RETURNING asset_id ` type ApplyPendingOutputParams struct { - ScriptKeyID int32 - AnchorUtxoID sql.NullInt32 + ScriptKeyID int64 + AnchorUtxoID sql.NullInt64 Amount int64 SplitCommitmentRootHash []byte SplitCommitmentRootValue sql.NullInt64 Spent bool - SpentAssetID int32 + SpentAssetID int64 } -func (q *Queries) ApplyPendingOutput(ctx context.Context, arg ApplyPendingOutputParams) (int32, error) { +func (q *Queries) ApplyPendingOutput(ctx context.Context, arg ApplyPendingOutputParams) (int64, error) { row := q.db.QueryRowContext(ctx, applyPendingOutput, arg.ScriptKeyID, arg.AnchorUtxoID, @@ -55,7 +55,7 @@ func (q *Queries) ApplyPendingOutput(ctx context.Context, arg ApplyPendingOutput arg.Spent, arg.SpentAssetID, ) - var asset_id int32 + var asset_id int64 err := row.Scan(&asset_id) return asset_id, err } @@ -65,7 +65,7 @@ DELETE FROM asset_witnesses WHERE asset_id = $1 ` -func (q *Queries) DeleteAssetWitnesses(ctx context.Context, assetID int32) error { +func (q *Queries) DeleteAssetWitnesses(ctx context.Context, assetID int64) error { _, err := q.db.ExecContext(ctx, deleteAssetWitnesses, assetID) return err } @@ -78,14 +78,14 @@ ORDER BY input_id ` type FetchTransferInputsRow struct { - InputID int32 + InputID int64 AnchorPoint []byte AssetID []byte ScriptKey []byte Amount int64 } -func (q *Queries) FetchTransferInputs(ctx context.Context, transferID int32) ([]FetchTransferInputsRow, error) { +func (q *Queries) FetchTransferInputs(ctx context.Context, transferID int64) ([]FetchTransferInputsRow, error) { rows, err := q.db.QueryContext(ctx, fetchTransferInputs, transferID) if err != nil { return nil, err @@ -148,7 +148,7 @@ ORDER BY output_id ` type FetchTransferOutputsRow struct { - OutputID int32 + OutputID int64 ProofSuffix []byte Amount int64 SerializedWitnesses []byte @@ -158,7 +158,7 @@ type FetchTransferOutputsRow struct { NumPassiveAssets int32 OutputType int16 ProofCourierAddr []byte - AnchorUtxoID int32 + AnchorUtxoID int64 AnchorOutpoint []byte AnchorValue int64 AnchorMerkleRoot []byte @@ -169,13 +169,13 @@ type FetchTransferOutputsRow struct { InternalKeyIndex int32 ScriptKeyBytes []byte ScriptKeyTweak []byte - ScriptKeyID int32 + ScriptKeyID int64 ScriptKeyRawKeyBytes []byte ScriptKeyFamily int32 ScriptKeyIndex int32 } -func (q *Queries) FetchTransferOutputs(ctx context.Context, transferID int32) ([]FetchTransferOutputsRow, error) { +func (q *Queries) FetchTransferOutputs(ctx context.Context, transferID int64) ([]FetchTransferOutputsRow, error) { rows, err := q.db.QueryContext(ctx, fetchTransferOutputs, transferID) if err != nil { return nil, err @@ -243,9 +243,9 @@ type InsertAssetTransferParams struct { AnchorTxid []byte } -func (q *Queries) InsertAssetTransfer(ctx context.Context, arg InsertAssetTransferParams) (int32, error) { +func (q *Queries) InsertAssetTransfer(ctx context.Context, arg InsertAssetTransferParams) (int64, error) { row := q.db.QueryRowContext(ctx, insertAssetTransfer, arg.HeightHint, arg.TransferTimeUnix, arg.AnchorTxid) - var id int32 + var id int64 err := row.Scan(&id) return id, err } @@ -259,7 +259,7 @@ INSERT INTO asset_transfer_inputs ( ` type InsertAssetTransferInputParams struct { - TransferID int32 + TransferID int64 AnchorPoint []byte AssetID []byte ScriptKey []byte @@ -289,9 +289,9 @@ INSERT INTO asset_transfer_outputs ( ` type InsertAssetTransferOutputParams struct { - TransferID int32 - AnchorUtxo int32 - ScriptKey int32 + TransferID int64 + AnchorUtxo int64 + ScriptKey int64 ScriptKeyLocal bool Amount int64 SerializedWitnesses []byte @@ -345,8 +345,8 @@ INSERT INTO passive_assets ( ` type InsertPassiveAssetParams struct { - TransferID int32 - NewAnchorUtxo int32 + TransferID int64 + NewAnchorUtxo int64 ScriptKey []byte NewWitnessStack []byte NewProof []byte @@ -405,7 +405,7 @@ type QueryAssetTransfersParams struct { } type QueryAssetTransfersRow struct { - ID int32 + ID int64 HeightHint int32 Txid []byte TransferTimeUnix time.Time @@ -456,15 +456,15 @@ WHERE passive.transfer_id = $1 ` type QueryPassiveAssetsRow struct { - AssetID int32 - NewAnchorUtxo int32 + AssetID int64 + NewAnchorUtxo int64 ScriptKey []byte NewWitnessStack []byte NewProof []byte GenesisID []byte } -func (q *Queries) QueryPassiveAssets(ctx context.Context, transferID int32) ([]QueryPassiveAssetsRow, error) { +func (q *Queries) QueryPassiveAssets(ctx context.Context, transferID int64) ([]QueryPassiveAssetsRow, error) { rows, err := q.db.QueryContext(ctx, queryPassiveAssets, transferID) if err != nil { return nil, err @@ -531,8 +531,8 @@ WHERE asset_id = $2 ` type ReAnchorPassiveAssetsParams struct { - NewAnchorUtxoID sql.NullInt32 - AssetID int32 + NewAnchorUtxoID sql.NullInt64 + AssetID int64 } func (q *Queries) ReAnchorPassiveAssets(ctx context.Context, arg ReAnchorPassiveAssetsParams) error { diff --git a/tapdb/sqlc/universe.sql.go b/tapdb/sqlc/universe.sql.go index 8fc3d3dc4..7d3997cc2 100644 --- a/tapdb/sqlc/universe.sql.go +++ b/tapdb/sqlc/universe.sql.go @@ -53,7 +53,7 @@ WHERE server_host = $1 OR id = $2 type DeleteUniverseServerParams struct { TargetServer string - TargetID int32 + TargetID int64 } func (q *Queries) DeleteUniverseServer(ctx context.Context, arg DeleteUniverseServerParams) error { @@ -530,7 +530,7 @@ type QueryUniverseLeavesParams struct { type QueryUniverseLeavesRow struct { ScriptKeyBytes []byte - GenAssetID int32 + GenAssetID int64 GenesisProof []byte SumAmt int64 AssetID []byte @@ -689,9 +689,9 @@ INSERT INTO universe_leaves ( ` type UpsertUniverseLeafParams struct { - AssetGenesisID int32 + AssetGenesisID int64 ScriptKeyBytes []byte - UniverseRootID int32 + UniverseRootID int64 LeafNodeKey []byte LeafNodeNamespace string MintingPoint []byte @@ -727,9 +727,9 @@ type UpsertUniverseRootParams struct { GroupKey []byte } -func (q *Queries) UpsertUniverseRoot(ctx context.Context, arg UpsertUniverseRootParams) (int32, error) { +func (q *Queries) UpsertUniverseRoot(ctx context.Context, arg UpsertUniverseRootParams) (int64, error) { row := q.db.QueryRowContext(ctx, upsertUniverseRoot, arg.NamespaceRoot, arg.AssetID, arg.GroupKey) - var id int32 + var id int64 err := row.Scan(&id) return id, err } diff --git a/tapdb/sqlite.go b/tapdb/sqlite.go index f7e2a6179..55113279d 100644 --- a/tapdb/sqlite.go +++ b/tapdb/sqlite.go @@ -131,8 +131,12 @@ func NewSqliteStore(cfg *SqliteConfig) (*SqliteStore, error) { return nil, err } + sqliteFS := newReplacerFS(sqlSchemas, map[string]string{ + "BIGINT PRIMARY KEY": "INTEGER PRIMARY KEY", + }) + err = applyMigrations( - sqlSchemas, driver, "sqlc/migrations", "sqlc", + sqliteFS, driver, "sqlc/migrations", "sqlc", ) if err != nil { return nil, err diff --git a/tapdb/sqlutils.go b/tapdb/sqlutils.go index 4bd7dbcec..906d5f1d5 100644 --- a/tapdb/sqlutils.go +++ b/tapdb/sqlutils.go @@ -18,6 +18,18 @@ var ( MaxValidSQLTime = time.Date(9999, 12, 31, 23, 59, 59, 999999, time.UTC) ) +// sqlInt64 turns a numerical integer type into the NullInt64 that sql/sqlc +// uses when an integer field can be permitted to be NULL. +// +// We use the constraints.Integer constraint here which maps to all signed and +// unsigned integer types. +func sqlInt64[T constraints.Integer](num T) sql.NullInt64 { + return sql.NullInt64{ + Int64: int64(num), + Valid: true, + } +} + // sqlInt32 turns a numerical integer type into the NullInt32 that sql/sqlc // uses when an integer field can be permitted to be NULL. // @@ -64,6 +76,13 @@ func sqlStr(s string) sql.NullString { } } +// extractSqlInt64 turns a NullInt64 into a numerical type. This can be useful +// when reading directly from the database, as this function handles extracting +// the inner value from the "option"-like struct. +func extractSqlInt64[T constraints.Integer](num sql.NullInt64) T { + return T(num.Int64) +} + // extractSqlInt32 turns a NullInt32 into a numerical type. This can be useful // when reading directly from the database, as this function handles extracting // the inner value from the "option"-like struct. diff --git a/tapdb/universe.go b/tapdb/universe.go index d3d1ed96e..2ed717e2f 100644 --- a/tapdb/universe.go +++ b/tapdb/universe.go @@ -78,7 +78,8 @@ type BaseUniverseStore interface { // UpsertUniverseRoot attempts to insert a universe root, returning the // existing primary key of the root if already exists. - UpsertUniverseRoot(ctx context.Context, arg NewUniverseRoot) (int32, error) + UpsertUniverseRoot(ctx context.Context, arg NewUniverseRoot) (int64, + error) // FetchUniverseKeys fetches the set of keys that are currently stored // for a given namespace. @@ -215,7 +216,7 @@ func (t *treeStoreWrapperTx) View(ctx context.Context, // exist. Otherwise, the primary key of the existing asset ID is returned. func upsertAssetGen(ctx context.Context, db UpsertAssetStore, assetGen asset.Genesis, groupKey *asset.GroupKey, - genesisProof *proof.Proof) (int32, error) { + genesisProof *proof.Proof) (int64, error) { // First, given the genesis point in the passed genesis, we'll insert a // new genesis point in the DB. @@ -290,7 +291,7 @@ func upsertAssetGen(ctx context.Context, db UpsertAssetStore, } if err := db.AnchorGenesisPoint(ctx, GenesisPointAnchor{ PrevOut: genesisPoint, - AnchorTxID: sqlInt32(chainTXID), + AnchorTxID: sqlInt64(chainTXID), }); err != nil { return 0, fmt.Errorf("unable to anchor genesis tx: %w", err) } diff --git a/tapdb/universe_federation.go b/tapdb/universe_federation.go index 93052f5fb..cd394b5b6 100644 --- a/tapdb/universe_federation.go +++ b/tapdb/universe_federation.go @@ -95,7 +95,7 @@ func (u *UniverseFederationDB) UniverseServers( uniServers = fn.Map(servers, func(s sqlc.UniverseServer) universe.ServerAddr { return universe.NewServerAddr( - uint32(s.ID), s.ServerHost, + s.ID, s.ServerHost, ) }, ) @@ -145,7 +145,7 @@ func (u *UniverseFederationDB) RemoveServers(ctx context.Context, // host string instead. This avoids bugs where a user // doesn't set the ID value, and we try to delete the // very first server. - uniID := int32(a.ID) + uniID := int64(a.ID) if a.HostStr() != "" { uniID = -1 } diff --git a/tapdb/universe_federation_test.go b/tapdb/universe_federation_test.go index b9efbeab6..78553c861 100644 --- a/tapdb/universe_federation_test.go +++ b/tapdb/universe_federation_test.go @@ -47,7 +47,7 @@ func TestUniverseFederationCRUD(t *testing.T) { // Next, we'll try to add a new series of servers to the DB. const numServers = 10 addrs := make([]universe.ServerAddr, 0, numServers) - for i := uint32(0); i < numServers; i++ { + for i := int64(0); i < numServers; i++ { portOffset := i + 10_000 hostStr := fmt.Sprintf("localhost:%v", portOffset) diff --git a/tapgarden/interface.go b/tapgarden/interface.go index 70a95db59..e894229ae 100644 --- a/tapgarden/interface.go +++ b/tapgarden/interface.go @@ -230,7 +230,7 @@ type MintingStore interface { // FetchGroupByGenesis fetches the asset group created by the genesis // referenced by the given ID. FetchGroupByGenesis(ctx context.Context, - genesisID int32) (*asset.AssetGroup, error) + genesisID int64) (*asset.AssetGroup, error) // FetchGroupByGroupKey fetches the asset group with a matching tweaked // key, including the genesis information used to create the group. diff --git a/universe/interface.go b/universe/interface.go index 00a4ba7c1..cfff3aca2 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -352,9 +352,7 @@ func resolverUniverseAddr(uniAddr string) (net.Addr, error) { // server. type ServerAddr struct { // ID is the unique identifier of the remote universe. - // - // TODO(roasbeef): break out into generic ID wrapper struct? - ID uint32 + ID int64 // addrStr is the pure string version of the address before any name // resolution has taken place. @@ -376,7 +374,7 @@ func NewServerAddrFromStr(s string) ServerAddr { // NewServerAddr creates a new server address from both the universe addr ID // and the host name string. -func NewServerAddr(i uint32, s string) ServerAddr { +func NewServerAddr(i int64, s string) ServerAddr { return ServerAddr{ ID: i, addrStr: s,