Asimpleimplemetatioofblockchai
Thisprojectaimstocreateasimpleimplemetatioofblockchaicoceptaddemostrateitiauserfriedlyway.
DesigCoceptThisprojectcosistsoftwomaiparts:agetaditerface.
AgetAagetstadsforoepeerwhichisabletostoreadmieblocksitheetwork.EveryagetiscoectedtoalltheotheragetsitheetworktocostructaP2Pdistributedetwork.Thebasicfuctiosforaagetare:
Sedmessagetootheragets,iordertobroadcastitsewlymiedblockReceivemessagefromotheragets,iordertoreceiveblocksmiedbyotheragetsMie,validateadgrowblocksoitsowbloackchaiSyclatestblockchaiwithotheragetsThealgorithmformiigisthekeyofablockchai.IthisprojectweolyuseSHA256hashtosimulatethemiigprocedure.
IterfaceAiterfaceimplemetedwithSprigbootisicludedithisprojecttodemostratetheusageoftheblockchai.Itmightmakepeoplefeellikeacetralizedmaagemetiterface,howeverweeedtouderstadthatagetscaalsoruidepedetly.TheiterfaceisRESTfuladallreturdataisijsoformat.Asiglepageapplicatioisalsoprovidedtovisualizetheblockchaicoceptiabetterway.
QuickStartStartserverNavigatetoprojectrootdiradstarttheserver:
$gradlebootRuUsewebiterfaceOpehttps://localhost:8080/ibrowseradtryitfromwebpage.Basicactiosare:
AddaagettotheetworkDeleteaagetfromtheetworkMieaewblockadbroadcasttotheetwork.Acolorschemeisusedtomarkdifferetblockscreatedbydifferetagets.UserestiterfaceUsecurldirectlyfromcommadlietoiteractwiththeserver:
Createewagetcurl-XPOST"https://localhost:8080/aget?ame=A1&port=1001"{"ame":"A1","port":1001,"blockchai":[{"idex":0,"timestamp":1502193341671,"hash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480","previousHash":"ROOT_HASH"}]}curl-XPOST"https://localhost:8080/aget?ame=A2&port=1002"{"ame":"A2","port":1002,"blockchai":[{"idex":0,"timestamp":1502193341671,"hash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480","previousHash":"ROOT_HASH"}]}curl-XPOST"https://localhost:8080/aget?ame=A3&port=1003"{"ame":"A3","port":1003,"blockchai":[{"idex":0,"timestamp":1502193341671,"hash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480","previousHash":"ROOT_HASH"}]}Mieblockcurl-XPOST"https://localhost:8080/aget/mie?aget=A1"{"idex":1,"timestamp":1502194172250,"hash":"2461f27f811df15a969391c70f136869a282224e8cc6fe8b628d16a499515d21","previousHash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480"}curl-XPOST"https://localhost:8080/mie?ame=A3"{"timestamp":1502194200235,"status":404,"error":"NotFoud","message":"Nomessageavailable","path":"/mie"}Showagetsadblockscurlhttps://localhost:8080/aget?ame=A1{"ame":"A1","port":1001,"blockchai":[{"idex":0,"timestamp":1502193341671,"hash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480","previousHash":"ROOT_HASH"},{"idex":1,"timestamp":1502194172250,"hash":"2461f27f811df15a969391c70f136869a282224e8cc6fe8b628d16a499515d21","previousHash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480"}]}curlhttps://localhost:8080/aget?ame=A3{"ame":"A3","port":1003,"blockchai":[{"idex":0,"timestamp":1502193341671,"hash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480","previousHash":"ROOT_HASH"},{"idex":1,"timestamp":1502194172250,"hash":"2461f27f811df15a969391c70f136869a282224e8cc6fe8b628d16a499515d21","previousHash":"4f99b67b06b6831886815ffe66a55be2e34dcefdfc16b6214710313062a8a480"}]}curlhttps://localhost:8080/aget/allRemoveagetcurl-XDELETEhttps://localhost:8080/aget/allChagelog20170902Letewlyaddedagetsycthelatestblockchaifrompeers.20170818Addawebiterface.20170807Serversidecodebasewithrestiterface.Thisprojectisispiredbyaivechai.











评论