Skip to content

Commit 5340913

Browse files
sgillespiekderme
authored andcommitted
feature(cardano-db): Add new tx field treasury_donation
1 parent d3b951d commit 5340913

File tree

10 files changed

+47
-1
lines changed

10 files changed

+47
-1
lines changed

cardano-db-sync/src/Cardano/DbSync/Era/Byron/Genesis.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ insertTxOuts hasConsumed disInOut blkId (address, value) = do
201201
, DB.txInvalidBefore = Nothing
202202
, DB.txValidContract = True
203203
, DB.txScriptSize = 0
204+
, DB.txTreasuryDonation = DB.DbLovelace 0
204205
}
205206
lift $
206207
DB.insertTxOutPlex hasConsumed disInOut $

cardano-db-sync/src/Cardano/DbSync/Era/Byron/Insert.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ insertByronTx syncEnv blkId tx blockIndex = do
253253
, DB.txInvalidBefore = Nothing
254254
, DB.txValidContract = True
255255
, DB.txScriptSize = 0
256+
, DB.txTreasuryDonation = DbLovelace 0
256257
}
257258

258259
when (ioTxCBOR iopts) $ do
@@ -295,6 +296,7 @@ insertByronTx' syncEnv blkId tx blockIndex = do
295296
, DB.txInvalidBefore = Nothing
296297
, DB.txValidContract = True
297298
, DB.txScriptSize = 0
299+
, DB.txTreasuryDonation = DbLovelace 0
298300
}
299301

300302
when (ioTxCBOR iopts) $ do

cardano-db-sync/src/Cardano/DbSync/Era/Shelley/Genesis.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ insertTxOuts trce hasConsumed disInOut blkId (TxIn txInId _, txOut) = do
241241
, DB.txInvalidBefore = Nothing
242242
, DB.txValidContract = True
243243
, DB.txScriptSize = 0
244+
, DB.txTreasuryDonation = DB.DbLovelace 0
244245
}
245246
_ <- insertStakeAddressRefIfMissing trce useNoCache (txOut ^. Core.addrTxOutL)
246247
DB.insertTxOutPlex hasConsumed disInOut $
@@ -286,6 +287,7 @@ insertStaking tracer cache blkId genesis = do
286287
, DB.txInvalidBefore = Nothing
287288
, DB.txValidContract = True
288289
, DB.txScriptSize = 0
290+
, DB.txTreasuryDonation = DB.DbLovelace 0
289291
}
290292
let params = zip [0 ..] $ ListMap.elems $ sgsPools $ sgStaking genesis
291293
let network = sgNetworkId genesis

cardano-db-sync/src/Cardano/DbSync/Era/Universal/Insert/Tx.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ insertTx syncEnv isMember blkId epochNo slotNo applyResult blockIndex tx grouped
117117
, DB.txInvalidHereafter = DbWord64 . unSlotNo <$> Generic.txInvalidHereafter tx
118118
, DB.txValidContract = Generic.txValidContract tx
119119
, DB.txScriptSize = sum $ Generic.txScriptSizes tx
120+
, DB.txTreasuryDonation = DB.DbLovelace 0
120121
}
121122

122123
when (ioTxCBOR iopts) $ do

cardano-db/src/Cardano/Db/Schema.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ share
131131
scriptSize Word64 sqltype=word31type
132132
UniqueTx hash
133133

134+
-- New for Conway
135+
treasuryDonation DbLovelace sqltype=lovelace default=0
136+
134137
TxCbor
135138
txId TxId noreference
136139
bytes ByteString sqltype=bytea

cardano-db/test/Test/IO/Cardano/Db/Insert.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ txZero bid =
170170
, txInvalidHereafter = Nothing
171171
, txValidContract = True
172172
, txScriptSize = 0
173+
, txTreasuryDonation = DbLovelace 0
173174
}
174175

175176
poolHash0 :: PoolHash

cardano-db/test/Test/IO/Cardano/Db/Rollback.hs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,22 @@ createAndInsertBlocks blockCount =
112112
if indx /= 0
113113
then pure mTxOutId
114114
else do
115-
txId <- insertTx $ Tx (mkTxHash blkId 0) blkId 0 (DbLovelace 0) (DbLovelace 0) (Just 0) 12 Nothing Nothing True 0
115+
txId <-
116+
insertTx $
117+
Tx
118+
(mkTxHash blkId 0)
119+
blkId
120+
0
121+
(DbLovelace 0)
122+
(DbLovelace 0)
123+
(Just 0)
124+
12
125+
Nothing
126+
Nothing
127+
True
128+
0
129+
(DbLovelace 0)
130+
116131
void $ insertTxOut (mkTxOut blkId txId)
117132
pure $ Just txId
118133
case (indx, mTxOutId) of

cardano-db/test/Test/IO/Cardano/Db/TotalSupply.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ initialSupplyTest =
4949
, txInvalidBefore = Nothing
5050
, txValidContract = True
5151
, txScriptSize = 0
52+
, txTreasuryDonation = DbLovelace 0
5253
}
5354
_ <- insertTxIn (TxIn tx1Id (head tx0Ids) 0 Nothing)
5455
let addr = mkAddressHash bid1 tx1Id

cardano-db/test/Test/IO/Cardano/Db/Util.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ mkTxs blkId count =
9191
, txInvalidBefore = Nothing
9292
, txValidContract = True
9393
, txScriptSize = 0
94+
, txTreasuryDonation = DbLovelace 0
9495
}
9596

9697
testSlotLeader :: SlotLeader

schema/migration-2-0040-20240626.sql

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- Persistent generated migration.
2+
3+
CREATE FUNCTION migrate() RETURNS void AS $$
4+
DECLARE
5+
next_version int ;
6+
BEGIN
7+
SELECT stage_two + 1 INTO next_version FROM schema_version ;
8+
IF next_version = 40 THEN
9+
EXECUTE 'ALTER TABLE "tx" ADD COLUMN "treasury_donation" lovelace NOT NULL DEFAULT 0' ;
10+
-- Hand written SQL statements can be added here.
11+
UPDATE schema_version SET stage_two = next_version ;
12+
RAISE NOTICE 'DB has been migrated to stage_two version %', next_version ;
13+
END IF ;
14+
END ;
15+
$$ LANGUAGE plpgsql ;
16+
17+
SELECT migrate() ;
18+
19+
DROP FUNCTION migrate() ;

0 commit comments

Comments
 (0)