|
|
@ -1,9 +1,9 @@ |
|
|
|
import BN from "bn.js"; |
|
|
|
import BN from "bn.js"; |
|
|
|
import {Cell, beginCell, Address} from "ton"; |
|
|
|
import {Cell, beginCell, Address, Slice, TonClient} from "ton"; |
|
|
|
import {SmartContract} from "ton-contract-executor"; |
|
|
|
import {SmartContract} from "ton-contract-executor"; |
|
|
|
import {encodeOffChainContent, makeSnakeCell} from "./utils"; |
|
|
|
import {AdnlAddress, encodeOffChainContent, encodeSemiChainContent, makeSnakeCell} from "./utils"; |
|
|
|
import {randomBytes} from "crypto"; |
|
|
|
import {randomBytes} from "crypto"; |
|
|
|
import {keyPairFromSeed, KeyPair, sign, keyPairFromSecretKey} from "ton-crypto"; |
|
|
|
import {keyPairFromSeed, KeyPair, sign, keyPairFromSecretKey, sha256} from "ton-crypto"; |
|
|
|
import { hex as item_code } from "../build/nft-item.compiled.json"; |
|
|
|
import { hex as item_code } from "../build/nft-item.compiled.json"; |
|
|
|
import {randomAddress} from "../test/helpers"; |
|
|
|
import {randomAddress} from "../test/helpers"; |
|
|
|
import {hashCell} from "ton/dist/boc/boc"; |
|
|
|
import {hashCell} from "ton/dist/boc/boc"; |
|
|
@ -83,9 +83,27 @@ export function itemData(params: { |
|
|
|
.storeUint(0, 64).endCell(); |
|
|
|
.storeUint(0, 64).endCell(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function auctionWithWinner(winnerAddress: Address) { |
|
|
|
export async function getRecords(tonclient: TonClient, address: Address) { |
|
|
|
return beginCell().storeAddress(winnerAddress).storeCoins(0).storeUint(0, 64) |
|
|
|
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]; |
|
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return {wallet, site}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function setContractBalance(contract: SmartContract, balance: number, address?: Address) { |
|
|
|
export function setContractBalance(contract: SmartContract, balance: number, address?: Address) { |
|
|
|
if (address == undefined) { |
|
|
|
if (address == undefined) { |
|
|
@ -164,18 +182,23 @@ export function initializeItemMsg(params: { domain: String, ownerAddr: Address } |
|
|
|
.endCell(); |
|
|
|
.endCell(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function itemContent(domain: string, zone: string): Cell { |
|
|
|
async function itemContent(domain: string, zone: string): Promise<Cell> { |
|
|
|
return encodeOffChainContent(`https://api.agorata.io/data/${zone}/${domain}.json`) |
|
|
|
return await encodeSemiChainContent(`https://api.agorata.io/data/${zone}/${domain}.json`) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function setContent(params: { domain: string, zone: string }) { |
|
|
|
export async function setContent(params: { domain: string, zone: string }) { |
|
|
|
return beginCell() |
|
|
|
return beginCell() |
|
|
|
.storeUint(0x1a0b9d51, 32) |
|
|
|
.storeUint(0x1a0b9d51, 32) |
|
|
|
.storeUint(0, 64) |
|
|
|
.storeUint(0, 64) |
|
|
|
.storeRef(itemContent(params.domain, params.zone)) |
|
|
|
.storeRef(await itemContent(params.domain, params.zone)) |
|
|
|
.endCell(); |
|
|
|
.endCell(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function loadRecords(map_cell: Cell) { |
|
|
|
|
|
|
|
let map_sl = map_cell.beginParse(); |
|
|
|
|
|
|
|
map_sl |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function instantBuySignature(receiverAddress: Address, issuedCollectionAddr: Address, amount: number, domain: Cell, privateKey: Buffer): Buffer { |
|
|
|
export function instantBuySignature(receiverAddress: Address, issuedCollectionAddr: Address, amount: number, domain: Cell, privateKey: Buffer): Buffer { |
|
|
|
let messageToSign = beginCell().storeAddress(receiverAddress).storeAddress(issuedCollectionAddr).storeUint(amount, 256).storeRef(domain).endCell(); |
|
|
|
let messageToSign = beginCell().storeAddress(receiverAddress).storeAddress(issuedCollectionAddr).storeUint(amount, 256).storeRef(domain).endCell(); |
|
|
|
let hash = messageToSign.hash(); |
|
|
|
let hash = messageToSign.hash(); |
|
|
|