-
Notifications
You must be signed in to change notification settings - Fork 5
feat: track assets with utxos #889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+222
−11
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
b1290f1
feat: add amount to Utxo table to track amount
874893f
feat: add amount to Utxo table to track amount
96aef0a
feat: add amount to Utxo table to track amount
55407d3
feat: added changes to track assets
8104e4b
Merge branch 'main' into track-asset
jkawan 034e35f
feat: added changes to track assets
e88b446
feat: addressed review comments
6b60ab4
feat: addressed review comments
d91396c
feat: addressed review comment
4e7c62d
feat: addressed review comment
45ecb6c
feat: addressed review comment
c435386
feat: addressed review comment
556b107
feat: addressed review comment
9c976d3
feat: addressed review comment
8f9bdb0
feat: addressed review comment
60c939a
feat: addressed review comments
a13aa5a
fix(database): asset type for utxo
wolf31o2 b01b489
chore: formatting
wolf31o2 64495da
fix(database): use custom uint64 database type
wolf31o2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2025 Blink Labs Software | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package sqlite | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/blinklabs-io/dingo/database/plugin/metadata/sqlite/models" | ||
lcommon "github.com/blinklabs-io/gouroboros/ledger/common" | ||
"gorm.io/gorm" | ||
) | ||
|
||
// GetAssetByPolicyAndName returns an asset by policy ID and asset name | ||
func (d *MetadataStoreSqlite) GetAssetByPolicyAndName( | ||
policyId lcommon.Blake2b224, | ||
assetName []byte, | ||
txn *gorm.DB, | ||
) (models.Asset, error) { | ||
var asset models.Asset | ||
var result *gorm.DB | ||
|
||
query := d.DB() | ||
if txn != nil { | ||
query = txn | ||
} | ||
|
||
result = query.Where("policy_id = ? AND name = ?", policyId[:], assetName).First(&asset) | ||
if result.Error != nil { | ||
if errors.Is(result.Error, gorm.ErrRecordNotFound) { | ||
return models.Asset{}, nil | ||
} | ||
return models.Asset{}, result.Error | ||
} | ||
return asset, nil | ||
} | ||
|
||
// GetAssetsByPolicy returns all assets for a given policy ID | ||
func (d *MetadataStoreSqlite) GetAssetsByPolicy( | ||
policyId lcommon.Blake2b224, | ||
txn *gorm.DB, | ||
) ([]models.Asset, error) { | ||
var assets []models.Asset | ||
var result *gorm.DB | ||
|
||
query := d.DB() | ||
if txn != nil { | ||
query = txn | ||
} | ||
|
||
result = query.Where("policy_id = ?", policyId[:]).Find(&assets) | ||
if result.Error != nil { | ||
return nil, result.Error | ||
} | ||
return assets, nil | ||
} | ||
|
||
// GetAssetsByUTxO returns all assets for a given UTxO using transaction ID and output index | ||
func (d *MetadataStoreSqlite) GetAssetsByUTxO( | ||
txId []byte, | ||
idx uint32, | ||
txn *gorm.DB, | ||
) ([]models.Asset, error) { | ||
var assets []models.Asset | ||
var result *gorm.DB | ||
|
||
query := d.DB() | ||
if txn != nil { | ||
query = txn | ||
} | ||
|
||
// Join with UTxO table to find assets by transaction ID and output index | ||
result = query.Joins("INNER JOIN utxos ON assets.utxo_id = utxos.id"). | ||
Where("utxos.tx_id = ? AND utxos.idx = ?", txId, idx). | ||
Find(&assets) | ||
if result.Error != nil { | ||
return nil, result.Error | ||
} | ||
return assets, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2025 Blink Labs Software | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package models | ||
|
||
import "github.com/blinklabs-io/dingo/database/types" | ||
|
||
type Asset struct { | ||
ID uint `gorm:"primaryKey"` | ||
UtxoID uint | ||
Name []byte `gorm:"index"` | ||
NameHex []byte `gorm:"index"` | ||
PolicyId []byte `gorm:"index"` | ||
Fingerprint []byte `gorm:"index"` | ||
Amount types.Uint64 `gorm:"index"` | ||
} | ||
|
||
func (Asset) TableName() string { | ||
return "asset" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add assets to the Utxo struct above so this doesn't need to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wolf31o2 what should be the type for assets in Utxo struct here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*lcommon.MultiAsset[T]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type that we're getting from
d.metadata.GetUtxo()
is amodels.Utxo
with an embedded[]models.Asset
. We can create a duplicateAsset
type in this package and modify the duplicateUtxo
type accordingly in the short term, but we're eventually going to need to do some conversion to get it back in alcommon.MultiAsset
. It probably makes sense to just do that here, since this PR already has a conversion function for the other direction.