Simple Blockchain

Hi all,

I've built the following simple blockchain:

[{"id":"458ccfaf.f3e23","type":"inject","z":"553ed51c.af9a8c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAS4AAACnCAMAAACYVkHVAAAAwFBMVEWPAAD///+JAACMAACFAADbwcH//PzGm5vVtrbx5+emV1efRUWSEhK0b2/15eXy6urNqKjOlpbCkpK0a2vl09OTHBzKoqL28PCVIyOYLS2+e3uycnL89/eAAADVs7OiS0vv3NzZvr7my8u9iYnTqKidJiayYWHWq6vnz8+6fn6iODiiMTG5gYGcOzvfubmzZWWvVFSoRUWXAACZDw/Ii4u9cnKrYGCgJCSsTk6xWlqpQ0O3e3ulNzfKj4/fycmbFhaOOVunAAAOb0lEQVR4nO2d6WLaPBaGbR1iQktMISEmjkMdyk5rCIEGMpPm/u9qDNZqyytLGND7Z+Yjsiw9lY6PjjZNU1JSUlJSOnlBLn11ab9WAK3v33LoZ+uCiUGp/+waeg4Z5nO/dKHA0MzNg4rInaGvLvlXCNlWEVq6btkXyAumxWBtdHtxvGBVsG1t29fq0uwX6hSnpeudC2tesN6Flq6vL6t5wQDXu7L8nkNLEz82uCxc2jCottNDeZx69IYt3rD61RU4qppOUO1FTiOEFsFzRusw5TpRtXCneszZqeAGP/hwmHKdovxe1VS4MgmQ5o+qb22FK10A8357aFpsWK1wxQppdsQ3VbhiBBp1mhSuVMF8EIWlcMUIxjUZLYVLKnivSGkpXDLBg0jLcYcKV7yARZkNt7t+aILy6uOF6pRWp6/5Y2qN4rpRuMKCNXFLnSnCeJo4stAt5cur1MU5nfEQm3RFq8/iD9hhNaYayiFtiiMZwy+szmEFI9ITbxgtuKfd8zqH6Kige67hQSD9Tv/gYlswcaSORUYZ/z1BXL5NruaQJl3DgLC10V3hj0jq5GfV4PSmNpB2M+i4Zma5Q6/xGakGrHAzcmYiy2ahKexAZu9o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ORK5CYII=","payloadType":"str","x":170,"y":480,"wires":[["1900752e.7aa9bb"]]},{"id":"1900752e.7aa9bb","type":"split","z":"553ed51c.af9a8c","name":"","splt":"1000","spltType":"len","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":290,"y":480,"wires":[["7774c858.794458"]]},{"id":"7774c858.794458","type":"join","z":"553ed51c.af9a8c","name":"blockchain","mode":"reduce","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"$append($A,[{\t\"index\": $I,\t\"timestamp\": $millis(), \t\t\"data\": payload,\t\t\t\t\t\"hash\" : \t\t\t(\t  $binPad:=function($n, $len){$pad($formatBase($n,2),-$len,'0')};\t  $bitwise:=function($lb, $rb, $fn){$split($lb,'')~>$map(function($c, $i){$fn($c='1',$substring($rb,$i,1)='1')?$power(2,(7-$i)):0})~>$sum()};\t  $and:=function($l,$r){$bitwise($binPad($l,8),$binPad($r,8),function($1,$2){$1 and $2})};\t  $or:=function($l,$r){$bitwise($binPad($l,8),$binPad($r,8),function($1,$2){$1 or $2})};  \t  [0..15]~>$map(function(){$floor($random()*256)})\t    ~>$map(function($v,$i){$i=6?$or($and($v,15),64):$i=8?$or($and($v,63),128):$v})\t    ~>$map(function($n,$i){$pad($formatBase($n,16),-2,'0') & ($i in [3,5,7,9]?'':'')})\t    ~>$join()\t),\t\t\t\"previousHash\" : \"GenesisNode\"\t\t\t\t\t}])","reduceInit":"[]","reduceInitType":"json","reduceFixup":"","x":430,"y":480,"wires":[["c643af25.326e2","bde6cda7.66a92"]]},{"id":"bde6cda7.66a92","type":"split","z":"553ed51c.af9a8c","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":410,"y":560,"wires":[["3fd0c7eb.457e28"]]},{"id":"3fd0c7eb.457e28","type":"switch","z":"553ed51c.af9a8c","name":"","property":"payload.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":530,"y":560,"wires":[["3d4e257f.b38e1a"],["98681b36.5589a8"]]},{"id":"3d4e257f.b38e1a","type":"change","z":"553ed51c.af9a8c","name":"GenesisBlock","rules":[{"t":"set","p":"payload.previousHash","pt":"msg","to":"GenesisBlock","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":540,"wires":[["cc57c6d3.16fc88"]]},{"id":"98681b36.5589a8","type":"change","z":"553ed51c.af9a8c","name":"previousHash","rules":[{"t":"set","p":"payload.previousHash","pt":"msg","to":"payload.hash","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":600,"wires":[["cc57c6d3.16fc88"]]},{"id":"cc57c6d3.16fc88","type":"debug","z":"553ed51c.af9a8c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":875,"y":560,"wires":[],"l":false},{"id":"c643af25.326e2","type":"debug","z":"553ed51c.af9a8c","name":"array","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":480,"wires":[]},{"id":"48cd5886.699b38","type":"comment","z":"553ed51c.af9a8c","name":"Current Blockchain ","info":"should be:\n(previousHash[i]=hash[i-1])","x":170,"y":420,"wires":[]}]

however, I'm having difficulties to complete the last part: setting the current block payload.previousHash[i] to the previous block payload.hash[i-1] like that:

I solved it hardcoded, but I know there's a much better and scalable solution.
Any help would be highly appreciated. Thanks!

If you just want to use a commercial provider, check out xooa.com they have a native Node-Red node to write to their blockchain platform.

Thanks for the tip @rgerrans, interesting.
However, it not much left to complete this simple blockchain.

Here's a working hardcoded version:

[{"id":"89c81d7c.15f1e","type":"inject","z":"eaead8cc.1a7cf8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"data:image/png;base64,iVBORw0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GhD/AjvmoVxmeSJlwKLVeUQ/pFKp+KqjTezKSUaNCg8E8TjqggBZIrrShMz2UjsWgb+SNH4l86FhUgjJRGXIot6dsVlPgg1isHF5i9whsm49LYwO0EyN8h0+CstFp1hqgZNhcYPWW9chHDp5CgxmAizP0aWuY1dcQW9LAUXcQlYJ0nBJdz8xzKn0axP/OWzCEBycx7lDLjDWiTWybJxX0ka7j40s6yti8bqGa7rtJTuPA2XeU2jemxOPw0XMUJi5hWSEzzUa4ZhdUmnpRVn13dW7Y5juPU/tJ0iulCcziZBbzE0DMMxB3bPtymh4W8iLiGQ2CHFmEZThlbghGpEcJEVOI9/W/ErcLzBaExXcX2uG202qmfxdH5qw6ODYeT/PzZzUaL+NFteEHihvBFcNbxtA+Lm1vxEGuBLqFJucDO9+1u2Gu1zXWZLzqhJgJvNj2JK2fqubY3c9q/3aCpWXG6QEOASryECBH9ogto7/Qs/cbbkq8+eZLafOBbSZAi7r678XqjkqY3QmkAf9DN9Kb3BFzY/pq8e3NYobfUg5wzJ1qb6SRgu1pAEXM5KNi3LuwTh62HhbcV+Id7+QMoreeYsabksa9MBrngKXI2S16bOeS86HRez9sJsvbGMTvovBUMiovCtGlcsRAZHkqvmAa1TWle4RgyXQc3zfnBlWfkcwkUNQmhJyWAiLilpdUPzN1dsbnH7DbiX4NJrU01cKaWNveQvY+JibHdMzNLOuOLX1Ue2LbT4NB9P/B4Hplp5whYs9crRpQ2Vj/n2774Z/7A23Zptl+ASD+15iWRTeh110ibNkjeSWIPZHPCP6bs2th/p+F0bkes4d9wTZA0+7MdHezGIWw/dqft/X8SulsNy6wv70R7Viy+rPpLU9s9cUrhySeHKJYUrl/4H531XkDXGROsAAAAASUVORK5CYII=","payloadType":"str","x":90,"y":360,"wires":[["3a20162d.9260ca"]]},{"id":"3a20162d.9260ca","type":"split","z":"eaead8cc.1a7cf8","name":"","splt":"1000","spltType":"len","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":210,"y":360,"wires":[["809ba667.674de8"]]},{"id":"809ba667.674de8","type":"join","z":"eaead8cc.1a7cf8","name":"blockchain","mode":"reduce","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"$append($A,[{\t\"index\": $I,\t\"timestamp\": $millis(), \t\t\"data\": payload,\t\t\"hash\" : \t\t(\t  $binPad:=function($n, $len){$pad($formatBase($n,2),-$len,'0')};\t  $bitwise:=function($lb, $rb, $fn){$split($lb,'')~>$map(function($c, $i){$fn($c='1',$substring($rb,$i,1)='1')?$power(2,(7-$i)):0})~>$sum()};\t  $and:=function($l,$r){$bitwise($binPad($l,8),$binPad($r,8),function($1,$2){$1 and $2})};\t  $or:=function($l,$r){$bitwise($binPad($l,8),$binPad($r,8),function($1,$2){$1 or $2})};  \t  [0..15]~>$map(function(){$floor($random()*256)})\t    ~>$map(function($v,$i){$i=6?$or($and($v,15),64):$i=8?$or($and($v,63),128):$v})\t    ~>$map(function($n,$i){$pad($formatBase($n,16),-2,'0') & ($i in [3,5,7,9]?'':'')})\t    ~>$join()\t),\t\t\t\"previousHash\" : \"GenesisBlock\"\t\t\t}])","reduceInit":"[]","reduceInitType":"json","reduceFixup":"","x":350,"y":360,"wires":[["e5f020be.b1aaf"]]},{"id":"e5f020be.b1aaf","type":"change","z":"eaead8cc.1a7cf8","name":"PrevBlock","rules":[{"t":"set","p":"payload[1].previousHash","pt":"msg","to":"payload[0].hash","tot":"msg"},{"t":"set","p":"payload[2].previousHash","pt":"msg","to":"payload[1].hash","tot":"msg"},{"t":"set","p":"payload[3].previousHash","pt":"msg","to":"payload[2].hash","tot":"msg"},{"t":"set","p":"payload[4].previousHash","pt":"msg","to":"payload[3].hash","tot":"msg"},{"t":"set","p":"payload[5].previousHash","pt":"msg","to":"payload[4].hash","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":360,"wires":[["7f1f5c35.6ab164"]]},{"id":"7f1f5c35.6ab164","type":"split","z":"eaead8cc.1a7cf8","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":650,"y":360,"wires":[["18350706.9c38b9"]]},{"id":"18350706.9c38b9","type":"debug","z":"eaead8cc.1a7cf8","name":"output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":735,"y":360,"wires":[],"l":false}]

The question is, how to change the "PrevBlock" node below into parameters, since the size of the array is unknown and varies (different sources).

Anyone? Thanks.

With a little help of function node

[{"id":"458ccfaf.f3e23","type":"inject","z":"3e015b6a.3ff654","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAS4AAACnCAMAAACYVkHVAAAAwFBMVEWPAAD///+JAACMAACFAADbwcH//PzGm5vVtrbx5+emV1efRUWSEhK0b2/15eXy6urNqKjOlpbCkpK0a2vl09OTHBzKoqL28PCVIyOYLS2+e3uycnL89/eAAADVs7OiS0vv3NzZvr7my8u9iYnTqKidJiayYWHWq6vnz8+6fn6iODiiMTG5gYGcOzvfubmzZWWvVFSoRUWXAACZDw/Ii4u9cnKrYGCgJCSsTk6xWlqpQ0O3e3ulNzfKj4/fycmbFhaOOVunAAAOb0lEQVR4nO2d6WLaPBaGbR1iQktMISEmjkMdyk5rCIEGMpPm/u9qDNZqyytLGND7Z+Yjsiw9lY6PjjZNU1JSUlJSOnlBLn11ab9WAK3v33LoZ+uCiUGp/+waeg4Z5nO/dKHA0MzNg4rInaGvLvlXCNlWEVq6btkXyAumxWBtdHtxvGBVsG1t29fq0uwX6hSnpeudC2tesN6Flq6vL6t5wQDXu7L8nkNLEz82uCxc2jCottNDeZx69IYt3rD61RU4qppOUO1FTiOEFsFzRusw5TpRtXCneszZqeAGP/hwmHKdovxe1VS4MgmQ5o+qb22FK10A8357aFpsWK1wxQppdsQ3VbhiBBp1mhSuVM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Wle4RgyXQc3zfnBlWfkcwkUNQmhJyWAiLilpdUPzN1dsbnH7DbiX4NJrU01cKaWNveQvY+JibHdMzNLOuOLX1Ue2LbT4NB9P/B4Hplp5whYs9crRpQ2Vj/n2774Z/7A23Zptl+ASD+15iWRTeh110ibNkjeSWIPZHPCP6bs2th/p+F0bkes4d9wTZA0+7MdHezGIWw/dqft/X8SulsNy6wv70R7Viy+rPpLU9s9cUrhySeHKJYUrl/4H531XkDXGROsAAAAASUVORK5CYII=","payloadType":"str","x":170,"y":1400,"wires":[["1900752e.7aa9bb"]]},{"id":"1900752e.7aa9bb","type":"split","z":"3e015b6a.3ff654","name":"","splt":"1000","spltType":"len","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":290,"y":1400,"wires":[["7774c858.794458"]]},{"id":"7774c858.794458","type":"join","z":"3e015b6a.3ff654","name":"blockchain","mode":"reduce","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"$append($A,[{\t\"index\": $I,\t\"timestamp\": $millis(), \t\t\"data\": payload,\t\t\t\t\t\"hash\" : \t\t\t(\t  $binPad:=function($n, $len){$pad($formatBase($n,2),-$len,'0')};\t  $bitwise:=function($lb, $rb, $fn){$split($lb,'')~>$map(function($c, $i){$fn($c='1',$substring($rb,$i,1)='1')?$power(2,(7-$i)):0})~>$sum()};\t  $and:=function($l,$r){$bitwise($binPad($l,8),$binPad($r,8),function($1,$2){$1 and $2})};\t  $or:=function($l,$r){$bitwise($binPad($l,8),$binPad($r,8),function($1,$2){$1 or $2})};  \t  [0..15]~>$map(function(){$floor($random()*256)})\t    ~>$map(function($v,$i){$i=6?$or($and($v,15),64):$i=8?$or($and($v,63),128):$v})\t    ~>$map(function($n,$i){$pad($formatBase($n,16),-2,'0') & ($i in [3,5,7,9]?'':'')})\t    ~>$join()\t),\t\t\t\"previousHash\" : \"GenesisNode\"\t\t\t\t\t}])","reduceInit":"[]","reduceInitType":"json","reduceFixup":"","x":430,"y":1400,"wires":[["5e86fe0b.e5316"]]},{"id":"c643af25.326e2","type":"debug","z":"3e015b6a.3ff654","name":"array","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":1220,"wires":[]},{"id":"48cd5886.699b38","type":"comment","z":"3e015b6a.3ff654","name":"Current Blockchain ","info":"should be:\n(previousHash[i]=hash[i-1])","x":170,"y":1340,"wires":[]},{"id":"5e86fe0b.e5316","type":"function","z":"3e015b6a.3ff654","name":"setPreviousHash","func":"function setPreviousHash(el,idx,arr){\n    if(idx > 0){\n        el.previousHash = arr[idx -1].hash\n    }\n}\nmsg.payload.forEach(setPreviousHash)\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":1400,"wires":[["c643af25.326e2"]]}]
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.