-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core)!: move parseAssetId and createAssetId from util.assetI…
…d to coreToCml and cmlToCore BREAKING CHANGE: - parseAssetId was moved from util.assetId.ts to coreToCml.ts - createAssetId was moved from util.assetId.ts to cmlToCore.ts
- Loading branch information
1 parent
c7e64d0
commit d649e02
Showing
6 changed files
with
50 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,10 @@ | ||
import { AssetId, AssetName, PolicyId } from '../../Cardano/types/Asset'; | ||
import { CML } from '../../CML/CML'; | ||
import { bytesToHex } from '../../util/misc/bytesToHex'; | ||
|
||
export const policyIdFromAssetId = (assetId: AssetId): PolicyId => PolicyId(assetId.slice(0, 56)); | ||
export const assetNameFromAssetId = (assetId: AssetId): AssetName => AssetName(assetId.slice(56)); | ||
|
||
/** | ||
* @returns {string} concatenated hex-encoded policy id and asset name | ||
*/ | ||
export const createAssetId = (scriptHash: CML.ScriptHash, assetName: CML.AssetName): AssetId => | ||
AssetId(bytesToHex(scriptHash.to_bytes()) + bytesToHex(assetName.name())); | ||
|
||
/** | ||
* @returns {AssetId} concatenated policy id and asset name | ||
*/ | ||
export const assetIdFromPolicyAndName = (policyId: PolicyId, assetName: AssetName): AssetId => | ||
AssetId(policyId + assetName); | ||
|
||
export const parseAssetId = (assetId: AssetId) => { | ||
const policyId = policyIdFromAssetId(assetId); | ||
const assetName = assetNameFromAssetId(assetId); | ||
return { | ||
assetName: CML.AssetName.new(Buffer.from(assetName, 'hex')), | ||
scriptHash: CML.ScriptHash.from_bytes(Buffer.from(policyId, 'hex')) | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters