Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let safeApp;
- async function authoriseAndConnect() {
- let appInfo = {
- name: 'Warz Test webapp',
- id: 'net.maidsafe.tutorials.web-app',
- version: '1.0.0',
- vendor: 'MaidSafe.net Ltd.'
- };
- safeApp = await window.safe.initialiseApp(appInfo);
- console.log('Authorising SAFE application...');
- const authReqUri = await safeApp.auth.genAuthUri();
- const authUri = await window.safe.authorise(authReqUri);
- console.log('SAFE application authorised by user');
- await safeApp.auth.loginFromUri(authUri);
- console.log("Application connected to the network");
- }
- let md;
- async function createMutableData() {
- console.log("Creating MutableData with initial dataset...");
- const typeTag = 15000;
- md = await safeApp.mutableData.newRandomPublic(typeTag);
- const initialData = {
- "random_key_1": JSON.stringify({
- text: 'Scotland to try Scotch whisky',
- made: false
- }),
- "random_key_2": JSON.stringify({
- text: 'Patagonia before I\'m too old',
- made: false
- })
- };
- await md.quickSetup(initialData);
- }
- async function getItems() {
- const entries = await md.getEntries();
- const entriesList = await entries.listEntries();
- const items = [];
- entriesList.forEach((entry) => {
- const value = entry.value;
- if (value.buf.length == 0) return;
- const parsedValue = JSON.parse(value.buf);
- items.push({ key: entry.key, value: parsedValue, version: value.version });
- });
- return items;
- };
- async function insertItem(key, value) {
- };
- async function updateItem(key, value, version) {
- };
- async function deleteItems(items) {
- };
- module.exports = {
- authoriseAndConnect,
- createMutableData,
- getItems,
- insertItem,
- updateItem,
- deleteItems
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement