Skip to content

Commit

Permalink
refactor(core): encapsulates context extension
Browse files Browse the repository at this point in the history
  • Loading branch information
capt-nemo429 committed Dec 12, 2022
1 parent d24494f commit 8d0ebcd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/models/ergoUnsignedInput.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("Construction", () => {
});
});

describe("extension", () => {
describe("Tweaking", () => {
it("Should set extension", () => {
const input = new ErgoUnsignedInput(regularBoxesMock[0]);
input.setContextVars({ 0: "0402", 1: "0580c0fc82aa02" });
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/models/ergoUnsignedInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,26 @@ type InputType<T> = T extends "default" ? UnsignedInput : EIP12UnsignedInput;
type DataInputType<T> = T extends "default" ? DataInput : EIP12UnsignedDataInput;

export class ErgoUnsignedInput extends ErgoBox {
extension?: ContextExtension;
private _extension?: ContextExtension;

public get extension(): ContextExtension | undefined {
return this._extension;
}

constructor(box: Box<Amount>) {
super(box);
}

public setContextVars(extension: ContextExtension): ErgoUnsignedInput {
this.extension = extension;
this._extension = extension;

return this;
}

public toUnsignedInputObject<T extends BuildOutputType>(type: T): InputType<T> {
return {
...this.toObject(type),
extension: this.extension || {}
extension: this._extension || {}
} as InputType<T>;
}

Expand Down

0 comments on commit 8d0ebcd

Please sign in to comment.