{"version":3,"file":"updateRecord.cjs","sources":["../../../src/bindings/updateRecord.ts"],"sourcesContent":["import { Address, IInstruction } from \"@solana/kit\";\r\n\r\nimport {\r\n  CENTRAL_STATE_DOMAIN_RECORDS,\r\n  NAME_PROGRAM_ADDRESS,\r\n  RECORDS_PROGRAM_ADDRESS,\r\n  SYSTEM_PROGRAM_ADDRESS,\r\n} from \"../constants/addresses\";\r\nimport { getDomainAddress } from \"../domain/getDomainAddress\";\r\nimport { InvalidParentError } from \"../errors\";\r\nimport { updateRecordInstruction } from \"../instructions/updateRecordInstruction\";\r\nimport { Record, RecordVersion } from \"../types/record\";\r\nimport { serializeRecordContent } from \"../utils/serializers/serializeRecordContent\";\r\n\r\ninterface UpdateRecordParams {\r\n  domain: string;\r\n  record: Record;\r\n  content: string;\r\n  owner: Address;\r\n  payer: Address;\r\n}\r\n\r\n/**\r\n * Updates an existing record under the specified domain.\r\n *\r\n * @param params - An object containing the following properties:\r\n *   - `domain`: The domain under which the record resides.\r\n *   - `record`: An enumeration representing the type of record to be updated.\r\n *   - `content`: The updated content to be associated with the record.\r\n *   - `owner`: The address of the domain's owner.\r\n *   - `payer`: The address funding the record update.\r\n * @returns A promise that resolves to the update record instruction.\r\n */\r\nexport const updateRecord = async ({\r\n  domain,\r\n  record,\r\n  content,\r\n  owner,\r\n  payer,\r\n}: UpdateRecordParams): Promise<IInstruction> => {\r\n  let { domainAddress, isSub, parentAddress } = await getDomainAddress({\r\n    domain: `${record}.${domain}`,\r\n    record: RecordVersion.V2,\r\n  });\r\n\r\n  if (isSub) {\r\n    parentAddress = (await getDomainAddress({ domain })).domainAddress;\r\n  }\r\n\r\n  if (!parentAddress) {\r\n    throw new InvalidParentError(\"Parent could not be found\");\r\n  }\r\n\r\n  const ix = new updateRecordInstruction({\r\n    record: `\\x02${record}`,\r\n    content: serializeRecordContent({ content, record }),\r\n  }).getInstruction(\r\n    RECORDS_PROGRAM_ADDRESS,\r\n    SYSTEM_PROGRAM_ADDRESS,\r\n    NAME_PROGRAM_ADDRESS,\r\n    payer,\r\n    domainAddress,\r\n    parentAddress,\r\n    owner,\r\n    CENTRAL_STATE_DOMAIN_RECORDS\r\n  );\r\n\r\n  return ix;\r\n};\r\n"],"names":["async","domain","record","content","owner","payer","domainAddress","isSub","parentAddress","getDomainAddress","RecordVersion","V2","InvalidParentError","updateRecordInstruction","serializeRecordContent","getInstruction","RECORDS_PROGRAM_ADDRESS","SYSTEM_PROGRAM_ADDRESS","NAME_PROGRAM_ADDRESS","CENTRAL_STATE_DOMAIN_RECORDS"],"mappings":"4SAiC4BA,OAC1BC,SACAC,OAAAA,EACAC,UACAC,QACAC,YAEA,IAAIC,cAAEA,EAAaC,MAAEA,EAAKC,cAAEA,SAAwBC,EAAAA,iBAAiB,CACnER,OAAQ,GAAGC,KAAUD,IACrBC,OAAQQ,EAAaA,cAACC,KAOxB,GAJIJ,IACFC,SAAuBC,EAAAA,iBAAiB,CAAER,YAAWK,gBAGlDE,EACH,MAAM,IAAII,EAAkBA,mBAAC,6BAiB/B,OAdW,IAAIC,0BAAwB,CACrCX,OAAQ,IAAOA,IACfC,QAASW,EAAsBA,uBAAC,CAAEX,UAAOD,OAAEA,MAC1Ca,eACDC,EAAuBA,wBACvBC,yBACAC,EAAAA,qBACAb,EACAC,EACAE,EACAJ,EACAe,+BAGO"}