|
|
|
@ -1,9 +1,9 @@
|
|
|
|
|
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 {encodeOffChainContent, makeSnakeCell} from "./utils"; |
|
|
|
|
import {AdnlAddress, encodeOffChainContent, encodeSemiChainContent, makeSnakeCell} from "./utils"; |
|
|
|
|
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 {randomAddress} from "../test/helpers"; |
|
|
|
|
import {hashCell} from "ton/dist/boc/boc"; |
|
|
|
@ -83,10 +83,28 @@ export function itemData(params: {
|
|
|
|
|
.storeUint(0, 64).endCell(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function auctionWithWinner(winnerAddress: Address) { |
|
|
|
|
return beginCell().storeAddress(winnerAddress).storeCoins(0).storeUint(0, 64) |
|
|
|
|
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]; |
|
|
|
|
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) { |
|
|
|
|
if (address == undefined) { |
|
|
|
|
address = randomAddress("collection"); |
|
|
|
@ -164,18 +182,23 @@ export function initializeItemMsg(params: { domain: String, ownerAddr: Address }
|
|
|
|
|
.endCell(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function itemContent(domain: string, zone: string): Cell { |
|
|
|
|
return encodeOffChainContent(`https://api.agorata.io/data/${zone}/${domain}.json`) |
|
|
|
|
async function itemContent(domain: string, zone: string): Promise<Cell> { |
|
|
|
|
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() |
|
|
|
|
.storeUint(0x1a0b9d51 , 32) |
|
|
|
|
.storeUint(0x1a0b9d51, 32) |
|
|
|
|
.storeUint(0, 64) |
|
|
|
|
.storeRef(itemContent(params.domain, params.zone)) |
|
|
|
|
.storeRef(await itemContent(params.domain, params.zone)) |
|
|
|
|
.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 { |
|
|
|
|
let messageToSign = beginCell().storeAddress(receiverAddress).storeAddress(issuedCollectionAddr).storeUint(amount, 256).storeRef(domain).endCell(); |
|
|
|
|
let hash = messageToSign.hash(); |
|
|
|
|