Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/nilaway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
nilaway:
name: nilaway
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 https://github.com/actions/checkout/releases/tag/v5.0.0
- uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 https://github.com/actions/setup-go/releases/tag/v6.0.0
Expand Down
12 changes: 12 additions & 0 deletions database/models/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ type Datum struct {
func (Datum) TableName() string {
return "datum"
}

// PlutusData represents a Plutus data value in the witness set
type PlutusData struct {
ID uint `gorm:"primaryKey"`
TransactionID uint `gorm:"index"`
Data []byte
Transaction *Transaction
}

func (PlutusData) TableName() string {
return "plutus_data"
}
5 changes: 5 additions & 0 deletions database/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ var MigrateModels = []any{
&DeregistrationDrep{},
&Drep{},
&Epoch{},
&KeyWitness{},
&Pool{},
&PoolRegistration{},
&PoolRegistrationOwner{},
&PoolRegistrationRelay{},
&PoolRetirement{},
&PParams{},
&PParamUpdate{},
&PlutusData{},
&Registration{},
&RegistrationDrep{},
&Redeemer{},
&ResignCommitteeCold{},
&Script{},
&StakeDelegation{},
&StakeDeregistration{},
&StakeRegistration{},
Expand All @@ -48,4 +52,5 @@ var MigrateModels = []any{
&Utxo{},
&VoteDelegation{},
&VoteRegistrationDelegation{},
&WitnessScripts{},
}
31 changes: 31 additions & 0 deletions database/models/redeemer.go
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
Copy link
Contributor

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 Transaction when we've already got the TransactionId field

}

func (Redeemer) TableName() string {
return "redeemer"
}
37 changes: 37 additions & 0 deletions database/models/script.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this file to witness_script.go

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
Copy link
Contributor

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 Transaction when we've already got the TransactionId field

}

func (WitnessScripts) TableName() string {
return "witness_scripts"
}
30 changes: 30 additions & 0 deletions database/models/script_content.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this file to script.go

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"
}
20 changes: 12 additions & 8 deletions database/models/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ package models

// Transaction represents a transaction record
type Transaction struct {
Hash []byte `gorm:"uniqueIndex"`
BlockHash []byte `gorm:"index"`
Inputs []Utxo `gorm:"foreignKey:SpentAtTxId;references:Hash"`
Outputs []Utxo `gorm:"foreignKey:TransactionID;references:ID"`
ReferenceInputs []Utxo `gorm:"foreignKey:ReferencedByTxId;references:Hash"`
Collateral []Utxo `gorm:"foreignKey:CollateralByTxId;references:Hash"`
CollateralReturn *Utxo `gorm:"foreignKey:TransactionID;references:ID"`
ID uint `gorm:"primaryKey"`
Hash []byte `gorm:"uniqueIndex"`
BlockHash []byte `gorm:"index"`
Inputs []Utxo `gorm:"foreignKey:SpentAtTxId;references:Hash"`
Outputs []Utxo `gorm:"foreignKey:TransactionID;references:ID"`
ReferenceInputs []Utxo `gorm:"foreignKey:ReferencedByTxId;references:Hash"`
Collateral []Utxo `gorm:"foreignKey:CollateralByTxId;references:Hash"`
CollateralReturn *Utxo `gorm:"foreignKey:TransactionID;references:ID"`
KeyWitnesses []KeyWitness `gorm:"foreignKey:TransactionID;references:ID"`
WitnessScripts []WitnessScripts `gorm:"foreignKey:TransactionID;references:ID"`
Redeemers []Redeemer `gorm:"foreignKey:TransactionID;references:ID"`
PlutusData []PlutusData `gorm:"foreignKey:TransactionID;references:ID"`
ID uint `gorm:"primaryKey"`
Type int
BlockIndex uint32
Metadata []byte
Expand Down
40 changes: 40 additions & 0 deletions database/models/witness.go
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
Copy link
Contributor

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 Transaction when we've already got the TransactionId field

}

func (KeyWitness) TableName() string {
return "key_witness"
}
42 changes: 42 additions & 0 deletions database/plugin/metadata/sqlite/script.go
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
}
Loading