Browse Source

Created an API

master
Lev 2 years ago
parent
commit
8a565970ee
  1. 38
      bin/api.js
  2. 1027
      package-lock.json
  3. 6
      package.json
  4. 5
      test/item.spec.ts

38
bin/api.js

@ -0,0 +1,38 @@
const main = require('../contracts/main');
const subcommand = require('subcommand');
const {Address} = require("ton");
const {keyPairFromSeed, getSecureRandomBytes, keyPairFromSecretKey} = require("ton-crypto");
const {Base64} = require('@tonconnect/protocol');
const BN = require("bn.js");
const express = require('express')
const app = express()
const port = 5171
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()]));
}
});
app.get('/content-message/:address/:zone/:domain', (req, res) => {
let msg = main.setContent({domain: req.params.domain, zone: req.params.zone});
let addr = main.getItemAddr(Address.parse(req.params.address), req.params.domain, 0);
res.send(JSON.stringify([Base64.encode(msg.toBoc()), addr.toString()]));
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})

1027
package-lock.json generated

File diff suppressed because it is too large Load Diff

6
package.json

@ -11,7 +11,8 @@
"deploy": "ts-node ./build/_deploy.ts",
"deploy:testnet": "ts-node ./build/_deploy.ts",
"postinstall": "ts-node ./build/_setup.ts",
"cli": "node --no-warnings --loader ts-node/esm bin/cli.js "
"cli": "node --no-warnings --loader ts-node/esm bin/cli.js",
"api": "node --no-warnings --loader ts-node/esm bin/api.js "
},
"devDependencies": {
"@swc/core": "^1.3.25",
@ -50,6 +51,7 @@
"@tonconnect/protocol": "^2.0.1",
"semver": "^7.3.7",
"subcommand": "^2.1.1",
"ton-compiler": "^2.0.0"
"ton-compiler": "^2.0.0",
"express": "^4.18.2"
}
}

5
test/item.spec.ts

@ -39,6 +39,9 @@ describe("Creating items tests", () => {
value: new BN(0),
});
const res = await contract.sendInternalMessage(initializeMsg);
// let nft_data = await contract.invokeGetMethod("get_nft_data", []);
// console.log(nft_data.result);
expect(res.type).to.equal("success");
expect(res.exit_code).to.equal(0);
const setDataMsg = internalMessage({
@ -49,5 +52,7 @@ describe("Creating items tests", () => {
const res2 = await contract.sendInternalMessage(setDataMsg);
expect(res2.type).to.equal("success");
expect(res2.exit_code).to.equal(0);
let nft_data = await contract.invokeGetMethod("get_nft_data", []);
console.log(nft_data.result);
});
});

Loading…
Cancel
Save