-
Notifications
You must be signed in to change notification settings - Fork 6
feat: track witness set for transaction #1027
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
base: main
Are you sure you want to change the base?
Changes from all commits
eb6ab54
6d6530d
c3fa7a0
dab5d82
6f5b11b
04852d0
3260f67
ffb53dc
d351aa8
d8edaf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| // Redeemer represents a redeemer in the witness set | ||
| type Redeemer struct { | ||
| ID uint `gorm:"primaryKey"` | ||
| TransactionID uint `gorm:"index"` | ||
| Tag uint8 `gorm:"index"` // Redeemer tag | ||
| Index uint32 `gorm:"index"` | ||
| Data []byte // Plutus data | ||
| ExUnitsMemory uint64 | ||
| ExUnitsCPU uint64 | ||
| Transaction *Transaction | ||
| } | ||
|
|
||
| func (Redeemer) TableName() string { | ||
| return "redeemer" | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename this file to |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // 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 | ||
|
|
||
| // WitnessScripts represents a reference to a script in the witness set | ||
| // Type corresponds to ScriptRefType constants from gouroboros/ledger/common: | ||
| // 0=NativeScript (ScriptRefTypeNativeScript) | ||
| // 1=PlutusV1 (ScriptRefTypePlutusV1) | ||
| // 2=PlutusV2 (ScriptRefTypePlutusV2) | ||
| // 3=PlutusV3 (ScriptRefTypePlutusV3) | ||
| // | ||
| // To avoid storing duplicate script data for the same script used in multiple | ||
| // transactions, we store only the script hash here. The actual script content | ||
| // is stored separately in Script table, indexed by hash. | ||
| type WitnessScripts struct { | ||
| ID uint `gorm:"primaryKey"` | ||
| TransactionID uint `gorm:"index"` | ||
| Type uint8 `gorm:"index"` // Script type | ||
| ScriptHash []byte `gorm:"index"` // Hash of the script | ||
| Transaction *Transaction | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably don't want/need this reference back to |
||
| } | ||
agaffney marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| func (WitnessScripts) TableName() string { | ||
| return "witness_scripts" | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rename this file to |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // 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 | ||
|
|
||
| // Script represents the content of a script, indexed by its hash | ||
| // This avoids storing duplicate script data when the same script appears | ||
| // in multiple transactions | ||
| type Script struct { | ||
| ID uint `gorm:"primaryKey"` | ||
| Hash []byte `gorm:"index;unique"` // Script hash | ||
| Type uint8 `gorm:"index"` // Script type | ||
| Content []byte // Script content | ||
| CreatedSlot uint64 // Slot when this script was first seen | ||
| } | ||
|
|
||
| func (Script) TableName() string { | ||
| return "script" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // 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 | ||
|
|
||
| const ( | ||
| // KeyWitnessTypeVkey represents a Vkey witness | ||
| KeyWitnessTypeVkey uint8 = 0 | ||
| // KeyWitnessTypeBootstrap represents a Bootstrap witness | ||
| KeyWitnessTypeBootstrap uint8 = 1 | ||
| ) | ||
|
|
||
| // KeyWitness represents a key witness entry (Vkey or Bootstrap) | ||
| // Type: KeyWitnessTypeVkey = VkeyWitness, KeyWitnessTypeBootstrap = BootstrapWitness | ||
| type KeyWitness struct { | ||
| ID uint `gorm:"primaryKey"` | ||
| TransactionID uint `gorm:"index"` | ||
| Type uint8 `gorm:"index"` // See KeyWitnessType* constants | ||
| Vkey []byte // Vkey witness key | ||
| Signature []byte // Witness signature | ||
| PublicKey []byte // For Bootstrap witness | ||
| ChainCode []byte // For Bootstrap witness | ||
| Attributes []byte // For Bootstrap witness | ||
| Transaction *Transaction | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably don't want/need this reference back to |
||
| } | ||
|
|
||
| func (KeyWitness) TableName() string { | ||
| return "key_witness" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // 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/models" | ||
| lcommon "github.com/blinklabs-io/gouroboros/ledger/common" | ||
| "gorm.io/gorm" | ||
| ) | ||
|
|
||
| // GetScript returns the script content by its hash | ||
| func (d *MetadataStoreSqlite) GetScript( | ||
| hash lcommon.ScriptHash, | ||
| txn *gorm.DB, | ||
| ) (*models.Script, error) { | ||
| ret := &models.Script{} | ||
| if txn == nil { | ||
| txn = d.DB() | ||
| } | ||
| result := txn.First(ret, "hash = ?", hash[:]) | ||
| if result.Error != nil { | ||
| if errors.Is(result.Error, gorm.ErrRecordNotFound) { | ||
| return nil, nil | ||
| } | ||
| return nil, result.Error | ||
| } | ||
| return ret, nil | ||
| } |
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 probably don't want/need this reference back to
Transactionwhen we've already got theTransactionIdfield