@mysten/sui
Version:
Sui TypeScript API(Work in Progress)
47 lines (46 loc) • 1.49 kB
JavaScript
import { normalizeSuiAddress } from "../utils/sui-types.js";
function extractMutableReference(normalizedType) {
return typeof normalizedType === "object" && "MutableReference" in normalizedType ? normalizedType.MutableReference : void 0;
}
function extractReference(normalizedType) {
return typeof normalizedType === "object" && "Reference" in normalizedType ? normalizedType.Reference : void 0;
}
function extractStructTag(normalizedType) {
if (typeof normalizedType === "object" && "Struct" in normalizedType) {
return normalizedType;
}
const ref = extractReference(normalizedType);
const mutRef = extractMutableReference(normalizedType);
if (typeof ref === "object" && "Struct" in ref) {
return ref;
}
if (typeof mutRef === "object" && "Struct" in mutRef) {
return mutRef;
}
return void 0;
}
function getIdFromCallArg(arg) {
if (typeof arg === "string") {
return normalizeSuiAddress(arg);
}
if (arg.Object) {
if (arg.Object.ImmOrOwnedObject) {
return normalizeSuiAddress(arg.Object.ImmOrOwnedObject.objectId);
}
if (arg.Object.Receiving) {
return normalizeSuiAddress(arg.Object.Receiving.objectId);
}
return normalizeSuiAddress(arg.Object.SharedObject.objectId);
}
if (arg.UnresolvedObject) {
return normalizeSuiAddress(arg.UnresolvedObject.objectId);
}
return void 0;
}
export {
extractMutableReference,
extractReference,
extractStructTag,
getIdFromCallArg
};
//# sourceMappingURL=utils.js.map