Skip to content

Commit

Permalink
set user data
Browse files Browse the repository at this point in the history
  • Loading branch information
leecchh committed Dec 17, 2024
1 parent cce9dce commit 0c0b136
Showing 1 changed file with 39 additions and 35 deletions.
74 changes: 39 additions & 35 deletions sdk/src/suins-transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,11 +478,11 @@ export class SuinsTransaction {
};

setTargetAddress({
nft,
nft, // Can be string or argument
address,
isSubname,
}: {
nft: TransactionObjectArgument;
nft: any;
address?: string;
isSubname?: boolean;
}) {
Expand All @@ -491,13 +491,15 @@ export class SuinsTransaction {
if (isSubname && !this.suinsClient.config.tempSubdomainsProxyPackageId)
throw new Error('Subnames proxy package ID not found');

const nftObject = typeof nft === 'string' ? this.transaction.object(nft) : nft;

this.transaction.moveCall({
target: isSubname
? `${this.suinsClient.config.tempSubdomainsProxyPackageId}::subdomain_proxy::set_target_address`
: `${this.suinsClient.config.utils.packageId}::direct_setup::set_target_address`,
arguments: [
this.transaction.object(this.suinsClient.config.suins),
nft,
nftObject,
this.transaction.pure(bcs.option(bcs.Address).serialize(address).toBytes()),
this.transaction.object(SUI_CLOCK_OBJECT_ID),
],
Expand Down Expand Up @@ -574,38 +576,40 @@ export class SuinsTransaction {
});
}

// setUserData({
// nft,
// value,
// key,
// isSubname,
// }: {
// nft: ObjectArgument;
// value: string;
// key: string;
// isSubname?: boolean;
// }) {
// if (!this.suinsClient.config.suins) throw new Error('SuiNS Object ID not found');
// if (!isSubname && !this.suinsClient.config.utilsPackageId)
// throw new Error('Utils package ID not found');
// if (isSubname && !this.suinsClient.config.tempSubNamesProxyPackageId)
// throw new Error('Subnames proxy package ID not found');

// if (!Object.values(ALLOWED_METADATA).some((x) => x === key)) throw new Error('Invalid key');

// this.transaction.moveCall({
// target: isSubname
// ? `${this.#suinsClient.constants.tempSubNamesProxyPackageId}::subdomain_proxy::set_user_data`
// : `${this.#suinsClient.constants.utilsPackageId}::direct_setup::set_user_data`,
// arguments: [
// this.transaction.object(this.#suinsClient.constants.suinsObjectId),
// this.transaction.object(nft),
// this.transaction.pure.string(key),
// this.transaction.pure.string(value),
// this.transaction.object(SUI_CLOCK_OBJECT_ID),
// ],
// });
// }
setUserData({
nft,
value,
key,
isSubname,
}: {
nft: any;
value: string;
key: string;
isSubname?: boolean;
}) {
if (!this.suinsClient.config.suins) throw new Error('SuiNS Object ID not found');
if (!isSubname && !this.suinsClient.config.utils?.packageId)
throw new Error('Utils package ID not found');
if (isSubname && !this.suinsClient.config.tempSubdomainsProxyPackageId)
throw new Error('Subnames proxy package ID not found');

const nftObject = typeof nft === 'string' ? this.transaction.object(nft) : nft;

if (!Object.values(ALLOWED_METADATA).some((x) => x === key)) throw new Error('Invalid key');

this.transaction.moveCall({
target: isSubname
? `${this.suinsClient.config.tempSubdomainsProxyPackageId}::subdomain_proxy::set_user_data`
: `${this.suinsClient.config.utils?.packageId}::direct_setup::set_user_data`,
arguments: [
this.transaction.object(this.suinsClient.config.suins),
nftObject,
this.transaction.pure.string(key),
this.transaction.pure.string(value),
this.transaction.object(SUI_CLOCK_OBJECT_ID),
],
});
}

/**
* Burns an expired NFT to collect storage rebates.
Expand Down

0 comments on commit 0c0b136

Please sign in to comment.