Skip to content

Commit

Permalink
added asNativeToken fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Brord van Wierst committed Nov 22, 2023
1 parent 14817a1 commit 1be4f7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions bindings/nodejs/lib/types/block/output/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ class NativeTokenFeature extends Feature {
this.id = nativeToken.id;
this.amount = nativeToken.amount;
}

/**
* Returns the native token contained in this feature.
*/
public asNativeToken(): INativeToken {
return {
id: this.id,
amount: this.amount,
};
}
}

/**
Expand Down
5 changes: 3 additions & 2 deletions bindings/nodejs/lib/types/block/output/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { HexEncodedString, NumericString, u64 } from '../../utils';
import { TokenScheme, TokenSchemeDiscriminator } from './token-scheme';
import { AccountId, NftId, AnchorId, DelegationId } from '../id';
import { EpochIndex } from '../../block/slot';
import { INativeToken } from '../../models/native-token';

export type OutputId = HexEncodedString;

Expand Down Expand Up @@ -126,14 +127,14 @@ abstract class CommonOutput extends Output {
/**
* The native token held by the output.
*/
getNativeToken(): NativeTokenFeature | undefined {
getNativeToken(): INativeToken | undefined {
if (!this.features) {
return undefined;
}

for (const feature of this.features) {
if (feature instanceof NativeTokenFeature) {
return feature as NativeTokenFeature;
return (feature as NativeTokenFeature).asNativeToken();
}
}
return undefined;
Expand Down

0 comments on commit 1be4f7e

Please sign in to comment.