TON contracts for Agorata
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.3 KiB

2 years ago
const main = require('../contracts/main');
2 years ago
const {Address, Cell, Slice} = require("ton");
2 years ago
const {Base64} = require('@tonconnect/protocol');
const BN = require("bn.js");
const express = require('express')
2 years ago
const {get_tonclient} = require("../contracts/utils");
const {sha256} = require("ton-crypto");
const {getRecords} = require("../contracts/main");
2 years ago
const app = express()
const port = 5171
2 years ago
const debug = process.env.DEBUG === '1';
let tonclient = get_tonclient(debug);
2 years ago
2 years ago
app.use(function(err, req, res, next) {
if(!err) return next(); // you also need this line
console.log("error");
res.send("error");
});
2 years ago
app.get('/', (req, res) => {
res.send('Agorata microservice for dealing with TON')
})
app.get('/buy-message/:collection/:domain' /* the rest as get parameters: buyer, key */, (req, res) => {
let collection = Address.parse(req.params.collection);
if (req.query.buyer !== '') {
let buyer = Address.parse(req.query.buyer);
let key = Buffer.from(req.query.key, 'hex');
let signature = main.signBuy(req.params.domain, collection, buyer, key);
let msg = main.createItem({domain: req.params.domain, signature})
res.send(JSON.stringify([Base64.encode(msg.toBoc()), collection.toString()]));
} else {
let msg = main.createItem({domain: req.params.domain, signature: '0'})
res.send(JSON.stringify([Base64.encode(msg.toBoc()), collection.toString()]));
}
});
2 years ago
app.get('/content-message/:address/:zone/:domain', async (req, res) => {
let msg = await main.setContent({domain: req.params.domain, zone: req.params.zone});
2 years ago
let addr = main.getItemAddr(Address.parse(req.params.address), req.params.domain, 0);
res.send(JSON.stringify([Base64.encode(msg.toBoc()), addr.toString()]));
});
2 years ago
app.get('/address/:collection/:domain', (req, res) => {
let addr = main.getItemAddr(Address.parse(req.params.collection), req.params.domain, 0);
res.send(JSON.stringify({"address": addr.toString()}));
})
app.get('/get-records/:address', async (req, res) => {
try {
let records = await getRecords(tonclient, Address.parse(req.params.address));
res.send(JSON.stringify(records));
} catch (e) {
console.log(e);
res.send(JSON.stringify({}));
}
})
2 years ago
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})