@@ -4,13 +4,13 @@ import {
44 Coin ,
55 CoinSpend ,
66 Constants ,
7- Output ,
87 Program ,
98 Puzzle ,
109 sha256 ,
1110 SpendBundle ,
1211 toHex ,
1312} from 'chia-wallet-sdk-wasm' ;
13+ import { COST_PER_BYTE } from './constants' ;
1414
1515export interface ParsedSpendBundle {
1616 coinSpends : ParsedCoinSpend [ ] ;
@@ -22,7 +22,7 @@ export interface ParsedCoinSpend {
2222 coin : ParsedCoin ;
2323 puzzleReveal : string ;
2424 solution : string ;
25- runtimeCost : string ;
25+ cost : string ;
2626 conditions : ParsedCondition [ ] ;
2727}
2828
@@ -79,8 +79,8 @@ interface DeserializedCoinSpend {
7979 coinSpend : CoinSpend ;
8080 puzzle : Puzzle ;
8181 solution : Program ;
82- output : Output ;
8382 conditions : Program [ ] ;
83+ cost : bigint ;
8484}
8585
8686export function parseSpendBundle (
@@ -116,6 +116,11 @@ export function parseSpendBundle(
116116 announcements . spentCoinIds . add ( toHex ( coinId ) ) ;
117117 announcements . spentPuzzleHashes . add ( toHex ( puzzleHash ) ) ;
118118
119+ let cost =
120+ output . cost +
121+ COST_PER_BYTE *
122+ BigInt ( coinSpend . puzzleReveal . length + coinSpend . solution . length ) ;
123+
119124 for ( const condition of conditions ) {
120125 const createCoinAnnouncement = condition . parseCreateCoinAnnouncement ( ) ;
121126 if ( createCoinAnnouncement ) {
@@ -159,20 +164,35 @@ export function parseSpendBundle(
159164 new Coin ( coinId , createCoin . puzzleHash , createCoin . amount ) . coinId ( ) ,
160165 ) ,
161166 ) ;
167+ cost += 1_800_000n ;
162168 }
163169
164170 const assertConcurrentSpend = condition . parseAssertConcurrentSpend ( ) ;
165171 if ( assertConcurrentSpend ) {
166172 announcements . assertedCoinIds . add ( toHex ( assertConcurrentSpend . coinId ) ) ;
167173 }
174+
175+ const aggSig =
176+ condition . parseAggSigParent ( ) ??
177+ condition . parseAggSigPuzzle ( ) ??
178+ condition . parseAggSigAmount ( ) ??
179+ condition . parseAggSigPuzzleAmount ( ) ??
180+ condition . parseAggSigParentAmount ( ) ??
181+ condition . parseAggSigParentPuzzle ( ) ??
182+ condition . parseAggSigUnsafe ( ) ??
183+ condition . parseAggSigMe ( ) ;
184+
185+ if ( aggSig ) {
186+ cost += 1_200_000n ;
187+ }
168188 }
169189
170190 deserializedCoinSpends . push ( {
171191 coinSpend,
172192 puzzle,
173193 solution,
174- output,
175194 conditions,
195+ cost,
176196 } ) ;
177197 }
178198
@@ -186,7 +206,7 @@ export function parseSpendBundle(
186206}
187207
188208function parseCoinSpend (
189- { coinSpend, output , puzzle, conditions } : DeserializedCoinSpend ,
209+ { coinSpend, cost , puzzle, conditions } : DeserializedCoinSpend ,
190210 ctx : BundleContext ,
191211) : ParsedCoinSpend {
192212 const coinId = coinSpend . coin . coinId ( ) ;
@@ -262,7 +282,7 @@ function parseCoinSpend(
262282 coin : parseCoin ( coinSpend . coin ) ,
263283 puzzleReveal : toHex ( coinSpend . puzzleReveal ) ,
264284 solution : toHex ( coinSpend . solution ) ,
265- runtimeCost : output . cost . toString ( ) ,
285+ cost : cost . toLocaleString ( ) ,
266286 conditions : conditions . map ( ( condition ) =>
267287 parseCondition ( coinSpend . coin , condition , ctx , isFastForwardable ) ,
268288 ) ,
0 commit comments