git ssb

0+

dangerousbeans / etherstreams



Commit af32cadfb1a2994216b270d57bb27f903c7d2700

load videos from contract

Joran committed on 9/25/2017, 12:11:17 AM
Parent: a4ceac2a5698bd9cc07554a4396dd267897781d5

Files changed

build/contracts/EtherStream.jsonchanged
build/contracts/Migrations.jsonchanged
build/contracts/SimpleStorage.jsondeleted
contracts/EtherStream.solchanged
src/components/VideoList.vuechanged
src/main.jschanged
src/store/videos.jschanged
src/util/getweb3.jsadded
test/unit/specs/simplestorage.jsdeleted
test/unit/specs/etherstreams.jsadded
test/TestSimpleStorage.soldeleted
test/TestEtherStream.soladded
build/contracts/EtherStream.jsonView
@@ -1,30 +1,35 @@
11 {
22 "contract_name": "EtherStream",
33 "abi": [
44 {
5- "constant": false,
6- "inputs": [
5 + "constant": true,
6 + "inputs": [],
7 + "name": "content_count",
8 + "outputs": [
79 {
8- "name": "x",
10 + "name": "",
911 "type": "uint256"
1012 }
1113 ],
12- "name": "set",
13- "outputs": [],
1414 "payable": false,
1515 "type": "function"
1616 },
1717 {
1818 "constant": true,
19- "inputs": [],
20- "name": "get",
21- "outputs": [
19 + "inputs": [
2220 {
2321 "name": "",
2422 "type": "uint256"
2523 }
2624 ],
25 + "name": "streams",
26 + "outputs": [
27 + {
28 + "name": "",
29 + "type": "address"
30 + }
31 + ],
2732 "payable": false,
2833 "type": "function"
2934 },
3035 {
@@ -34,27 +39,85 @@
3439 "name": "",
3540 "type": "uint256"
3641 }
3742 ],
38- "name": "videos",
43 + "name": "content",
3944 "outputs": [
4045 {
41- "name": "",
46 + "name": "title",
4247 "type": "string"
48 + },
49 + {
50 + "name": "uri",
51 + "type": "string"
52 + },
53 + {
54 + "name": "love",
55 + "type": "uint256"
56 + },
57 + {
58 + "name": "creator",
59 + "type": "address"
4360 }
4461 ],
4562 "payable": false,
4663 "type": "function"
64 + },
65 + {
66 + "constant": false,
67 + "inputs": [
68 + {
69 + "name": "_title",
70 + "type": "string"
71 + },
72 + {
73 + "name": "_uri",
74 + "type": "string"
75 + }
76 + ],
77 + "name": "newContent",
78 + "outputs": [
79 + {
80 + "name": "content_id",
81 + "type": "uint256"
82 + }
83 + ],
84 + "payable": false,
85 + "type": "function"
86 + },
87 + {
88 + "constant": true,
89 + "inputs": [],
90 + "name": "stream_count",
91 + "outputs": [
92 + {
93 + "name": "",
94 + "type": "uint256"
95 + }
96 + ],
97 + "payable": false,
98 + "type": "function"
99 + },
100 + {
101 + "inputs": [],
102 + "payable": false,
103 + "type": "constructor"
47104 }
48105 ],
49- "unlinked_binary": "0x6060604052341561000f57600080fd5b5b6102168061001f6000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166360fe47b181146100535780636d4ce63c1461006b578063e6821bf514610090575b600080fd5b341561005e57600080fd5b61006960043561011e565b005b341561007657600080fd5b61007e610127565b60405190815260200160405180910390f35b341561009b57600080fd5b6100a660043561012e565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156100e35780820151818401525b6020016100ca565b50505050905090810190601f1680156101105780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60008190555b50565b6000545b90565b600180548290811061013c57fe5b906000526020600020900160005b915090508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101e25780601f106101b7576101008083540402835291602001916101e2565b820191906000526020600020905b8154815290600101906020018083116101c557829003601f168201915b5050505050815600a165627a7a723058200053b54c7a167fb62808d48e447e1155ebf654f45f97da2462dc12c66684cb930029",
106 + "unlinked_binary": "0x606060405260006001556000600355341561001957600080fd5b5b6100c16040805190810160405280600681526020017f53696e74656c000000000000000000000000000000000000000000000000000081525060606040519081016040908152603c82527f6d61676e65743a3f78743d75726e3a627469683a30386164613561376136313860208301527f3361616531653039643833316466363734386435363630393561313000000000908201526401000000006103656100c882021704565b505b6102c8565b6000805481906100db826001830161015d565b91506000828154811015156100ec57fe5b906000526020600020906004020160005b5090508084805161011292916020019061018f565b506001810183805161012892916020019061018f565b50600160028201819055600382018054600160a060020a03191633600160a060020a03161790558054810190555b5092915050565b81548183558181151161018957600402816004028360005260206000209182019101610189919061020e565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106101d057805160ff19168380011785556101fd565b828001600101855582156101fd579182015b828111156101fd5782518255916020019190600101906101e2565b5b5061020a92915061025f565b5090565b61025c91905b8082111561020a5760006102288282610280565b610236600183016000610280565b5060006002820155600381018054600160a060020a0319169055600401610214565b5090565b90565b61025c91905b8082111561020a5760008155600101610265565b5090565b90565b50805460018160011615610100020316600290046000825580601f106102a657506102c4565b601f0160209004906000526020600020908101906102c4919061025f565b5b50565b6105be806102d76000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166302336692811461006957806364d60d911461008e578063baa0b806146100cd578063d27a0c441461020b578063d6be24f7146102b0575b600080fd5b341561007457600080fd5b61007c6102d5565b60405190815260200160405180910390f35b341561009957600080fd5b6100a46004356102db565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390f35b34156100d857600080fd5b6100e360043561031a565b6040516040810183905273ffffffffffffffffffffffffffffffffffffffff8216606082015260808082528554600260001961010060018416150201909116049082018190528190602082019060a0830190889080156101845780601f1061015957610100808354040283529160200191610184565b820191906000526020600020905b81548152906001019060200180831161016757829003601f168201915b50508381038252865460026000196101006001841615020190911604808252602090910190879080156101f85780601f106101cd576101008083540402835291602001916101f8565b820191906000526020600020905b8154815290600101906020018083116101db57829003601f168201915b5050965050505050505060405180910390f35b341561021657600080fd5b61007c60046024813581810190830135806020601f8201819004810201604051908101604052818152929190602084018383808284378201915050505050509190803590602001908201803590602001908080601f01602080910402602001604051908101604052818152929190602084018383808284375094965061036595505050505050565b60405190815260200160405180910390f35b34156102bb57600080fd5b61007c610414565b60405190815260200160405180910390f35b60015481565b60028054829081106102e957fe5b906000526020600020900160005b915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080548290811061032857fe5b906000526020600020906004020160005b5060028101546003820154919250600183019173ffffffffffffffffffffffffffffffffffffffff1684565b600080548190610378826001830161041a565b915060008281548110151561038957fe5b906000526020600020906004020160005b509050808480516103af92916020019061044c565b50600181018380516103c592916020019061044c565b5060016002820181905560038201805473ffffffffffffffffffffffffffffffffffffffff19163373ffffffffffffffffffffffffffffffffffffffff161790558054810190555b5092915050565b60035481565b8154818355818115116104465760040281600402836000526020600020918201910161044691906104cb565b5b505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061048d57805160ff19168380011785556104ba565b828001600101855582156104ba579182015b828111156104ba57825182559160200191906001019061049f565b5b506104c7929150610529565b5090565b61052691905b808211156104c75760006104e5828261054a565b6104f360018301600061054a565b506000600282015560038101805473ffffffffffffffffffffffffffffffffffffffff191690556004016104d1565b5090565b90565b61052691905b808211156104c7576000815560010161052f565b5090565b90565b50805460018160011615610100020316600290046000825580601f10610570575061058e565b601f01602090049060005260206000209081019061058e9190610529565b5b505600a165627a7a72305820b4291767f40d940bfbbea1669fb97451f183e20675ba72ae7532a44205c69dc50029",
50107 "networks": {
51108 "1505969715555": {
52109 "events": {},
53110 "links": {},
111 + "address": "0x14850c3b3ee407a643aa44186c69e02500206b41",
112 + "updated_at": 1506290994306
113 + },
114 + "1506292646185": {
115 + "events": {},
116 + "links": {},
54117 "address": "0x4dac1b2cd8269570153e1f864aafcceba5fd590e",
55- "updated_at": 1505969724240
118 + "updated_at": 1506292657900
56119 }
57120 },
58121 "schema_version": "0.0.5",
59- "updated_at": 1506059253139
122 + "updated_at": 1506292657900
60123 }
build/contracts/Migrations.jsonView
@@ -69,11 +69,17 @@
6969 },
7070 "1505969715555": {
7171 "events": {},
7272 "links": {},
73 + "address": "0x0b551cddba621280cb11b709bdaabea3ad54bc5a",
74 + "updated_at": 1506290994305
75 + },
76 + "1506292646185": {
77 + "events": {},
78 + "links": {},
7379 "address": "0x4a41c35347dfb18d835b688885f40d6f7a84b95e",
74- "updated_at": 1505969724240
80 + "updated_at": 1506292657900
7581 }
7682 },
7783 "schema_version": "0.0.5",
78- "updated_at": 1505969724240
84 + "updated_at": 1506292657900
7985 }
build/contracts/SimpleStorage.jsonView
@@ -1,42 +1,0 @@
1-{
2- "contract_name": "EtherStream",
3- "abi": [
4- {
5- "constant": false,
6- "inputs": [
7- {
8- "name": "x",
9- "type": "uint256"
10- }
11- ],
12- "name": "set",
13- "outputs": [],
14- "payable": false,
15- "type": "function"
16- },
17- {
18- "constant": true,
19- "inputs": [],
20- "name": "get",
21- "outputs": [
22- {
23- "name": "",
24- "type": "uint256"
25- }
26- ],
27- "payable": false,
28- "type": "function"
29- }
30- ],
31- "unlinked_binary": "0x6060604052341561000f57600080fd5b5b60b98061001e6000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166360fe47b1811460465780636d4ce63c14605b575b600080fd5b3415605057600080fd5b6059600435607d565b005b3415606557600080fd5b606b6086565b60405190815260200160405180910390f35b60008190555b50565b6000545b905600a165627a7a72305820e890e81d6a072060a90ae180a111f545656602bd4af5e763513faccd6092fc9b0029",
32- "networks": {
33- "1505537959578": {
34- "events": {},
35- "links": {},
36- "address": "0x8423fc0596c5c815d4c179e2c9883b99d74ea538",
37- "updated_at": 1505696275575
38- }
39- },
40- "schema_version": "0.0.5",
41- "updated_at": 1505696275575
42-}
contracts/EtherStream.solView
@@ -1,15 +1,40 @@
11 pragma solidity ^0.4.2;
22
33 contract EtherStream {
4- uint storedData;
4 + // Content in this stream
5 + Content[] public content;
6 + uint public content_count = 0;
57
6- string[] public videos;
8 + // Substream contracts
9 + address[] public streams;
10 + uint public stream_count = 0;
711
8- function set(uint x) {
9- storedData = x;
12 + struct Content {
13 + string title;
14 + string uri;
15 + uint love;
16 + address creator;
1017 }
1118
12- function get() constant returns (uint) {
13- return storedData;
19 + function EtherStream ()
20 + {
21 + // Starter content
22 + newContent("Sintel", "magnet:?xt=urn:btih:08ada5a7a6183aae1e09d831df6748d566095a10");
1423 }
24 +
25 + // Add new content
26 + function newContent(string _title, string _uri) returns (uint content_id) {
27 + Content memory c;
28 +
29 + c.title = _title;
30 + c.uri = _uri;
31 + c.love = 1;
32 + c.creator = msg.sender;
33 +
34 + content.push(c);
35 + content_count++;
36 +
37 + return content_count;
38 + }
39 +
1540 }
src/components/VideoList.vueView
@@ -12,10 +12,8 @@
1212
1313 <div class="row">
1414 <VideoPreview v-for="c in ContentStore.state.content" :video="c">
1515 </VideoPreview>
16-
17-
1816 </div>
1917 </div>
2018 </template>
2119
src/main.jsView
@@ -10,13 +10,26 @@
1010
1111 Vue.config.productionTip = false
1212
1313
14 +// ContentStore
15 +import ContentStore from './store/videos'
16 +
1417 Vue.use(BootstrapVue);
1518
19 +
1620 /* eslint-disable no-new */
1721 new Vue({
1822 el: '#app',
1923 router,
2024 template: '<App/>',
21- components: { App }
25 + components: { App },
26 + props: [ 'web3' ],
27 + methods: {
28 +
29 + },
30 +
31 + created: function () {
32 + // Establish Ethereum connection on create
33 + ContentStore.getWeb3()
34 + }
2235 })
src/store/videos.jsView
@@ -1,10 +1,54 @@
1 +import EtherStreamContract from '../../build/contracts/EtherStream.json'
2 +import getWeb3 from './../util/getweb3'
3 +
14 export default {
25 state: {
3- content: [
4-
5- ]
6 + web3: null,
7 + stream_contract: null,
8 + stream_instance: null,
9 + count: 0,
10 + content: [ ]
611 },
12 + getWeb3(){
13 + console.log("getWeb3")
14 + getWeb3
15 + .then(results => {
16 + this.state.web3 = results.web3
17 + this.instantiateContract()
18 + })
19 + },
20 + instantiateContract() {
21 + const contract = require('truffle-contract')
22 + const etherStreams = contract(EtherStreamContract)
23 + etherStreams.setProvider(this.state.web3.currentProvider)
24 +
25 + // Get accounts.
26 + this.state.web3.eth.getAccounts((error, accounts) => {
27 + etherStreams.deployed().then((instance) => {
28 + // debugger
29 + console.log(Object.getOwnPropertyNames(instance))
30 + return this.state.stream_instance = instance
31 + }).then((result) => {
32 + // Get the value from the contract to prove it worked.
33 + return this.state.stream_instance.content_count.call(accounts[0])
34 + }).then((result) => {
35 + console.log(result)
36 +
37 + return this.state.count = [ result.c[0] ]
38 + }).then((result) => {
39 +
40 + for(var i = 0; i < this.state.count; i++)
41 + {
42 + console.log("loading content")
43 + this.state.stream_instance.content(i).then((result) => {
44 + console.log(result)
45 + this.addContent({ title: result[0], magnet: result[1], love: Number(result[2]), creator: result[3] })
46 + })
47 + }
48 + })
49 + })
50 + },
751 addContent (content) {
8- this.state.content.push({content, date: Date.now()})
52 + this.state.content.push(content)
953 }
1054 }
src/util/getweb3.jsView
@@ -1,0 +1,38 @@
1 +import Web3 from 'web3'
2 +
3 +let getWeb3 = new Promise(function(resolve, reject) {
4 + // Wait for loading completion to avoid race conditions with web3 injection timing.
5 + window.addEventListener('load', function() {
6 + var results
7 + var web3 = window.web3
8 +
9 + // Checking if Web3 has been injected by the browser (Mist/MetaMask)
10 + if (typeof web3 !== 'undefined') {
11 + // Use Mist/MetaMask's provider.
12 + web3 = new Web3(web3.currentProvider)
13 +
14 + results = {
15 + web3: web3
16 + }
17 +
18 + console.log('Injected web3 detected.');
19 +
20 + resolve(results)
21 + } else {
22 + // Fallback to localhost if no web3 injection.
23 + var provider = new Web3.providers.HttpProvider('http://localhost:8545')
24 +
25 + web3 = new Web3(provider)
26 +
27 + results = {
28 + web3: web3
29 + }
30 +
31 + console.log('No web3 instance injected, using Local web3.');
32 +
33 + resolve(results)
34 + }
35 + })
36 +})
37 +
38 +export default getWeb3
test/unit/specs/simplestorage.jsView
@@ -1,20 +1,0 @@
1-// import Vue from 'vue'
2-// import Hello from '@/components/Hello'
3-
4-var EtherStream = artifacts.require("./EtherStream.sol");
5-
6-contract('EtherStream', function(accounts) {
7-
8- it("...should store the value 89.", function() {
9- return EtherStream.deployed().then(function(instance) {
10- EtherStreamInstance = instance;
11-
12- return EtherStreamInstance.set(89, {from: accounts[0]});
13- }).then(function() {
14- return EtherStreamInstance.get.call();
15- }).then(function(storedData) {
16- assert.equal(storedData, 89, "The value 89 was not stored.");
17- });
18- });
19-
20-});
test/unit/specs/etherstreams.jsView
@@ -1,0 +1,19 @@
1 +var EtherStream = artifacts.require("./EtherStream.sol");
2 +
3 +contract('EtherStream', function(accounts) {
4 +
5 + it("...should store the value 89.", function() {
6 + return EtherStream.deployed().then(function(instance) {
7 + etherStreamInstance = instance;
8 +
9 + // debugger
10 +
11 + return etherStreamInstance.newContent("Sentinel", "magnet:blahblah", {from: accounts[0]});
12 + }).then(function() {
13 + return etherStreamInstance.get.call();
14 + }).then(function(storedData) {
15 + assert.equal(storedData, 89, "The value 89 was not stored.");
16 + });
17 + });
18 +
19 +});
test/TestSimpleStorage.solView
@@ -1,19 +1,0 @@
1-pragma solidity ^0.4.2;
2-
3-import "truffle/Assert.sol";
4-import "truffle/DeployedAddresses.sol";
5-import "../contracts/EtherStream.sol";
6-
7-contract TestEtherStream {
8-
9- function testItStoresAValue() {
10- EtherStream etherStream = EtherStream(DeployedAddresses.EtherStream());
11-
12- etherStream.set(89);
13-
14- uint expected = 89;
15-
16- Assert.equal(etherStream.get(), expected, "It should store the value 89.");
17- }
18-
19-}
test/TestEtherStream.solView
@@ -1,0 +1,19 @@
1 +pragma solidity ^0.4.2;
2 +
3 +import "truffle/Assert.sol";
4 +import "truffle/DeployedAddresses.sol";
5 +import "../contracts/EtherStream.sol";
6 +
7 +contract TestEtherStream {
8 +
9 + function testItStoresAValue() {
10 + EtherStream etherStream = EtherStream(DeployedAddresses.EtherStream());
11 +
12 + etherStream.newContent("Sentinel", "magnet:blahblah");
13 +
14 + string expected = "Sentinel";
15 +
16 + /*Assert.equal(etherStream.getstream_content(0), expected, "It should store the title.");*/
17 + }
18 +
19 +}

Built with git-ssb-web