Skip to content

Commit

Permalink
update model
Browse files Browse the repository at this point in the history
  • Loading branch information
vol4tim committed Dec 15, 2020
1 parent d5a7f68 commit f521215
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 10 deletions.
35 changes: 26 additions & 9 deletions src/services/carbonfootprintitaly/components/Request.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<script>
import { genRosbagIpfs } from "@/utils/utils";
import { addByFile } from "../add";
import model from "../model";
export default {
props: ["model", "token", "validator", "submit", "onResponse"],
Expand All @@ -24,22 +25,38 @@ export default {
objective: null,
onResult: null,
onOffer: null,
isRun: false
isRun: false,
};
},
methods: {
async getObjective(fields) {
const payload = {};
for (let field in fields) {
const fieldHash = model.rosbag_scheme.find(
(item) => item.suffix === `/${field}_hash`
);
if (fields[field].type === "file") {
payload[field] = await addByFile(fields[field].value);
if (fieldHash) {
payload[`${field}_hash`] = payload[field];
}
} else if (fields[field].type === "files") {
payload[field] = [];
if (fieldHash) {
payload[`${field}_hash`] = [];
}
for (let name in fields[field].items) {
payload[field].push(await addByFile(fields[field].items[name]));
const hash = await addByFile(fields[field].items[name]);
payload[field].push(hash);
if (fieldHash) {
payload[`${field}_hash`].push(hash);
}
}
} else {
payload[field] = fields[field].value;
if (fieldHash) {
payload[`${field}_hash`] = fields[field].value;
}
}
}
return genRosbagIpfs(payload);
Expand All @@ -48,7 +65,7 @@ export default {
if (this.onResult) {
return;
}
this.onResult = this.$robonomics.onResult(msg => {
this.onResult = this.$robonomics.onResult((msg) => {
if (
msg.liability === this.$robonomics.account.address &&
msg.result === this.objective
Expand All @@ -57,7 +74,7 @@ export default {
this.responseError = "Energy consumption very small.";
}
});
this.onOffer = this.$robonomics.onOffer(this.model, msg => {
this.onOffer = this.$robonomics.onOffer(this.model, (msg) => {
console.log("offer", msg);
if (msg.objective === this.objective) {
this.responseError = null;
Expand All @@ -82,7 +99,7 @@ export default {
return;
}
this.getObjective(fields)
.then(objective => {
.then((objective) => {
this.listenResult();
const demand = {
model: this.model,
Expand All @@ -92,9 +109,9 @@ export default {
lighthouse: this.$robonomics.lighthouse.address,
validator: this.validator,
validatorFee: 0,
deadline: r.number + 1000
deadline: r.number + 1000,
};
this.$robonomics.sendDemand(demand, false, msg => {
this.$robonomics.sendDemand(demand, false, (msg) => {
this.objective = msg.objective;
});
})
Expand All @@ -105,7 +122,7 @@ export default {
} else {
this.isRun = false;
}
}
}
},
},
};
</script>
2 changes: 1 addition & 1 deletion src/services/carbonfootprintitaly/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
model: "QmTYzPKCge7Sw1hTotFomU2Nh6mQwihc4CcahrB1rCaFEy",
model: "QmRHLgQVJK9r9ioQHzNXgSFBvYwceWMm5EQeKUJrvR8jUW",
token: "0x668B3a6F9b6C4a2759Fa3912D0a59f39d1F0f0B0",
};
25 changes: 25 additions & 0 deletions src/services/carbonfootprintitaly/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"rosbag_type": "std_msgs/String",
"data_type": "IPFSBin"
},
{
"suffix": "/company_logo_hash",
"rosbag_type": "std_msgs/String",
"data_type": "String"
},
{
"suffix": "/company_reg_number",
"rosbag_type": "std_msgs/String",
Expand Down Expand Up @@ -64,6 +69,11 @@
"rosbag_type": "std_msgs/String",
"data_type": "IPFSBin"
},
{
"suffix": "/company_photo_hash",
"rosbag_type": "std_msgs/String",
"data_type": "String"
},
{
"suffix": "/product_registration_n",
"rosbag_type": "std_msgs/String",
Expand All @@ -84,6 +94,11 @@
"rosbag_type": "std_msgs/String",
"data_type": "IPFSBin"
},
{
"suffix": "/product_photo_hash",
"rosbag_type": "std_msgs/String",
"data_type": "String"
},
{
"suffix": "/cfp_registration_date",
"rosbag_type": "std_msgs/String",
Expand All @@ -104,6 +119,11 @@
"rosbag_type": "std_msgs/String",
"data_type": "IPFSBin"
},
{
"suffix": "/cfp_chart_hash",
"rosbag_type": "std_msgs/String",
"data_type": "String"
},
{
"suffix": "/cfp_reference_year",
"rosbag_type": "std_msgs/String",
Expand Down Expand Up @@ -189,6 +209,11 @@
"rosbag_type": "std_msgs/String",
"data_type": "IPFSBin"
},
{
"suffix": "/cfo_graph_hash",
"rosbag_type": "std_msgs/String",
"data_type": "String"
},
{
"suffix": "/cfo_verification_statement",
"rosbag_type": "std_msgs/String",
Expand Down

0 comments on commit f521215

Please sign in to comment.