Skip to content

Commit

Permalink
add setFee method to TransactionBuilderContext
Browse files Browse the repository at this point in the history
  • Loading branch information
capt-nemo429 committed Jun 24, 2023
1 parent 5293925 commit b51587f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hungry-houses-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleet-sdk/core": patch
---

**Transaction Builder**: add `setFee` method to plugin context.
14 changes: 13 additions & 1 deletion packages/core/src/builder/pluginContext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NotAllowedTokenBurning } from "../errors";
import { regularBoxesMock } from "../tests/mocks/mockBoxes";
import { OutputBuilder } from "./outputBuilder";
import { createPluginContext, FleetPluginContext } from "./pluginContext";
import { TransactionBuilder } from "./transactionBuilder";
import { RECOMMENDED_MIN_FEE_VALUE, TransactionBuilder } from "./transactionBuilder";

describe("Plugin context", () => {
const creationHeight = 894169;
Expand Down Expand Up @@ -121,4 +121,16 @@ describe("Plugin context", () => {
expect(burnTokensMethod).not.toBeCalled();
expect(builder.burning).toBeUndefined();
});

it("Should set fee amount", () => {
builder.from(regularBoxesMock);

const payFeeMethod = vi.spyOn(builder, "payFee");
const fee = RECOMMENDED_MIN_FEE_VALUE * 3n;

context.setFee(RECOMMENDED_MIN_FEE_VALUE * 3n);

expect(builder.fee).to.be.equal(fee);
expect(payFeeMethod).toBeCalledWith(fee);
});
});
9 changes: 8 additions & 1 deletion packages/core/src/builder/pluginContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export type FleetPluginContext = {
* it will thrown a {@link NotAllowedTokenBurning} exception.
*/
burnTokens: (tokens: OneOrMore<TokenAmount<Amount>>) => void;

/**
* Set transaction fee amount
* @param amount amount in nanoergs
*/
setFee: (amount: Amount) => void;
};

export function createPluginContext(transactionBuilder: TransactionBuilder): FleetPluginContext {
Expand All @@ -53,6 +59,7 @@ export function createPluginContext(transactionBuilder: TransactionBuilder): Fle
throw new NotAllowedTokenBurning();
}
transactionBuilder.burnTokens(tokens);
}
},
setFee: (amount) => transactionBuilder.payFee(amount)
};
}

0 comments on commit b51587f

Please sign in to comment.