引谈 | 使用IPFS、IOTA构建的智能回收系统
Filecoin进度,最新动态
2020年2月14日


-
工厂将把所有的笔记本电脑数据和id发送到我们的系统,以保存在我们的系统上。(id将是访问每台笔记本电脑的关键)
-
所有笔记本电脑都将以如下状态被保存:未找到,由用户A找到,在垃圾桶B中找到

-
所有笔记本电脑将有NFC标签来编写其ID。
-
现在消费者将扫描他想回收的笔记本电脑。扫描笔记本后,API调用会将使用者设置为回收笔记本的所有者。

-
当消费者把他的笔记本电脑扔进我们的垃圾箱,他就会得到代币作为奖励。


app.route(‘/init’)
.get(recycler.init);
exports.init = async (req,res) =>{
const response = await manageClients.init()
-
res.json('DB initialized with some clients with root',response )
}
const init = async()=>
-
{
products['HELLODRAYMANRNFELVTJREBCXJETCFEUGXBZHEGHCJHIYIFPQEQGDXILJZYUQMOYSELXIG9KUYOSYBFAY'] = {
'name':'product01',
'address':'HELLODRAYMANRNFELVTJREBCXJETCFEUGXBZHEGHCJHIYIFPQEQGDXILJZYUQMOYSELXIG9KUYOSYBFAY',
'owner':false,
'producer':'client01'
}
-
products['AB9CCUACOSC9VHQQFSVUGOVLAGNYJYDPROPBYTZIGNVOF9KMFNXBMSUGFFA9HTVHBPKPGGIBGSRJPUXZK'] = {
'name':'product02',
'address':'AB9CCUACOSC9VHQQFSVUGOVLAGNYJYDPROPBYTZIGNVOF9KMFNXBMSUGFFA9HTVHBPKPGGIBGSRJPUXZK',
'owner':false,
'producer':'client01'
}
products['LHSQELEGSRM9IAQCUBPXOLYXDMFOAPNJFS9JPOJBSRUDJAIRTWHTZCJCFLVYVRJPGPNXEWDDRGTCGKRAB'] = {
'name':'product03',
'address':'LHSQELEGSRM9IAQCUBPXOLYXDMFOAPNJFS9JPOJBSRUDJAIRTWHTZCJCFLVYVRJPGPNXEWDDRGTCGKRAB',
'owner':false,
'producer':'client01'
}
const ipfsHash = await addIPFS.execute(products)
const root = await mamManage.send(ipfsHash)
return root
}
app.route('/addClient')
.post(recycler.addClient);
exports.addClient = async (req,res) =>{
const response = await manageClients.addNewClient(req.body.root,req.body.products)
res.json("added new client succefuly "+response)
}
const addNewClient = async (_root,_products)=>{
const currentPropretiesRoot = _root
const currentPropretiesHash = await mamManage.fetch(currentPropretiesRoot)
const currentPropretiesString = await catIPFS.execute(getLastHash(currentPropretiesHash))
const currentPropretiesJSON = JSON.parse(currentPropretiesString)
const productsJSON = JSON.parse(JSON.stringify(_products))
for(let i = 0; i < productsJSON.length;i++){
-
currentPropretiesJSON[productsJSON[i].address] = productsJSON[i]
}
const newPropretiesHash = await addIPFS.execute(currentPropretiesJSON)
const newPropretiesRoot = await mamManage.send(newPropretiesHash)
-
return newPropretiesRoot
}
app.route('/addOwner')
.post(recycler.addOwner);
-
exports.addOwner = async (req,res) =>{
const response = await manageClients.addNewOwner(req.body.root,req.body.productAddress,req.body.ownerAddress)
res.json("added new owner "+ response)
}
const addNewOwner = async(_root,productAddress,ownerAddress)=>{
const proprietiesHash = await mamManage.fetch(_root)
const currentPropretiesString = await catIPFS.execute(getLastHash(proprietiesHash))
const currentPropretiesJSON = JSON.parse(currentPropretiesString)
-
currentPropretiesJSON[productAddress].owner = ownerAddress
const newPropretiesHash = await addIPFS.execute(currentPropretiesJSON)
const root = await mamManage.send(newPropretiesHash)
return root
}
app.route('/giveReward').post(recycler.giveReward);
exports.giveReward = async (req,res) =>{const response = await giveReward.execute(req.body.root,req.body.productAddress)res.json(response)}
const sendToken = require('./sendToken')
const fetchToMap = require('./fetchToMap')
-
giveRewards = async(root,productAddress) =>{
const OwnerAddrress = await fetchToMap.execute(root)
console.log(OwnerAddrress[productAddress].owner)
await sendToken.execute(OwnerAddrress[productAddress].owner,1)
return "Send 1 i. Congrats"
}
/End.


原创文章,作者:IPFSforce,如若转载,请注明出处:https://ipfser.org/2020/02/11/ipfsiotagoujianzhinenghuishouxitong/
本文来源于互联网:引谈 | 使用IPFS、IOTA构建的智能回收系统