|
|
|
@ -1,7 +1,14 @@
|
|
|
|
|
import BN from "bn.js"; |
|
|
|
|
import {Cell, beginCell, Address, Slice, TonClient} from "ton"; |
|
|
|
|
import {SmartContract} from "ton-contract-executor"; |
|
|
|
|
import {AdnlAddress, encodeOffChainContent, encodeSemiChainContent, makeSnakeCell} from "./utils"; |
|
|
|
|
import { |
|
|
|
|
AdnlAddress, |
|
|
|
|
categoryToBN, |
|
|
|
|
decodeOffChainContent, |
|
|
|
|
encodeOffChainContent, |
|
|
|
|
encodeSemiChainContent, |
|
|
|
|
makeSnakeCell |
|
|
|
|
} from "./utils"; |
|
|
|
|
import {randomBytes} from "crypto"; |
|
|
|
|
import {keyPairFromSeed, KeyPair, sign, keyPairFromSecretKey, sha256} from "ton-crypto"; |
|
|
|
|
import { hex as item_code } from "../build/nft-item.compiled.json"; |
|
|
|
@ -84,24 +91,38 @@ export function itemData(params: {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export async function getRecords(tonclient: TonClient, address: Address) { |
|
|
|
|
let ans_wallet = (await tonclient.callGetMethod(address, 'dnsresolve', |
|
|
|
|
[["tvm.Slice", "te6cckEBAQEAAwAAAgDTZ9xB"], |
|
|
|
|
["num", new BN(await sha256('wallet')).toString()]])).stack[1]; |
|
|
|
|
let wallet = null; |
|
|
|
|
if (ans_wallet[1].bytes !== undefined) { |
|
|
|
|
wallet = Cell.fromBoc(Buffer.from(ans_wallet[1].bytes, 'base64'))[0]; |
|
|
|
|
} |
|
|
|
|
let ans_site = (await tonclient.callGetMethod(address, 'dnsresolve', |
|
|
|
|
[["tvm.Slice", "te6cckEBAQEAAwAAAgDTZ9xB"], |
|
|
|
|
["num", new BN(await sha256('site')).toString()]])).stack[1]; |
|
|
|
|
try { |
|
|
|
|
let ans_wallet = (await tonclient.callGetMethod(address, 'dnsresolve', |
|
|
|
|
[["tvm.Slice", "te6cckEBAQEAAwAAAgDTZ9xB"], |
|
|
|
|
["num", new BN(await sha256('wallet')).toString()]])).stack[1]; |
|
|
|
|
if (ans_wallet[1].bytes !== undefined) { |
|
|
|
|
wallet = Cell.fromBoc(Buffer.from(ans_wallet[1].bytes, 'base64'))[0].beginParse().readAddress(); |
|
|
|
|
} |
|
|
|
|
} catch (e) {} |
|
|
|
|
let site = null; |
|
|
|
|
if (ans_site[1].bytes !== undefined) { |
|
|
|
|
let site_data = ans_site[1].bytes; // object.data.b64;
|
|
|
|
|
// print site_data converted from base64
|
|
|
|
|
let c = Cell.fromBoc(Buffer.from(site_data, 'base64'))[0]; |
|
|
|
|
site = new AdnlAddress(c.bits.buffer.subarray(2, 2 + 32)).toHex(); |
|
|
|
|
try { |
|
|
|
|
let ans_site = (await tonclient.callGetMethod(address, 'dnsresolve', |
|
|
|
|
[["tvm.Slice", "te6cckEBAQEAAwAAAgDTZ9xB"], |
|
|
|
|
["num", new BN(await sha256('site')).toString()]])).stack[1]; |
|
|
|
|
if (ans_site[1].bytes !== undefined) { |
|
|
|
|
let site_data = ans_site[1].bytes; // object.data.b64;
|
|
|
|
|
// print site_data converted from base64
|
|
|
|
|
let c = Cell.fromBoc(Buffer.from(site_data, 'base64'))[0]; |
|
|
|
|
site = new AdnlAddress(c.bits.buffer.subarray(2, 2 + 32)).toHex(); |
|
|
|
|
} |
|
|
|
|
} catch (e) {} |
|
|
|
|
let uri = null; |
|
|
|
|
try { |
|
|
|
|
let ans_uri = (await tonclient.callGetMethod(address, 'dnsresolve', |
|
|
|
|
[["tvm.Slice", "te6cckEBAQEAAwAAAgDTZ9xB"], |
|
|
|
|
["num", new BN(await sha256('uri')).toString()]])).stack[1]; |
|
|
|
|
uri = Buffer.from(ans_uri[1].bytes, 'base64').toString(); |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(e); |
|
|
|
|
console.log((await tonclient.callGetMethod(address, 'get_nft_data')).stack[4]); |
|
|
|
|
} |
|
|
|
|
return {wallet, site}; |
|
|
|
|
return {wallet, site, uri}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -159,6 +180,31 @@ export function TON(): number {
|
|
|
|
|
return 1000000000; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export async function changeRecordMsg(category: string, value: Cell | null) { |
|
|
|
|
let cell = beginCell() |
|
|
|
|
.storeUint(0x4eb1f0f9, 32) |
|
|
|
|
.storeUint(0, 64) |
|
|
|
|
.storeUint(new BN(await categoryToBN(category)), 256); |
|
|
|
|
if (value) { |
|
|
|
|
cell.storeRef(value); |
|
|
|
|
} |
|
|
|
|
return cell.endCell(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export async function AdnlRecord(site: AdnlAddress) { |
|
|
|
|
return beginCell() |
|
|
|
|
.storeUint(0xad01, 16) |
|
|
|
|
.storeBuffer(<Buffer>site.bytes) |
|
|
|
|
.storeUint(0, 8).endCell(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export async function WalletRecord(wallet: Address) { |
|
|
|
|
return beginCell() |
|
|
|
|
.storeUint(0x9fd3, 16) |
|
|
|
|
.storeAddress(wallet) |
|
|
|
|
.storeUint(0, 8).endCell(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// message encoders for all ops (see contracts/imports/constants.fc for consts)
|
|
|
|
|
|
|
|
|
|
export function transferOwnership(params: { newOwnerAddress: Address }): Cell { |
|
|
|
@ -187,11 +233,12 @@ async function itemContent(domain: string, zone: string): Promise<Cell> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export async function setContent(params: { domain: string, zone: string }) { |
|
|
|
|
return beginCell() |
|
|
|
|
.storeUint(0x1a0b9d51, 32) |
|
|
|
|
.storeUint(0, 64) |
|
|
|
|
.storeRef(await itemContent(params.domain, params.zone)) |
|
|
|
|
.endCell(); |
|
|
|
|
// return beginCell()
|
|
|
|
|
// .storeUint(0x1a0b9d51, 32)
|
|
|
|
|
// .storeUint(0, 64)
|
|
|
|
|
// .storeRef(await itemContent(params.domain, params.zone))
|
|
|
|
|
// .endCell();
|
|
|
|
|
return changeRecordMsg("uri", beginCell().storeBuffer(Buffer.from(`https://api.agorata.io/data/${params.zone}/${params.domain}.json`)).endCell()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function loadRecords(map_cell: Cell) { |
|
|
|
|