Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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 `gorm:"type:bytea"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the GORM field type override. This is a Postgres column type that won't work in SQLite

Transaction *Transaction
}

func (PlutusData) TableName() string {
return "plutus_data"
}
4 changes: 4 additions & 0 deletions database/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ var MigrateModels = []any{
&Utxo{},
&VoteDelegation{},
&VoteRegistrationDelegation{},
&Witness{},
&Script{},
&Redeemer{},
&PlutusData{},
}
43 changes: 43 additions & 0 deletions database/models/redeemer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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

// RedeemerTag represents the tag for a redeemer (spend, mint, cert, reward, voting, proposing)
type RedeemerTag uint8

const (
RedeemerTagSpend RedeemerTag = 0
RedeemerTagMint RedeemerTag = 1
RedeemerTagCert RedeemerTag = 2
RedeemerTagReward RedeemerTag = 3
RedeemerTagVoting RedeemerTag = 4
RedeemerTagProposing RedeemerTag = 5
)
Copy link
Contributor

Choose a reason for hiding this comment

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

We should reuse the constants from gouroboros/ledger/common


// Redeemer represents a redeemer in the witness set
type Redeemer struct {
ID uint `gorm:"primaryKey"`
TransactionID uint `gorm:"index"`
Tag uint8 `gorm:"index"` // RedeemerTag
Index uint32 `gorm:"index"`
Data []byte `gorm:"type:bytea"` // Plutus data
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a Postgres data type, which is not supported by SQLite. We should let GORM determine the correct type to use under the hood where it can.

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"
}
38 changes: 38 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,38 @@
// 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

// ScriptType represents the type of script
type ScriptType uint8

const (
ScriptTypeNative ScriptType = 0
ScriptTypePlutusV1 ScriptType = 1
ScriptTypePlutusV2 ScriptType = 2
ScriptTypePlutusV3 ScriptType = 3
)

// Script represents a script entry in the witness set
type Script struct {
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 to WitnessScripts to be a bit more specific about its function (mapping TX ID to script hash when the script appears in the TX witness)

ID uint `gorm:"primaryKey"`
TransactionID uint `gorm:"index"`
Type uint8 `gorm:"index"` // ScriptType (0=Native, 1=PlutusV1, 2=PlutusV2, 3=PlutusV3)
ScriptData []byte `gorm:"type:bytea"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a Postgres data type, which is not supported by SQLite. We should let GORM determine the correct type to use under the hood where it can.

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 (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"`
Witnesses []Witness `gorm:"foreignKey:TransactionID;references:ID"`
Scripts []Script `gorm:"foreignKey:TransactionID;references:ID"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename to WitnessScripts

Redeemers []Redeemer `gorm:"foreignKey:TransactionID;references:ID"`
PlutusDataList []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

// WitnessType represents the type of witness
type WitnessType uint8

const (
WitnessTypeVkey WitnessType = 0
WitnessTypeBootstrap WitnessType = 1
)

// Witness represents a witness entry (Vkey or Bootstrap)
type Witness struct {
ID uint `gorm:"primaryKey"`
TransactionID uint `gorm:"index"`
Type uint8 `gorm:"index"` // WitnessType (0=Vkey, 1=Bootstrap)
Vkey []byte `gorm:"type:bytea"`
Signature []byte `gorm:"type:bytea"`
PublicKey []byte `gorm:"type:bytea"` // For Bootstrap
ChainCode []byte `gorm:"type:bytea"` // For Bootstrap
Attributes []byte `gorm:"type:bytea"` // For Bootstrap
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 (Witness) TableName() string {
return "witness"
}
Loading