Skip to content

Commit

Permalink
feat(Apollo): add method to set collateralAmount for transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
mgpai22 committed Jan 14, 2025
1 parent ee833a2 commit 8ff1f05
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions ApolloBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type Apollo struct {
FeePadding int64
Ttl int64
ValidityStart int64
collateralAmount int
totalCollateral int
referenceInputs []TransactionInput.TransactionInput
collateralReturn *TransactionOutput.TransactionOutput
Expand Down Expand Up @@ -833,8 +834,13 @@ Returns:
*/

func (b *Apollo) setCollateral() (*Apollo, error) {
collateral_amount := 5_000_000

if b.collateralAmount > 0 {
collateral_amount = b.collateralAmount
}

if len(b.collaterals) > 0 {
collateral_amount := 5_000_000
for _, utxo := range b.collaterals {
if int(utxo.Output.GetValue().GetCoin()) >= collateral_amount+1_000_000 && len(utxo.Output.GetValue().GetAssets()) <= 5 {
b.totalCollateral = collateral_amount
Expand All @@ -852,7 +858,7 @@ func (b *Apollo) setCollateral() (*Apollo, error) {
return b, nil
}
availableUtxos := b.getAvailableUtxos()
collateral_amount := 5_000_000

for _, utxo := range availableUtxos {
if int(utxo.Output.GetValue().GetCoin()) >= collateral_amount && len(utxo.Output.GetValue().GetAssets()) <= 5 {
return_amount := utxo.Output.GetValue().GetCoin() - int64(collateral_amount)
Expand Down Expand Up @@ -1861,6 +1867,19 @@ func (b *Apollo) DisableExecutionUnitsEstimation() *Apollo {
return b
}

/*
*
SetCollateralAmount sets the collateral amount for the transaction.
Returns:
*Apollo: A pointer to the modified Apollo instance with the collateral amount set.
*/
func (b *Apollo) SetCollateralAmount(amount int) *Apollo {
b.collateralAmount = amount
return b
}

func (b *Apollo) AddWithdrawal(address Address.Address, amount int, redeemerData PlutusData.PlutusData) *Apollo {
if b.withdrawals == nil {
newWithdrawal := Withdrawal.New()
Expand Down

0 comments on commit 8ff1f05

Please sign in to comment.