Skip to content

Commit

Permalink
Fix: Mint and burn with plutus
Browse files Browse the repository at this point in the history
  • Loading branch information
Salvionied committed Dec 5, 2023
1 parent 67e693e commit 44876a0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
29 changes: 23 additions & 6 deletions ApolloBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1150,28 +1150,45 @@ func (b *Apollo) GetBurns() (burns Value.Value) {

}

/**
func (b *Apollo) getPositiveMints() (mints Value.Value) {
mints = Value.Value{}
for _, mintUnit := range b.mint {
if mintUnit.Quantity > 0 {
usedUnit := Unit{
PolicyId: mintUnit.PolicyId,
Name: mintUnit.Name,
Quantity: mintUnit.Quantity,
}
mints = mints.Add(usedUnit.ToValue())
}

}
return mints

}

/*
*
Add change and fees to the transaction.
Returns:
*Apollo: A pointer to the Apollo object with change and fees added.
error: An error if addChangeAndFee fails.
*/

func (b *Apollo) addChangeAndFee() (*Apollo, error) {
burns := b.GetBurns()
mints := b.getMints()
mints := b.getPositiveMints()
providedAmount := Value.Value{}
for _, utxo := range b.preselectedUtxos {
providedAmount = providedAmount.Add(utxo.Output.GetValue())
}
providedAmount = providedAmount.Sub(burns)
providedAmount = providedAmount.Add(Value.SimpleValue(0, mints))
providedAmount = providedAmount.Add(mints)
requestedAmount := Value.Value{}
for _, payment := range b.payments {
requestedAmount = requestedAmount.Add(payment.ToValue())
}
requestedAmount = requestedAmount.Add(burns)
b.Fee = b.estimateFee()
requestedAmount.AddLovelace(b.Fee)
change := providedAmount.Sub(requestedAmount)
Expand Down
6 changes: 4 additions & 2 deletions serialization/TransactionWitnessSet/TransactionWitnessSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ type WithRedeemerNoScripts struct {
VkeyWitnesses []VerificationKeyWitness.VerificationKeyWitness `cbor:"0,keyasint,omitempty"`
NativeScripts []NativeScript.NativeScript `cbor:"1,keyasint,omitempty"`
BootstrapWitnesses []any `cbor:"2,keyasint,omitempty"`
PlutusV1Script []PlutusData.PlutusV1Script `cbor:"3,keyasint"`
PlutusV1Script []PlutusData.PlutusV1Script `cbor:"3,keyasint,omitempty"`
PlutusV2Script []PlutusData.PlutusV2Script `cbor:"6,keyasint,omitempty"`
PlutusData *PlutusData.PlutusIndefArray `cbor:"4,keyasint,omitempty"`
Redeemer []Redeemer.Redeemer `cbor:"5,keyasint,omitempty"`
}

/**
/*
*
MarshalCBOR serializes the TransactionWitnessSet to a CBOR byte slice.
Returns:
Expand Down
4 changes: 2 additions & 2 deletions tests/txBuilding/ApolloBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func TestBurnPlutus(t *testing.T) {
t.Error(err)
}
txBytes, err := apollob.GetTx().Bytes()
if hex.EncodeToString(txBytes) != "84a5008182584064356431663763323233646338386262343134373461663233623638356530323437333037653934653731356566356536326633323561633934663733303536000181825839010a59337f7b3a913424d7f7a151401e052642b68e948d8cacadc6372016a9999419cc5a61ca62da81e378d7538213a3715a6b858c948c69c91a00e2117b021a0002d04509a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa14454455354200b5820aed726f17f6c88739b6d5ba2e104b948bb81f6c46e8fc0809c120021c1e6e88ba203800581840000f6820000f5f6" {
if hex.EncodeToString(txBytes) != "84a5008182584064356431663763323233646338386262343134373461663233623638356530323437333037653934653731356566356536326633323561633934663733303536000181825839010a59337f7b3a913424d7f7a151401e052642b68e948d8cacadc6372016a9999419cc5a61ca62da81e378d7538213a3715a6b858c948c69c91a00e211d3021a0002cfed09a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa14454455354200b5820aed726f17f6c88739b6d5ba2e104b948bb81f6c46e8fc0809c120021c1e6e88ba10581840000f6820000f5f6" {
t.Error("Tx is not correct", hex.EncodeToString(txBytes))
}
}
Expand Down Expand Up @@ -517,7 +517,7 @@ func TestMintPlutus(t *testing.T) {
t.Error(err)
}
txBytes, err := apollob.GetTx().Bytes()
if hex.EncodeToString(txBytes) != "84a5008182584064356431663763323233646338386262343134373461663233623638356530323437333037653934653731356566356536326633323561633934663733303536000181825839010a59337f7b3a913424d7f7a151401e052642b68e948d8cacadc6372016a9999419cc5a61ca62da81e378d7538213a3715a6b858c948c69c9821a00e20ac7a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa1445445535401021a0002d6f909a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa14454455354010b5820aed726f17f6c88739b6d5ba2e104b948bb81f6c46e8fc0809c120021c1e6e88ba203800581840000f6820000f5f6" {
if hex.EncodeToString(txBytes) != "84a5008182584064356431663763323233646338386262343134373461663233623638356530323437333037653934653731356566356536326633323561633934663733303536000181825839010a59337f7b3a913424d7f7a151401e052642b68e948d8cacadc6372016a9999419cc5a61ca62da81e378d7538213a3715a6b858c948c69c9821a00e20b1fa1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa1445445535401021a0002d6a109a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa14454455354010b5820aed726f17f6c88739b6d5ba2e104b948bb81f6c46e8fc0809c120021c1e6e88ba10581840000f6820000f5f6" {
t.Error("Tx is not correct", hex.EncodeToString(txBytes))
}
}

0 comments on commit 44876a0

Please sign in to comment.