Skip to content

Commit eb6ab54

Browse files
author
Jenita
committed
feat: track witness set for transaction
Signed-off-by: Jenita <jkawan@blinklabs.io>
1 parent a01f5ab commit eb6ab54

File tree

6 files changed

+149
-8
lines changed

6 files changed

+149
-8
lines changed

database/models/datum.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ type Datum struct {
2424
func (Datum) TableName() string {
2525
return "datum"
2626
}
27+
28+
// PlutusData represents a Plutus data value in the witness set
29+
type PlutusData struct {
30+
ID uint `gorm:"primaryKey"`
31+
TransactionID uint `gorm:"index"`
32+
Data []byte `gorm:"type:bytea"`
33+
Transaction *Transaction
34+
}
35+
36+
func (PlutusData) TableName() string {
37+
return "plutus_data"
38+
}

database/models/models.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ var MigrateModels = []any{
4848
&Utxo{},
4949
&VoteDelegation{},
5050
&VoteRegistrationDelegation{},
51+
&Witness{},
52+
&Script{},
53+
&Redeemer{},
54+
&PlutusData{},
5155
}

database/models/redeemer.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2025 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package models
16+
17+
// RedeemerTag represents the tag for a redeemer (spend, mint, cert, reward, voting, proposing)
18+
type RedeemerTag uint8
19+
20+
const (
21+
RedeemerTagSpend RedeemerTag = 0
22+
RedeemerTagMint RedeemerTag = 1
23+
RedeemerTagCert RedeemerTag = 2
24+
RedeemerTagReward RedeemerTag = 3
25+
RedeemerTagVoting RedeemerTag = 4
26+
RedeemerTagProposing RedeemerTag = 5
27+
)
28+
29+
// Redeemer represents a redeemer in the witness set
30+
type Redeemer struct {
31+
ID uint `gorm:"primaryKey"`
32+
TransactionID uint `gorm:"index"`
33+
Tag uint8 `gorm:"index"` // RedeemerTag
34+
Index uint32 `gorm:"index"`
35+
Data []byte `gorm:"type:bytea"` // Plutus data
36+
ExUnitsMemory uint64
37+
ExUnitsCPU uint64
38+
Transaction *Transaction
39+
}
40+
41+
func (Redeemer) TableName() string {
42+
return "redeemer"
43+
}

database/models/script.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2025 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package models
16+
17+
// ScriptType represents the type of script
18+
type ScriptType uint8
19+
20+
const (
21+
ScriptTypeNative ScriptType = 0
22+
ScriptTypePlutusV1 ScriptType = 1
23+
ScriptTypePlutusV2 ScriptType = 2
24+
ScriptTypePlutusV3 ScriptType = 3
25+
)
26+
27+
// Script represents a script entry in the witness set
28+
type Script struct {
29+
ID uint `gorm:"primaryKey"`
30+
TransactionID uint `gorm:"index"`
31+
Type uint8 `gorm:"index"` // ScriptType (0=Native, 1=PlutusV1, 2=PlutusV2, 3=PlutusV3)
32+
ScriptData []byte `gorm:"type:bytea"`
33+
Transaction *Transaction
34+
}
35+
36+
func (Script) TableName() string {
37+
return "script"
38+
}

database/models/transaction.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ package models
1616

1717
// Transaction represents a transaction record
1818
type Transaction struct {
19-
Hash []byte `gorm:"uniqueIndex"`
20-
BlockHash []byte `gorm:"index"`
21-
Inputs []Utxo `gorm:"foreignKey:SpentAtTxId;references:Hash"`
22-
Outputs []Utxo `gorm:"foreignKey:TransactionID;references:ID"`
23-
ReferenceInputs []Utxo `gorm:"foreignKey:ReferencedByTxId;references:Hash"`
24-
Collateral []Utxo `gorm:"foreignKey:CollateralByTxId;references:Hash"`
25-
CollateralReturn *Utxo `gorm:"foreignKey:TransactionID;references:ID"`
26-
ID uint `gorm:"primaryKey"`
19+
Hash []byte `gorm:"uniqueIndex"`
20+
BlockHash []byte `gorm:"index"`
21+
Inputs []Utxo `gorm:"foreignKey:SpentAtTxId;references:Hash"`
22+
Outputs []Utxo `gorm:"foreignKey:TransactionID;references:ID"`
23+
ReferenceInputs []Utxo `gorm:"foreignKey:ReferencedByTxId;references:Hash"`
24+
Collateral []Utxo `gorm:"foreignKey:CollateralByTxId;references:Hash"`
25+
CollateralReturn *Utxo `gorm:"foreignKey:TransactionID;references:ID"`
26+
Witnesses []Witness `gorm:"foreignKey:TransactionID;references:ID"`
27+
Scripts []Script `gorm:"foreignKey:TransactionID;references:ID"`
28+
Redeemers []Redeemer `gorm:"foreignKey:TransactionID;references:ID"`
29+
PlutusDataList []PlutusData `gorm:"foreignKey:TransactionID;references:ID"`
30+
ID uint `gorm:"primaryKey"`
2731
Type int
2832
BlockIndex uint32
2933
Metadata []byte

database/models/witness.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2025 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package models
16+
17+
// WitnessType represents the type of witness
18+
type WitnessType uint8
19+
20+
const (
21+
WitnessTypeVkey WitnessType = 0
22+
WitnessTypeBootstrap WitnessType = 1
23+
)
24+
25+
// Witness represents a witness entry (Vkey or Bootstrap)
26+
type Witness struct {
27+
ID uint `gorm:"primaryKey"`
28+
TransactionID uint `gorm:"index"`
29+
Type uint8 `gorm:"index"` // WitnessType (0=Vkey, 1=Bootstrap)
30+
Vkey []byte `gorm:"type:bytea"`
31+
Signature []byte `gorm:"type:bytea"`
32+
PublicKey []byte `gorm:"type:bytea"` // For Bootstrap
33+
ChainCode []byte `gorm:"type:bytea"` // For Bootstrap
34+
Attributes []byte `gorm:"type:bytea"` // For Bootstrap
35+
Transaction *Transaction
36+
}
37+
38+
func (Witness) TableName() string {
39+
return "witness"
40+
}

0 commit comments

Comments
 (0)