ethereum_js.go 176 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package jsre
  17. const Web3_JS = `
  18. require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  19. /*
  20. This file is part of ethereum.js.
  21. ethereum.js is free software: you can redistribute it and/or modify
  22. it under the terms of the GNU Lesser General Public License as published by
  23. the Free Software Foundation, either version 3 of the License, or
  24. (at your option) any later version.
  25. ethereum.js is distributed in the hope that it will be useful,
  26. but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. GNU Lesser General Public License for more details.
  29. You should have received a copy of the GNU Lesser General Public License
  30. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  31. */
  32. /**
  33. * @file coder.js
  34. * @author Marek Kotewicz <marek@ethdev.com>
  35. * @date 2015
  36. */
  37. var BigNumber = require('bignumber.js');
  38. var utils = require('../utils/utils');
  39. var f = require('./formatters');
  40. var SolidityParam = require('./param');
  41. /**
  42. * Should be used to check if a type is an array type
  43. *
  44. * @method isArrayType
  45. * @param {String} type
  46. * @return {Bool} true is the type is an array, otherwise false
  47. */
  48. var isArrayType = function (type) {
  49. return type.slice(-2) === '[]';
  50. };
  51. /**
  52. * SolidityType prototype is used to encode/decode solidity params of certain type
  53. */
  54. var SolidityType = function (config) {
  55. this._name = config.name;
  56. this._match = config.match;
  57. this._mode = config.mode;
  58. this._inputFormatter = config.inputFormatter;
  59. this._outputFormatter = config.outputFormatter;
  60. };
  61. /**
  62. * Should be used to determine if this SolidityType do match given type
  63. *
  64. * @method isType
  65. * @param {String} name
  66. * @return {Bool} true if type match this SolidityType, otherwise false
  67. */
  68. SolidityType.prototype.isType = function (name) {
  69. if (this._match === 'strict') {
  70. return this._name === name || (name.indexOf(this._name) === 0 && name.slice(this._name.length) === '[]');
  71. } else if (this._match === 'prefix') {
  72. // TODO better type detection!
  73. return name.indexOf(this._name) === 0;
  74. }
  75. };
  76. /**
  77. * Should be used to transform plain param to SolidityParam object
  78. *
  79. * @method formatInput
  80. * @param {Object} param - plain object, or an array of objects
  81. * @param {Bool} arrayType - true if a param should be encoded as an array
  82. * @return {SolidityParam} encoded param wrapped in SolidityParam object
  83. */
  84. SolidityType.prototype.formatInput = function (param, arrayType) {
  85. if (utils.isArray(param) && arrayType) { // TODO: should fail if this two are not the same
  86. var self = this;
  87. return param.map(function (p) {
  88. return self._inputFormatter(p);
  89. }).reduce(function (acc, current) {
  90. return acc.combine(current);
  91. }, f.formatInputInt(param.length)).withOffset(32);
  92. }
  93. return this._inputFormatter(param);
  94. };
  95. /**
  96. * Should be used to transoform SolidityParam to plain param
  97. *
  98. * @method formatOutput
  99. * @param {SolidityParam} byteArray
  100. * @param {Bool} arrayType - true if a param should be decoded as an array
  101. * @return {Object} plain decoded param
  102. */
  103. SolidityType.prototype.formatOutput = function (param, arrayType) {
  104. if (arrayType) {
  105. // let's assume, that we solidity will never return long arrays :P
  106. var result = [];
  107. var length = new BigNumber(param.dynamicPart().slice(0, 64), 16);
  108. for (var i = 0; i < length * 64; i += 64) {
  109. result.push(this._outputFormatter(new SolidityParam(param.dynamicPart().substr(i + 64, 64))));
  110. }
  111. return result;
  112. }
  113. return this._outputFormatter(param);
  114. };
  115. /**
  116. * Should be used to slice single param from bytes
  117. *
  118. * @method sliceParam
  119. * @param {String} bytes
  120. * @param {Number} index of param to slice
  121. * @param {String} type
  122. * @returns {SolidityParam} param
  123. */
  124. SolidityType.prototype.sliceParam = function (bytes, index, type) {
  125. if (this._mode === 'bytes') {
  126. return SolidityParam.decodeBytes(bytes, index);
  127. } else if (isArrayType(type)) {
  128. return SolidityParam.decodeArray(bytes, index);
  129. }
  130. return SolidityParam.decodeParam(bytes, index);
  131. };
  132. /**
  133. * SolidityCoder prototype should be used to encode/decode solidity params of any type
  134. */
  135. var SolidityCoder = function (types) {
  136. this._types = types;
  137. };
  138. /**
  139. * This method should be used to transform type to SolidityType
  140. *
  141. * @method _requireType
  142. * @param {String} type
  143. * @returns {SolidityType}
  144. * @throws {Error} throws if no matching type is found
  145. */
  146. SolidityCoder.prototype._requireType = function (type) {
  147. var solidityType = this._types.filter(function (t) {
  148. return t.isType(type);
  149. })[0];
  150. if (!solidityType) {
  151. throw Error('invalid solidity type!: ' + type);
  152. }
  153. return solidityType;
  154. };
  155. /**
  156. * Should be used to transform plain param of given type to SolidityParam
  157. *
  158. * @method _formatInput
  159. * @param {String} type of param
  160. * @param {Object} plain param
  161. * @return {SolidityParam}
  162. */
  163. SolidityCoder.prototype._formatInput = function (type, param) {
  164. return this._requireType(type).formatInput(param, isArrayType(type));
  165. };
  166. /**
  167. * Should be used to encode plain param
  168. *
  169. * @method encodeParam
  170. * @param {String} type
  171. * @param {Object} plain param
  172. * @return {String} encoded plain param
  173. */
  174. SolidityCoder.prototype.encodeParam = function (type, param) {
  175. return this._formatInput(type, param).encode();
  176. };
  177. /**
  178. * Should be used to encode list of params
  179. *
  180. * @method encodeParams
  181. * @param {Array} types
  182. * @param {Array} params
  183. * @return {String} encoded list of params
  184. */
  185. SolidityCoder.prototype.encodeParams = function (types, params) {
  186. var self = this;
  187. var solidityParams = types.map(function (type, index) {
  188. return self._formatInput(type, params[index]);
  189. });
  190. return SolidityParam.encodeList(solidityParams);
  191. };
  192. /**
  193. * Should be used to decode bytes to plain param
  194. *
  195. * @method decodeParam
  196. * @param {String} type
  197. * @param {String} bytes
  198. * @return {Object} plain param
  199. */
  200. SolidityCoder.prototype.decodeParam = function (type, bytes) {
  201. return this.decodeParams([type], bytes)[0];
  202. };
  203. /**
  204. * Should be used to decode list of params
  205. *
  206. * @method decodeParam
  207. * @param {Array} types
  208. * @param {String} bytes
  209. * @return {Array} array of plain params
  210. */
  211. SolidityCoder.prototype.decodeParams = function (types, bytes) {
  212. var self = this;
  213. return types.map(function (type, index) {
  214. var solidityType = self._requireType(type);
  215. var p = solidityType.sliceParam(bytes, index, type);
  216. return solidityType.formatOutput(p, isArrayType(type));
  217. });
  218. };
  219. var coder = new SolidityCoder([
  220. new SolidityType({
  221. name: 'address',
  222. match: 'strict',
  223. mode: 'value',
  224. inputFormatter: f.formatInputInt,
  225. outputFormatter: f.formatOutputAddress
  226. }),
  227. new SolidityType({
  228. name: 'bool',
  229. match: 'strict',
  230. mode: 'value',
  231. inputFormatter: f.formatInputBool,
  232. outputFormatter: f.formatOutputBool
  233. }),
  234. new SolidityType({
  235. name: 'int',
  236. match: 'prefix',
  237. mode: 'value',
  238. inputFormatter: f.formatInputInt,
  239. outputFormatter: f.formatOutputInt,
  240. }),
  241. new SolidityType({
  242. name: 'uint',
  243. match: 'prefix',
  244. mode: 'value',
  245. inputFormatter: f.formatInputInt,
  246. outputFormatter: f.formatOutputUInt
  247. }),
  248. new SolidityType({
  249. name: 'bytes',
  250. match: 'strict',
  251. mode: 'bytes',
  252. inputFormatter: f.formatInputDynamicBytes,
  253. outputFormatter: f.formatOutputDynamicBytes
  254. }),
  255. new SolidityType({
  256. name: 'bytes',
  257. match: 'prefix',
  258. mode: 'value',
  259. inputFormatter: f.formatInputBytes,
  260. outputFormatter: f.formatOutputBytes
  261. }),
  262. new SolidityType({
  263. name: 'string',
  264. match: 'strict',
  265. mode: 'bytes',
  266. inputFormatter: f.formatInputString,
  267. outputFormatter: f.formatOutputString
  268. }),
  269. new SolidityType({
  270. name: 'real',
  271. match: 'prefix',
  272. mode: 'value',
  273. inputFormatter: f.formatInputReal,
  274. outputFormatter: f.formatOutputReal
  275. }),
  276. new SolidityType({
  277. name: 'ureal',
  278. match: 'prefix',
  279. mode: 'value',
  280. inputFormatter: f.formatInputReal,
  281. outputFormatter: f.formatOutputUReal
  282. })
  283. ]);
  284. module.exports = coder;
  285. },{"../utils/utils":7,"./formatters":2,"./param":3,"bignumber.js":"bignumber.js"}],2:[function(require,module,exports){
  286. /*
  287. This file is part of ethereum.js.
  288. ethereum.js is free software: you can redistribute it and/or modify
  289. it under the terms of the GNU Lesser General Public License as published by
  290. the Free Software Foundation, either version 3 of the License, or
  291. (at your option) any later version.
  292. ethereum.js is distributed in the hope that it will be useful,
  293. but WITHOUT ANY WARRANTY; without even the implied warranty of
  294. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  295. GNU Lesser General Public License for more details.
  296. You should have received a copy of the GNU Lesser General Public License
  297. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  298. */
  299. /**
  300. * @file formatters.js
  301. * @author Marek Kotewicz <marek@ethdev.com>
  302. * @date 2015
  303. */
  304. var BigNumber = require('bignumber.js');
  305. var utils = require('../utils/utils');
  306. var c = require('../utils/config');
  307. var SolidityParam = require('./param');
  308. /**
  309. * Formats input value to byte representation of int
  310. * If value is negative, return it's two's complement
  311. * If the value is floating point, round it down
  312. *
  313. * @method formatInputInt
  314. * @param {String|Number|BigNumber} value that needs to be formatted
  315. * @returns {SolidityParam}
  316. */
  317. var formatInputInt = function (value) {
  318. var padding = c.ETH_PADDING * 2;
  319. BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);
  320. var result = utils.padLeft(utils.toTwosComplement(value).round().toString(16), padding);
  321. return new SolidityParam(result);
  322. };
  323. /**
  324. * Formats input bytes
  325. *
  326. * @method formatInputBytes
  327. * @param {String}
  328. * @returns {SolidityParam}
  329. */
  330. var formatInputBytes = function (value) {
  331. var result = utils.padRight(utils.toHex(value).substr(2), 64);
  332. return new SolidityParam(result);
  333. };
  334. /**
  335. * Formats input bytes
  336. *
  337. * @method formatDynamicInputBytes
  338. * @param {String}
  339. * @returns {SolidityParam}
  340. */
  341. var formatInputDynamicBytes = function (value) {
  342. var result = utils.toHex(value).substr(2);
  343. var length = result.length / 2;
  344. var l = Math.floor((result.length + 63) / 64);
  345. var result = utils.padRight(result, l * 64);
  346. return new SolidityParam(formatInputInt(length).value + result, 32);
  347. };
  348. /**
  349. * Formats input value to byte representation of string
  350. *
  351. * @method formatInputString
  352. * @param {String}
  353. * @returns {SolidityParam}
  354. */
  355. var formatInputString = function (value) {
  356. var result = utils.fromAscii(value).substr(2);
  357. var length = result.length / 2;
  358. var l = Math.floor((result.length + 63) / 64);
  359. result = utils.padRight(result, l * 64);
  360. return new SolidityParam(formatInputInt(length).value + result, 32);
  361. };
  362. /**
  363. * Formats input value to byte representation of bool
  364. *
  365. * @method formatInputBool
  366. * @param {Boolean}
  367. * @returns {SolidityParam}
  368. */
  369. var formatInputBool = function (value) {
  370. var result = '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0');
  371. return new SolidityParam(result);
  372. };
  373. /**
  374. * Formats input value to byte representation of real
  375. * Values are multiplied by 2^m and encoded as integers
  376. *
  377. * @method formatInputReal
  378. * @param {String|Number|BigNumber}
  379. * @returns {SolidityParam}
  380. */
  381. var formatInputReal = function (value) {
  382. return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128)));
  383. };
  384. /**
  385. * Check if input value is negative
  386. *
  387. * @method signedIsNegative
  388. * @param {String} value is hex format
  389. * @returns {Boolean} true if it is negative, otherwise false
  390. */
  391. var signedIsNegative = function (value) {
  392. return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1';
  393. };
  394. /**
  395. * Formats right-aligned output bytes to int
  396. *
  397. * @method formatOutputInt
  398. * @param {SolidityParam} param
  399. * @returns {BigNumber} right-aligned output bytes formatted to big number
  400. */
  401. var formatOutputInt = function (param) {
  402. var value = param.staticPart() || "0";
  403. // check if it's negative number
  404. // it it is, return two's complement
  405. if (signedIsNegative(value)) {
  406. return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);
  407. }
  408. return new BigNumber(value, 16);
  409. };
  410. /**
  411. * Formats right-aligned output bytes to uint
  412. *
  413. * @method formatOutputUInt
  414. * @param {SolidityParam}
  415. * @returns {BigNumeber} right-aligned output bytes formatted to uint
  416. */
  417. var formatOutputUInt = function (param) {
  418. var value = param.staticPart() || "0";
  419. return new BigNumber(value, 16);
  420. };
  421. /**
  422. * Formats right-aligned output bytes to real
  423. *
  424. * @method formatOutputReal
  425. * @param {SolidityParam}
  426. * @returns {BigNumber} input bytes formatted to real
  427. */
  428. var formatOutputReal = function (param) {
  429. return formatOutputInt(param).dividedBy(new BigNumber(2).pow(128));
  430. };
  431. /**
  432. * Formats right-aligned output bytes to ureal
  433. *
  434. * @method formatOutputUReal
  435. * @param {SolidityParam}
  436. * @returns {BigNumber} input bytes formatted to ureal
  437. */
  438. var formatOutputUReal = function (param) {
  439. return formatOutputUInt(param).dividedBy(new BigNumber(2).pow(128));
  440. };
  441. /**
  442. * Should be used to format output bool
  443. *
  444. * @method formatOutputBool
  445. * @param {SolidityParam}
  446. * @returns {Boolean} right-aligned input bytes formatted to bool
  447. */
  448. var formatOutputBool = function (param) {
  449. return param.staticPart() === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false;
  450. };
  451. /**
  452. * Should be used to format output bytes
  453. *
  454. * @method formatOutputBytes
  455. * @param {SolidityParam} left-aligned hex representation of string
  456. * @returns {String} hex string
  457. */
  458. var formatOutputBytes = function (param) {
  459. return '0x' + param.staticPart();
  460. };
  461. /**
  462. * Should be used to format output bytes
  463. *
  464. * @method formatOutputDynamicBytes
  465. * @param {SolidityParam} left-aligned hex representation of string
  466. * @returns {String} hex string
  467. */
  468. var formatOutputDynamicBytes = function (param) {
  469. var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2;
  470. return '0x' + param.dynamicPart().substr(64, length);
  471. };
  472. /**
  473. * Should be used to format output string
  474. *
  475. * @method formatOutputString
  476. * @param {SolidityParam} left-aligned hex representation of string
  477. * @returns {String} ascii string
  478. */
  479. var formatOutputString = function (param) {
  480. var length = (new BigNumber(param.dynamicPart().slice(0, 64), 16)).toNumber() * 2;
  481. return utils.toAscii(param.dynamicPart().substr(64, length));
  482. };
  483. /**
  484. * Should be used to format output address
  485. *
  486. * @method formatOutputAddress
  487. * @param {SolidityParam} right-aligned input bytes
  488. * @returns {String} address
  489. */
  490. var formatOutputAddress = function (param) {
  491. var value = param.staticPart();
  492. return "0x" + value.slice(value.length - 40, value.length);
  493. };
  494. module.exports = {
  495. formatInputInt: formatInputInt,
  496. formatInputBytes: formatInputBytes,
  497. formatInputDynamicBytes: formatInputDynamicBytes,
  498. formatInputString: formatInputString,
  499. formatInputBool: formatInputBool,
  500. formatInputReal: formatInputReal,
  501. formatOutputInt: formatOutputInt,
  502. formatOutputUInt: formatOutputUInt,
  503. formatOutputReal: formatOutputReal,
  504. formatOutputUReal: formatOutputUReal,
  505. formatOutputBool: formatOutputBool,
  506. formatOutputBytes: formatOutputBytes,
  507. formatOutputDynamicBytes: formatOutputDynamicBytes,
  508. formatOutputString: formatOutputString,
  509. formatOutputAddress: formatOutputAddress
  510. };
  511. },{"../utils/config":5,"../utils/utils":7,"./param":3,"bignumber.js":"bignumber.js"}],3:[function(require,module,exports){
  512. /*
  513. This file is part of ethereum.js.
  514. ethereum.js is free software: you can redistribute it and/or modify
  515. it under the terms of the GNU Lesser General Public License as published by
  516. the Free Software Foundation, either version 3 of the License, or
  517. (at your option) any later version.
  518. ethereum.js is distributed in the hope that it will be useful,
  519. but WITHOUT ANY WARRANTY; without even the implied warranty of
  520. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  521. GNU Lesser General Public License for more details.
  522. You should have received a copy of the GNU Lesser General Public License
  523. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  524. */
  525. /**
  526. * @file param.js
  527. * @author Marek Kotewicz <marek@ethdev.com>
  528. * @date 2015
  529. */
  530. var utils = require('../utils/utils');
  531. /**
  532. * SolidityParam object prototype.
  533. * Should be used when encoding, decoding solidity bytes
  534. */
  535. var SolidityParam = function (value, offset) {
  536. this.value = value || '';
  537. this.offset = offset; // offset in bytes
  538. };
  539. /**
  540. * This method should be used to get length of params's dynamic part
  541. *
  542. * @method dynamicPartLength
  543. * @returns {Number} length of dynamic part (in bytes)
  544. */
  545. SolidityParam.prototype.dynamicPartLength = function () {
  546. return this.dynamicPart().length / 2;
  547. };
  548. /**
  549. * This method should be used to create copy of solidity param with different offset
  550. *
  551. * @method withOffset
  552. * @param {Number} offset length in bytes
  553. * @returns {SolidityParam} new solidity param with applied offset
  554. */
  555. SolidityParam.prototype.withOffset = function (offset) {
  556. return new SolidityParam(this.value, offset);
  557. };
  558. /**
  559. * This method should be used to combine solidity params together
  560. * eg. when appending an array
  561. *
  562. * @method combine
  563. * @param {SolidityParam} param with which we should combine
  564. * @param {SolidityParam} result of combination
  565. */
  566. SolidityParam.prototype.combine = function (param) {
  567. return new SolidityParam(this.value + param.value);
  568. };
  569. /**
  570. * This method should be called to check if param has dynamic size.
  571. * If it has, it returns true, otherwise false
  572. *
  573. * @method isDynamic
  574. * @returns {Boolean}
  575. */
  576. SolidityParam.prototype.isDynamic = function () {
  577. return this.value.length > 64 || this.offset !== undefined;
  578. };
  579. /**
  580. * This method should be called to transform offset to bytes
  581. *
  582. * @method offsetAsBytes
  583. * @returns {String} bytes representation of offset
  584. */
  585. SolidityParam.prototype.offsetAsBytes = function () {
  586. return !this.isDynamic() ? '' : utils.padLeft(utils.toTwosComplement(this.offset).toString(16), 64);
  587. };
  588. /**
  589. * This method should be called to get static part of param
  590. *
  591. * @method staticPart
  592. * @returns {String} offset if it is a dynamic param, otherwise value
  593. */
  594. SolidityParam.prototype.staticPart = function () {
  595. if (!this.isDynamic()) {
  596. return this.value;
  597. }
  598. return this.offsetAsBytes();
  599. };
  600. /**
  601. * This method should be called to get dynamic part of param
  602. *
  603. * @method dynamicPart
  604. * @returns {String} returns a value if it is a dynamic param, otherwise empty string
  605. */
  606. SolidityParam.prototype.dynamicPart = function () {
  607. return this.isDynamic() ? this.value : '';
  608. };
  609. /**
  610. * This method should be called to encode param
  611. *
  612. * @method encode
  613. * @returns {String}
  614. */
  615. SolidityParam.prototype.encode = function () {
  616. return this.staticPart() + this.dynamicPart();
  617. };
  618. /**
  619. * This method should be called to encode array of params
  620. *
  621. * @method encodeList
  622. * @param {Array[SolidityParam]} params
  623. * @returns {String}
  624. */
  625. SolidityParam.encodeList = function (params) {
  626. // updating offsets
  627. var totalOffset = params.length * 32;
  628. var offsetParams = params.map(function (param) {
  629. if (!param.isDynamic()) {
  630. return param;
  631. }
  632. var offset = totalOffset;
  633. totalOffset += param.dynamicPartLength();
  634. return param.withOffset(offset);
  635. });
  636. // encode everything!
  637. return offsetParams.reduce(function (result, param) {
  638. return result + param.dynamicPart();
  639. }, offsetParams.reduce(function (result, param) {
  640. return result + param.staticPart();
  641. }, ''));
  642. };
  643. /**
  644. * This method should be used to decode plain (static) solidity param at given index
  645. *
  646. * @method decodeParam
  647. * @param {String} bytes
  648. * @param {Number} index
  649. * @returns {SolidityParam}
  650. */
  651. SolidityParam.decodeParam = function (bytes, index) {
  652. index = index || 0;
  653. return new SolidityParam(bytes.substr(index * 64, 64));
  654. };
  655. /**
  656. * This method should be called to get offset value from bytes at given index
  657. *
  658. * @method getOffset
  659. * @param {String} bytes
  660. * @param {Number} index
  661. * @returns {Number} offset as number
  662. */
  663. var getOffset = function (bytes, index) {
  664. // we can do this cause offset is rather small
  665. return parseInt('0x' + bytes.substr(index * 64, 64));
  666. };
  667. /**
  668. * This method should be called to decode solidity bytes param at given index
  669. *
  670. * @method decodeBytes
  671. * @param {String} bytes
  672. * @param {Number} index
  673. * @returns {SolidityParam}
  674. */
  675. SolidityParam.decodeBytes = function (bytes, index) {
  676. index = index || 0;
  677. var offset = getOffset(bytes, index);
  678. var l = parseInt('0x' + bytes.substr(offset * 2, 64));
  679. l = Math.floor((l + 31) / 32);
  680. // (1 + l) * , cause we also parse length
  681. return new SolidityParam(bytes.substr(offset * 2, (1 + l) * 64), 0);
  682. };
  683. /**
  684. * This method should be used to decode solidity array at given index
  685. *
  686. * @method decodeArray
  687. * @param {String} bytes
  688. * @param {Number} index
  689. * @returns {SolidityParam}
  690. */
  691. SolidityParam.decodeArray = function (bytes, index) {
  692. index = index || 0;
  693. var offset = getOffset(bytes, index);
  694. var length = parseInt('0x' + bytes.substr(offset * 2, 64));
  695. return new SolidityParam(bytes.substr(offset * 2, (length + 1) * 64), 0);
  696. };
  697. module.exports = SolidityParam;
  698. },{"../utils/utils":7}],4:[function(require,module,exports){
  699. 'use strict';
  700. // go env doesn't have and need XMLHttpRequest
  701. if (typeof XMLHttpRequest === 'undefined') {
  702. exports.XMLHttpRequest = {};
  703. } else {
  704. exports.XMLHttpRequest = XMLHttpRequest; // jshint ignore:line
  705. }
  706. },{}],5:[function(require,module,exports){
  707. /*
  708. This file is part of ethereum.js.
  709. ethereum.js is free software: you can redistribute it and/or modify
  710. it under the terms of the GNU Lesser General Public License as published by
  711. the Free Software Foundation, either version 3 of the License, or
  712. (at your option) any later version.
  713. ethereum.js is distributed in the hope that it will be useful,
  714. but WITHOUT ANY WARRANTY; without even the implied warranty of
  715. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  716. GNU Lesser General Public License for more details.
  717. You should have received a copy of the GNU Lesser General Public License
  718. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  719. */
  720. /** @file config.js
  721. * @authors:
  722. * Marek Kotewicz <marek@ethdev.com>
  723. * @date 2015
  724. */
  725. /**
  726. * Utils
  727. *
  728. * @module utils
  729. */
  730. /**
  731. * Utility functions
  732. *
  733. * @class [utils] config
  734. * @constructor
  735. */
  736. /// required to define ETH_BIGNUMBER_ROUNDING_MODE
  737. var BigNumber = require('bignumber.js');
  738. var ETH_UNITS = [
  739. 'wei',
  740. 'kwei',
  741. 'Mwei',
  742. 'Gwei',
  743. 'szabo',
  744. 'finney',
  745. 'femtoether',
  746. 'picoether',
  747. 'nanoether',
  748. 'microether',
  749. 'milliether',
  750. 'nano',
  751. 'micro',
  752. 'milli',
  753. 'ether',
  754. 'grand',
  755. 'Mether',
  756. 'Gether',
  757. 'Tether',
  758. 'Pether',
  759. 'Eether',
  760. 'Zether',
  761. 'Yether',
  762. 'Nether',
  763. 'Dether',
  764. 'Vether',
  765. 'Uether'
  766. ];
  767. module.exports = {
  768. ETH_PADDING: 32,
  769. ETH_SIGNATURE_LENGTH: 4,
  770. ETH_UNITS: ETH_UNITS,
  771. ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN },
  772. ETH_POLLING_TIMEOUT: 1000/2,
  773. defaultBlock: 'latest',
  774. defaultAccount: undefined
  775. };
  776. },{"bignumber.js":"bignumber.js"}],6:[function(require,module,exports){
  777. /*
  778. This file is part of ethereum.js.
  779. ethereum.js is free software: you can redistribute it and/or modify
  780. it under the terms of the GNU Lesser General Public License as published by
  781. the Free Software Foundation, either version 3 of the License, or
  782. (at your option) any later version.
  783. ethereum.js is distributed in the hope that it will be useful,
  784. but WITHOUT ANY WARRANTY; without even the implied warranty of
  785. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  786. GNU Lesser General Public License for more details.
  787. You should have received a copy of the GNU Lesser General Public License
  788. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  789. */
  790. /**
  791. * @file sha3.js
  792. * @author Marek Kotewicz <marek@ethdev.com>
  793. * @date 2015
  794. */
  795. var utils = require('./utils');
  796. var sha3 = require('crypto-js/sha3');
  797. module.exports = function (str, isNew) {
  798. if (str.substr(0, 2) === '0x' && !isNew) {
  799. console.warn('requirement of using web3.fromAscii before sha3 is deprecated');
  800. console.warn('new usage: \'web3.sha3("hello")\'');
  801. console.warn('see https://github.com/ethereum/web3.js/pull/205');
  802. console.warn('if you need to hash hex value, you can do \'sha3("0xfff", true)\'');
  803. str = utils.toAscii(str);
  804. }
  805. return sha3(str, {
  806. outputLength: 256
  807. }).toString();
  808. };
  809. },{"./utils":7,"crypto-js/sha3":34}],7:[function(require,module,exports){
  810. /*
  811. This file is part of ethereum.js.
  812. ethereum.js is free software: you can redistribute it and/or modify
  813. it under the terms of the GNU Lesser General Public License as published by
  814. the Free Software Foundation, either version 3 of the License, or
  815. (at your option) any later version.
  816. ethereum.js is distributed in the hope that it will be useful,
  817. but WITHOUT ANY WARRANTY; without even the implied warranty of
  818. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  819. GNU Lesser General Public License for more details.
  820. You should have received a copy of the GNU Lesser General Public License
  821. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  822. */
  823. /**
  824. * @file utils.js
  825. * @author Marek Kotewicz <marek@ethdev.com>
  826. * @date 2015
  827. */
  828. /**
  829. * Utils
  830. *
  831. * @module utils
  832. */
  833. /**
  834. * Utility functions
  835. *
  836. * @class [utils] utils
  837. * @constructor
  838. */
  839. var BigNumber = require('bignumber.js');
  840. var unitMap = {
  841. 'wei': '1',
  842. 'kwei': '1000',
  843. 'ada': '1000',
  844. 'femtoether': '1000',
  845. 'mwei': '1000000',
  846. 'babbage': '1000000',
  847. 'picoether': '1000000',
  848. 'gwei': '1000000000',
  849. 'shannon': '1000000000',
  850. 'nanoether': '1000000000',
  851. 'nano': '1000000000',
  852. 'szabo': '1000000000000',
  853. 'microether': '1000000000000',
  854. 'micro': '1000000000000',
  855. 'finney': '1000000000000000',
  856. 'milliether': '1000000000000000',
  857. 'milli': '1000000000000000',
  858. 'ether': '1000000000000000000',
  859. 'kether': '1000000000000000000000',
  860. 'grand': '1000000000000000000000',
  861. 'einstein': '1000000000000000000000',
  862. 'mether': '1000000000000000000000000',
  863. 'gether': '1000000000000000000000000000',
  864. 'tether': '1000000000000000000000000000000'
  865. };
  866. /**
  867. * Should be called to pad string to expected length
  868. *
  869. * @method padLeft
  870. * @param {String} string to be padded
  871. * @param {Number} characters that result string should have
  872. * @param {String} sign, by default 0
  873. * @returns {String} right aligned string
  874. */
  875. var padLeft = function (string, chars, sign) {
  876. return new Array(chars - string.length + 1).join(sign ? sign : "0") + string;
  877. };
  878. /**
  879. * Should be called to pad string to expected length
  880. *
  881. * @method padRight
  882. * @param {String} string to be padded
  883. * @param {Number} characters that result string should have
  884. * @param {String} sign, by default 0
  885. * @returns {String} right aligned string
  886. */
  887. var padRight = function (string, chars, sign) {
  888. return string + (new Array(chars - string.length + 1).join(sign ? sign : "0"));
  889. };
  890. /**
  891. * Should be called to get sting from it's hex representation
  892. * TODO: it should be called toUTF8
  893. *
  894. * @method toAscii
  895. * @param {String} string in hex
  896. * @returns {String} ascii string representation of hex value
  897. */
  898. var toAscii = function(hex) {
  899. // Find termination
  900. var str = "";
  901. var i = 0, l = hex.length;
  902. if (hex.substring(0, 2) === '0x') {
  903. i = 2;
  904. }
  905. for (; i < l; i+=2) {
  906. var code = parseInt(hex.substr(i, 2), 16);
  907. str += String.fromCharCode(code);
  908. }
  909. return decodeURIComponent(escape(str));
  910. };
  911. /**
  912. * Shold be called to get hex representation (prefixed by 0x) of ascii string
  913. *
  914. * @method toHexNative
  915. * @param {String} string
  916. * @returns {String} hex representation of input string
  917. */
  918. var toHexNative = function(str) {
  919. str = unescape(encodeURIComponent(str));
  920. var hex = "";
  921. for(var i = 0; i < str.length; i++) {
  922. var n = str.charCodeAt(i).toString(16);
  923. hex += n.length < 2 ? '0' + n : n;
  924. }
  925. return hex;
  926. };
  927. /**
  928. * Shold be called to get hex representation (prefixed by 0x) of ascii string
  929. *
  930. * @method fromAscii
  931. * @param {String} string
  932. * @param {Number} optional padding
  933. * @returns {String} hex representation of input string
  934. */
  935. var fromAscii = function(str, pad) {
  936. pad = pad === undefined ? 0 : pad;
  937. var hex = toHexNative(str);
  938. while (hex.length < pad*2)
  939. hex += "00";
  940. return "0x" + hex;
  941. };
  942. /**
  943. * Should be used to create full function/event name from json abi
  944. *
  945. * @method transformToFullName
  946. * @param {Object} json-abi
  947. * @return {String} full fnction/event name
  948. */
  949. var transformToFullName = function (json) {
  950. if (json.name.indexOf('(') !== -1) {
  951. return json.name;
  952. }
  953. var typeName = json.inputs.map(function(i){return i.type; }).join();
  954. return json.name + '(' + typeName + ')';
  955. };
  956. /**
  957. * Should be called to get display name of contract function
  958. *
  959. * @method extractDisplayName
  960. * @param {String} name of function/event
  961. * @returns {String} display name for function/event eg. multiply(uint256) -> multiply
  962. */
  963. var extractDisplayName = function (name) {
  964. var length = name.indexOf('(');
  965. return length !== -1 ? name.substr(0, length) : name;
  966. };
  967. /// @returns overloaded part of function/event name
  968. var extractTypeName = function (name) {
  969. /// TODO: make it invulnerable
  970. var length = name.indexOf('(');
  971. return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : "";
  972. };
  973. /**
  974. * Converts value to it's decimal representation in string
  975. *
  976. * @method toDecimal
  977. * @param {String|Number|BigNumber}
  978. * @return {String}
  979. */
  980. var toDecimal = function (value) {
  981. return toBigNumber(value).toNumber();
  982. };
  983. /**
  984. * Converts value to it's hex representation
  985. *
  986. * @method fromDecimal
  987. * @param {String|Number|BigNumber}
  988. * @return {String}
  989. */
  990. var fromDecimal = function (value) {
  991. var number = toBigNumber(value);
  992. var result = number.toString(16);
  993. return number.lessThan(0) ? '-0x' + result.substr(1) : '0x' + result;
  994. };
  995. /**
  996. * Auto converts any given value into it's hex representation.
  997. *
  998. * And even stringifys objects before.
  999. *
  1000. * @method toHex
  1001. * @param {String|Number|BigNumber|Object}
  1002. * @return {String}
  1003. */
  1004. var toHex = function (val) {
  1005. /*jshint maxcomplexity: 8 */
  1006. if (isBoolean(val))
  1007. return fromDecimal(+val);
  1008. if (isBigNumber(val))
  1009. return fromDecimal(val);
  1010. if (isObject(val))
  1011. return fromAscii(JSON.stringify(val));
  1012. // if its a negative number, pass it through fromDecimal
  1013. if (isString(val)) {
  1014. if (val.indexOf('-0x') === 0)
  1015. return fromDecimal(val);
  1016. else if (!isFinite(val))
  1017. return fromAscii(val);
  1018. else if(val.indexOf('0x') === 0)
  1019. return val;
  1020. }
  1021. return fromDecimal(val);
  1022. };
  1023. /**
  1024. * Returns value of unit in Wei
  1025. *
  1026. * @method getValueOfUnit
  1027. * @param {String} unit the unit to convert to, default ether
  1028. * @returns {BigNumber} value of the unit (in Wei)
  1029. * @throws error if the unit is not correct:w
  1030. */
  1031. var getValueOfUnit = function (unit) {
  1032. unit = unit ? unit.toLowerCase() : 'ether';
  1033. var unitValue = unitMap[unit];
  1034. if (unitValue === undefined) {
  1035. throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2));
  1036. }
  1037. return new BigNumber(unitValue, 10);
  1038. };
  1039. /**
  1040. * Takes a number of wei and converts it to any other ether unit.
  1041. *
  1042. * Possible units are:
  1043. * SI Short SI Full Effigy Other
  1044. * - kwei femtoether ada
  1045. * - mwei picoether babbage
  1046. * - gwei nanoether shannon nano
  1047. * - -- microether szabo micro
  1048. * - -- milliether finney milli
  1049. * - ether -- --
  1050. * - kether einstein grand
  1051. * - mether
  1052. * - gether
  1053. * - tether
  1054. *
  1055. * @method fromWei
  1056. * @param {Number|String} number can be a number, number string or a HEX of a decimal
  1057. * @param {String} unit the unit to convert to, default ether
  1058. * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
  1059. */
  1060. var fromWei = function(number, unit) {
  1061. var returnValue = toBigNumber(number).dividedBy(getValueOfUnit(unit));
  1062. return isBigNumber(number) ? returnValue : returnValue.toString(10);
  1063. };
  1064. /**
  1065. * Takes a number of a unit and converts it to wei.
  1066. *
  1067. * Possible units are:
  1068. * SI Short SI Full Effigy Other
  1069. * - kwei femtoether ada
  1070. * - mwei picoether babbage
  1071. * - gwei nanoether shannon nano
  1072. * - -- microether szabo micro
  1073. * - -- milliether finney milli
  1074. * - ether -- --
  1075. * - kether einstein grand
  1076. * - mether
  1077. * - gether
  1078. * - tether
  1079. *
  1080. * @method toWei
  1081. * @param {Number|String|BigNumber} number can be a number, number string or a HEX of a decimal
  1082. * @param {String} unit the unit to convert from, default ether
  1083. * @return {String|Object} When given a BigNumber object it returns one as well, otherwise a number
  1084. */
  1085. var toWei = function(number, unit) {
  1086. var returnValue = toBigNumber(number).times(getValueOfUnit(unit));
  1087. return isBigNumber(number) ? returnValue : returnValue.toString(10);
  1088. };
  1089. /**
  1090. * Takes an input and transforms it into an bignumber
  1091. *
  1092. * @method toBigNumber
  1093. * @param {Number|String|BigNumber} a number, string, HEX string or BigNumber
  1094. * @return {BigNumber} BigNumber
  1095. */
  1096. var toBigNumber = function(number) {
  1097. /*jshint maxcomplexity:5 */
  1098. number = number || 0;
  1099. if (isBigNumber(number))
  1100. return number;
  1101. if (isString(number) && (number.indexOf('0x') === 0 || number.indexOf('-0x') === 0)) {
  1102. return new BigNumber(number.replace('0x',''), 16);
  1103. }
  1104. return new BigNumber(number.toString(10), 10);
  1105. };
  1106. /**
  1107. * Takes and input transforms it into bignumber and if it is negative value, into two's complement
  1108. *
  1109. * @method toTwosComplement
  1110. * @param {Number|String|BigNumber}
  1111. * @return {BigNumber}
  1112. */
  1113. var toTwosComplement = function (number) {
  1114. var bigNumber = toBigNumber(number);
  1115. if (bigNumber.lessThan(0)) {
  1116. return new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).plus(bigNumber).plus(1);
  1117. }
  1118. return bigNumber;
  1119. };
  1120. /**
  1121. * Checks if the given string is strictly an address
  1122. *
  1123. * @method isStrictAddress
  1124. * @param {String} address the given HEX adress
  1125. * @return {Boolean}
  1126. */
  1127. var isStrictAddress = function (address) {
  1128. return /^0x[0-9a-f]{40}$/.test(address);
  1129. };
  1130. /**
  1131. * Checks if the given string is an address
  1132. *
  1133. * @method isAddress
  1134. * @param {String} address the given HEX adress
  1135. * @return {Boolean}
  1136. */
  1137. var isAddress = function (address) {
  1138. return /^(0x)?[0-9a-f]{40}$/.test(address);
  1139. };
  1140. /**
  1141. * Transforms given string to valid 20 bytes-length addres with 0x prefix
  1142. *
  1143. * @method toAddress
  1144. * @param {String} address
  1145. * @return {String} formatted address
  1146. */
  1147. var toAddress = function (address) {
  1148. if (isStrictAddress(address)) {
  1149. return address;
  1150. }
  1151. if (/^[0-9a-f]{40}$/.test(address)) {
  1152. return '0x' + address;
  1153. }
  1154. return '0x' + padLeft(toHex(address).substr(2), 40);
  1155. };
  1156. /**
  1157. * Returns true if object is BigNumber, otherwise false
  1158. *
  1159. * @method isBigNumber
  1160. * @param {Object}
  1161. * @return {Boolean}
  1162. */
  1163. var isBigNumber = function (object) {
  1164. return object instanceof BigNumber ||
  1165. (object && object.constructor && object.constructor.name === 'BigNumber');
  1166. };
  1167. /**
  1168. * Returns true if object is string, otherwise false
  1169. *
  1170. * @method isString
  1171. * @param {Object}
  1172. * @return {Boolean}
  1173. */
  1174. var isString = function (object) {
  1175. return typeof object === 'string' ||
  1176. (object && object.constructor && object.constructor.name === 'String');
  1177. };
  1178. /**
  1179. * Returns true if object is function, otherwise false
  1180. *
  1181. * @method isFunction
  1182. * @param {Object}
  1183. * @return {Boolean}
  1184. */
  1185. var isFunction = function (object) {
  1186. return typeof object === 'function';
  1187. };
  1188. /**
  1189. * Returns true if object is Objet, otherwise false
  1190. *
  1191. * @method isObject
  1192. * @param {Object}
  1193. * @return {Boolean}
  1194. */
  1195. var isObject = function (object) {
  1196. return typeof object === 'object';
  1197. };
  1198. /**
  1199. * Returns true if object is boolean, otherwise false
  1200. *
  1201. * @method isBoolean
  1202. * @param {Object}
  1203. * @return {Boolean}
  1204. */
  1205. var isBoolean = function (object) {
  1206. return typeof object === 'boolean';
  1207. };
  1208. /**
  1209. * Returns true if object is array, otherwise false
  1210. *
  1211. * @method isArray
  1212. * @param {Object}
  1213. * @return {Boolean}
  1214. */
  1215. var isArray = function (object) {
  1216. return object instanceof Array;
  1217. };
  1218. /**
  1219. * Returns true if given string is valid json object
  1220. *
  1221. * @method isJson
  1222. * @param {String}
  1223. * @return {Boolean}
  1224. */
  1225. var isJson = function (str) {
  1226. try {
  1227. return !!JSON.parse(str);
  1228. } catch (e) {
  1229. return false;
  1230. }
  1231. };
  1232. /**
  1233. * This method should be called to check if string is valid ethereum IBAN number
  1234. * Supports direct and indirect IBANs
  1235. *
  1236. * @method isIBAN
  1237. * @param {String}
  1238. * @return {Boolean}
  1239. */
  1240. var isIBAN = function (iban) {
  1241. return /^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30})$/.test(iban);
  1242. };
  1243. module.exports = {
  1244. padLeft: padLeft,
  1245. padRight: padRight,
  1246. toHex: toHex,
  1247. toDecimal: toDecimal,
  1248. fromDecimal: fromDecimal,
  1249. toAscii: toAscii,
  1250. fromAscii: fromAscii,
  1251. transformToFullName: transformToFullName,
  1252. extractDisplayName: extractDisplayName,
  1253. extractTypeName: extractTypeName,
  1254. toWei: toWei,
  1255. fromWei: fromWei,
  1256. toBigNumber: toBigNumber,
  1257. toTwosComplement: toTwosComplement,
  1258. toAddress: toAddress,
  1259. isBigNumber: isBigNumber,
  1260. isStrictAddress: isStrictAddress,
  1261. isAddress: isAddress,
  1262. isFunction: isFunction,
  1263. isString: isString,
  1264. isObject: isObject,
  1265. isBoolean: isBoolean,
  1266. isArray: isArray,
  1267. isJson: isJson,
  1268. isIBAN: isIBAN
  1269. };
  1270. },{"bignumber.js":"bignumber.js"}],8:[function(require,module,exports){
  1271. module.exports={
  1272. "version": "0.9.1"
  1273. }
  1274. },{}],9:[function(require,module,exports){
  1275. /*
  1276. This file is part of ethereum.js.
  1277. ethereum.js is free software: you can redistribute it and/or modify
  1278. it under the terms of the GNU Lesser General Public License as published by
  1279. the Free Software Foundation, either version 3 of the License, or
  1280. (at your option) any later version.
  1281. ethereum.js is distributed in the hope that it will be useful,
  1282. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1283. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1284. GNU Lesser General Public License for more details.
  1285. You should have received a copy of the GNU Lesser General Public License
  1286. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  1287. */
  1288. /** @file web3.js
  1289. * @authors:
  1290. * Jeffrey Wilcke <jeff@ethdev.com>
  1291. * Marek Kotewicz <marek@ethdev.com>
  1292. * Marian Oancea <marian@ethdev.com>
  1293. * Fabian Vogelsteller <fabian@ethdev.com>
  1294. * Gav Wood <g@ethdev.com>
  1295. * @date 2014
  1296. */
  1297. var version = require('./version.json');
  1298. var net = require('./web3/net');
  1299. var eth = require('./web3/eth');
  1300. var db = require('./web3/db');
  1301. var shh = require('./web3/shh');
  1302. var watches = require('./web3/watches');
  1303. var Filter = require('./web3/filter');
  1304. var utils = require('./utils/utils');
  1305. var formatters = require('./web3/formatters');
  1306. var RequestManager = require('./web3/requestmanager');
  1307. var c = require('./utils/config');
  1308. var Property = require('./web3/property');
  1309. var Batch = require('./web3/batch');
  1310. var sha3 = require('./utils/sha3');
  1311. var web3Properties = [
  1312. new Property({
  1313. name: 'version.client',
  1314. getter: 'web3_clientVersion'
  1315. }),
  1316. new Property({
  1317. name: 'version.network',
  1318. getter: 'net_version',
  1319. inputFormatter: utils.toDecimal
  1320. }),
  1321. new Property({
  1322. name: 'version.ethereum',
  1323. getter: 'eth_protocolVersion',
  1324. inputFormatter: utils.toDecimal
  1325. }),
  1326. new Property({
  1327. name: 'version.whisper',
  1328. getter: 'shh_version',
  1329. inputFormatter: utils.toDecimal
  1330. })
  1331. ];
  1332. /// creates methods in a given object based on method description on input
  1333. /// setups api calls for these methods
  1334. var setupMethods = function (obj, methods) {
  1335. methods.forEach(function (method) {
  1336. method.attachToObject(obj);
  1337. });
  1338. };
  1339. /// creates properties in a given object based on properties description on input
  1340. /// setups api calls for these properties
  1341. var setupProperties = function (obj, properties) {
  1342. properties.forEach(function (property) {
  1343. property.attachToObject(obj);
  1344. });
  1345. };
  1346. /// setups web3 object, and it's in-browser executed methods
  1347. var web3 = {};
  1348. web3.providers = {};
  1349. web3.currentProvider = null;
  1350. web3.version = {};
  1351. web3.version.api = version.version;
  1352. web3.eth = {};
  1353. /*jshint maxparams:4 */
  1354. web3.eth.filter = function (fil, callback) {
  1355. return new Filter(fil, watches.eth(), formatters.outputLogFormatter, callback);
  1356. };
  1357. /*jshint maxparams:3 */
  1358. web3.shh = {};
  1359. web3.shh.filter = function (fil, callback) {
  1360. return new Filter(fil, watches.shh(), formatters.outputPostFormatter, callback);
  1361. };
  1362. web3.net = {};
  1363. web3.db = {};
  1364. web3.setProvider = function (provider) {
  1365. this.currentProvider = provider;
  1366. RequestManager.getInstance().setProvider(provider);
  1367. };
  1368. web3.isConnected = function(){
  1369. return (this.currentProvider && this.currentProvider.isConnected());
  1370. };
  1371. web3.reset = function () {
  1372. RequestManager.getInstance().reset();
  1373. c.defaultBlock = 'latest';
  1374. c.defaultAccount = undefined;
  1375. };
  1376. web3.toHex = utils.toHex;
  1377. web3.toAscii = utils.toAscii;
  1378. web3.fromAscii = utils.fromAscii;
  1379. web3.toDecimal = utils.toDecimal;
  1380. web3.fromDecimal = utils.fromDecimal;
  1381. web3.toBigNumber = utils.toBigNumber;
  1382. web3.toWei = utils.toWei;
  1383. web3.fromWei = utils.fromWei;
  1384. web3.isAddress = utils.isAddress;
  1385. web3.isIBAN = utils.isIBAN;
  1386. web3.sha3 = sha3;
  1387. web3.createBatch = function () {
  1388. return new Batch();
  1389. };
  1390. // ADD defaultblock
  1391. Object.defineProperty(web3.eth, 'defaultBlock', {
  1392. get: function () {
  1393. return c.defaultBlock;
  1394. },
  1395. set: function (val) {
  1396. c.defaultBlock = val;
  1397. return val;
  1398. }
  1399. });
  1400. Object.defineProperty(web3.eth, 'defaultAccount', {
  1401. get: function () {
  1402. return c.defaultAccount;
  1403. },
  1404. set: function (val) {
  1405. c.defaultAccount = val;
  1406. return val;
  1407. }
  1408. });
  1409. // EXTEND
  1410. web3._extend = function(extension){
  1411. /*jshint maxcomplexity: 6 */
  1412. if(extension.property && !web3[extension.property])
  1413. web3[extension.property] = {};
  1414. setupMethods(web3[extension.property] || web3, extension.methods || []);
  1415. setupProperties(web3[extension.property] || web3, extension.properties || []);
  1416. };
  1417. web3._extend.formatters = formatters;
  1418. web3._extend.utils = utils;
  1419. web3._extend.Method = require('./web3/method');
  1420. web3._extend.Property = require('./web3/property');
  1421. /// setups all api methods
  1422. setupProperties(web3, web3Properties);
  1423. setupMethods(web3.net, net.methods);
  1424. setupProperties(web3.net, net.properties);
  1425. setupMethods(web3.eth, eth.methods);
  1426. setupProperties(web3.eth, eth.properties);
  1427. setupMethods(web3.db, db.methods);
  1428. setupMethods(web3.shh, shh.methods);
  1429. module.exports = web3;
  1430. },{"./utils/config":5,"./utils/sha3":6,"./utils/utils":7,"./version.json":8,"./web3/batch":11,"./web3/db":13,"./web3/eth":15,"./web3/filter":17,"./web3/formatters":18,"./web3/method":24,"./web3/net":26,"./web3/property":27,"./web3/requestmanager":28,"./web3/shh":29,"./web3/watches":31}],10:[function(require,module,exports){
  1431. /*
  1432. This file is part of ethereum.js.
  1433. ethereum.js is free software: you can redistribute it and/or modify
  1434. it under the terms of the GNU Lesser General Public License as published by
  1435. the Free Software Foundation, either version 3 of the License, or
  1436. (at your option) any later version.
  1437. ethereum.js is distributed in the hope that it will be useful,
  1438. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1439. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1440. GNU Lesser General Public License for more details.
  1441. You should have received a copy of the GNU Lesser General Public License
  1442. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  1443. */
  1444. /**
  1445. * @file allevents.js
  1446. * @author Marek Kotewicz <marek@ethdev.com>
  1447. * @date 2014
  1448. */
  1449. var sha3 = require('../utils/sha3');
  1450. var SolidityEvent = require('./event');
  1451. var formatters = require('./formatters');
  1452. var utils = require('../utils/utils');
  1453. var Filter = require('./filter');
  1454. var watches = require('./watches');
  1455. var AllSolidityEvents = function (json, address) {
  1456. this._json = json;
  1457. this._address = address;
  1458. };
  1459. AllSolidityEvents.prototype.encode = function (options) {
  1460. options = options || {};
  1461. var result = {};
  1462. ['fromBlock', 'toBlock'].filter(function (f) {
  1463. return options[f] !== undefined;
  1464. }).forEach(function (f) {
  1465. result[f] = formatters.inputBlockNumberFormatter(options[f]);
  1466. });
  1467. result.address = this._address;
  1468. return result;
  1469. };
  1470. AllSolidityEvents.prototype.decode = function (data) {
  1471. data.data = data.data || '';
  1472. data.topics = data.topics || [];
  1473. var eventTopic = data.topics[0].slice(2);
  1474. var match = this._json.filter(function (j) {
  1475. return eventTopic === sha3(utils.transformToFullName(j));
  1476. })[0];
  1477. if (!match) { // cannot find matching event?
  1478. console.warn('cannot find event for log');
  1479. return data;
  1480. }
  1481. var event = new SolidityEvent(match, this._address);
  1482. return event.decode(data);
  1483. };
  1484. AllSolidityEvents.prototype.execute = function (options, callback) {
  1485. var o = this.encode(options);
  1486. var formatter = this.decode.bind(this);
  1487. return new Filter(o, watches.eth(), formatter, callback);
  1488. };
  1489. AllSolidityEvents.prototype.attachToContract = function (contract) {
  1490. var execute = this.execute.bind(this);
  1491. contract.allEvents = execute;
  1492. };
  1493. module.exports = AllSolidityEvents;
  1494. },{"../utils/sha3":6,"../utils/utils":7,"./event":16,"./filter":17,"./formatters":18,"./watches":31}],11:[function(require,module,exports){
  1495. /*
  1496. This file is part of ethereum.js.
  1497. ethereum.js is free software: you can redistribute it and/or modify
  1498. it under the terms of the GNU Lesser General Public License as published by
  1499. the Free Software Foundation, either version 3 of the License, or
  1500. (at your option) any later version.
  1501. ethereum.js is distributed in the hope that it will be useful,
  1502. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1503. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1504. GNU Lesser General Public License for more details.
  1505. You should have received a copy of the GNU Lesser General Public License
  1506. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  1507. */
  1508. /**
  1509. * @file batch.js
  1510. * @author Marek Kotewicz <marek@ethdev.com>
  1511. * @date 2015
  1512. */
  1513. var RequestManager = require('./requestmanager');
  1514. var Jsonrpc = require('./jsonrpc');
  1515. var errors = require('./errors');
  1516. var Batch = function () {
  1517. this.requests = [];
  1518. };
  1519. /**
  1520. * Should be called to add create new request to batch request
  1521. *
  1522. * @method add
  1523. * @param {Object} jsonrpc requet object
  1524. */
  1525. Batch.prototype.add = function (request) {
  1526. this.requests.push(request);
  1527. };
  1528. /**
  1529. * Should be called to execute batch request
  1530. *
  1531. * @method execute
  1532. */
  1533. Batch.prototype.execute = function () {
  1534. var requests = this.requests;
  1535. RequestManager.getInstance().sendBatch(requests, function (err, results) {
  1536. results = results || [];
  1537. requests.map(function (request, index) {
  1538. return results[index] || {};
  1539. }).forEach(function (result, index) {
  1540. if (requests[index].callback) {
  1541. if (!Jsonrpc.getInstance().isValidResponse(result)) {
  1542. return requests[index].callback(errors.InvalidResponse(result));
  1543. }
  1544. requests[index].callback(null, (requests[index].format ? requests[index].format(result.result) : result.result));
  1545. }
  1546. });
  1547. });
  1548. };
  1549. module.exports = Batch;
  1550. },{"./errors":14,"./jsonrpc":23,"./requestmanager":28}],12:[function(require,module,exports){
  1551. /*
  1552. This file is part of ethereum.js.
  1553. ethereum.js is free software: you can redistribute it and/or modify
  1554. it under the terms of the GNU Lesser General Public License as published by
  1555. the Free Software Foundation, either version 3 of the License, or
  1556. (at your option) any later version.
  1557. ethereum.js is distributed in the hope that it will be useful,
  1558. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1559. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1560. GNU Lesser General Public License for more details.
  1561. You should have received a copy of the GNU Lesser General Public License
  1562. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  1563. */
  1564. /**
  1565. * @file contract.js
  1566. * @author Marek Kotewicz <marek@ethdev.com>
  1567. * @date 2014
  1568. */
  1569. var web3 = require('../web3');
  1570. var utils = require('../utils/utils');
  1571. var coder = require('../solidity/coder');
  1572. var SolidityEvent = require('./event');
  1573. var SolidityFunction = require('./function');
  1574. var AllEvents = require('./allevents');
  1575. /**
  1576. * Should be called to encode constructor params
  1577. *
  1578. * @method encodeConstructorParams
  1579. * @param {Array} abi
  1580. * @param {Array} constructor params
  1581. */
  1582. var encodeConstructorParams = function (abi, params) {
  1583. return abi.filter(function (json) {
  1584. return json.type === 'constructor' && json.inputs.length === params.length;
  1585. }).map(function (json) {
  1586. return json.inputs.map(function (input) {
  1587. return input.type;
  1588. });
  1589. }).map(function (types) {
  1590. return coder.encodeParams(types, params);
  1591. })[0] || '';
  1592. };
  1593. /**
  1594. * Should be called to add functions to contract object
  1595. *
  1596. * @method addFunctionsToContract
  1597. * @param {Contract} contract
  1598. * @param {Array} abi
  1599. */
  1600. var addFunctionsToContract = function (contract, abi) {
  1601. abi.filter(function (json) {
  1602. return json.type === 'function';
  1603. }).map(function (json) {
  1604. return new SolidityFunction(json, contract.address);
  1605. }).forEach(function (f) {
  1606. f.attachToContract(contract);
  1607. });
  1608. };
  1609. /**
  1610. * Should be called to add events to contract object
  1611. *
  1612. * @method addEventsToContract
  1613. * @param {Contract} contract
  1614. * @param {Array} abi
  1615. */
  1616. var addEventsToContract = function (contract, abi) {
  1617. var events = abi.filter(function (json) {
  1618. return json.type === 'event';
  1619. });
  1620. var All = new AllEvents(events, contract.address);
  1621. All.attachToContract(contract);
  1622. events.map(function (json) {
  1623. return new SolidityEvent(json, contract.address);
  1624. }).forEach(function (e) {
  1625. e.attachToContract(contract);
  1626. });
  1627. };
  1628. /**
  1629. * Should be called to create new ContractFactory
  1630. *
  1631. * @method contract
  1632. * @param {Array} abi
  1633. * @returns {ContractFactory} new contract factory
  1634. */
  1635. var contract = function (abi) {
  1636. return new ContractFactory(abi);
  1637. };
  1638. /**
  1639. * Should be called to check if the contract gets properly deployed on the blockchain.
  1640. *
  1641. * @method checkForContractAddress
  1642. * @param {Object} contract
  1643. * @param {Function} callback
  1644. * @returns {Undefined}
  1645. */
  1646. var checkForContractAddress = function(contract, abi, callback){
  1647. var count = 0,
  1648. callbackFired = false;
  1649. // wait for receipt
  1650. var filter = web3.eth.filter('latest', function(e){
  1651. if(!e && !callbackFired) {
  1652. count++;
  1653. // console.log('Checking for contract address', count);
  1654. // stop watching after 50 blocks (timeout)
  1655. if(count > 50) {
  1656. filter.stopWatching();
  1657. callbackFired = true;
  1658. if(callback)
  1659. callback(new Error('Contract transaction couldn\'t be found after 50 blocks'));
  1660. else
  1661. throw new Error('Contract transaction couldn\'t be found after 50 blocks');
  1662. } else {
  1663. web3.eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
  1664. if(receipt && !callbackFired) {
  1665. web3.eth.getCode(receipt.contractAddress, function(e, code){
  1666. /*jshint maxcomplexity: 5 */
  1667. if(callbackFired)
  1668. return;
  1669. filter.stopWatching();
  1670. callbackFired = true;
  1671. if(code.length > 2) {
  1672. // console.log('Contract code deployed!');
  1673. contract.address = receipt.contractAddress;
  1674. // attach events and methods
  1675. addFunctionsToContract(contract, abi);
  1676. addEventsToContract(contract, abi);
  1677. // call callback for the second time
  1678. if(callback)
  1679. callback(null, contract);
  1680. } else {
  1681. if(callback)
  1682. callback(new Error('The contract code couldn\'t be stored, please check your gas amount.'));
  1683. else
  1684. throw new Error('The contract code couldn\'t be stored, please check your gas amount.');
  1685. }
  1686. });
  1687. }
  1688. });
  1689. }
  1690. }
  1691. });
  1692. };
  1693. /**
  1694. * Should be called to create new ContractFactory instance
  1695. *
  1696. * @method ContractFactory
  1697. * @param {Array} abi
  1698. */
  1699. var ContractFactory = function (abi) {
  1700. this.abi = abi;
  1701. };
  1702. /**
  1703. * Should be called to create new contract on a blockchain
  1704. *
  1705. * @method new
  1706. * @param {Any} contract constructor param1 (optional)
  1707. * @param {Any} contract constructor param2 (optional)
  1708. * @param {Object} contract transaction object (required)
  1709. * @param {Function} callback
  1710. * @returns {Contract} returns contract instance
  1711. */
  1712. ContractFactory.prototype.new = function () {
  1713. var _this = this;
  1714. var contract = new Contract(this.abi);
  1715. // parse arguments
  1716. var options = {}; // required!
  1717. var callback;
  1718. var args = Array.prototype.slice.call(arguments);
  1719. if (utils.isFunction(args[args.length - 1])) {
  1720. callback = args.pop();
  1721. }
  1722. var last = args[args.length - 1];
  1723. if (utils.isObject(last) && !utils.isArray(last)) {
  1724. options = args.pop();
  1725. }
  1726. // throw an error if there are no options
  1727. var bytes = encodeConstructorParams(this.abi, args);
  1728. options.data += bytes;
  1729. if(callback) {
  1730. // wait for the contract address adn check if the code was deployed
  1731. web3.eth.sendTransaction(options, function (err, hash) {
  1732. if (err) {
  1733. callback(err);
  1734. } else {
  1735. // add the transaction hash
  1736. contract.transactionHash = hash;
  1737. // call callback for the first time
  1738. callback(null, contract);
  1739. checkForContractAddress(contract, _this.abi, callback);
  1740. }
  1741. });
  1742. } else {
  1743. var hash = web3.eth.sendTransaction(options);
  1744. // add the transaction hash
  1745. contract.transactionHash = hash;
  1746. checkForContractAddress(contract, _this.abi);
  1747. }
  1748. return contract;
  1749. };
  1750. /**
  1751. * Should be called to get access to existing contract on a blockchain
  1752. *
  1753. * @method at
  1754. * @param {Address} contract address (required)
  1755. * @param {Function} callback {optional)
  1756. * @returns {Contract} returns contract if no callback was passed,
  1757. * otherwise calls callback function (err, contract)
  1758. */
  1759. ContractFactory.prototype.at = function (address, callback) {
  1760. var contract = new Contract(this.abi, address);
  1761. // TODO: address is required
  1762. // attach functions
  1763. addFunctionsToContract(contract, this.abi);
  1764. addEventsToContract(contract, this.abi);
  1765. if (callback) {
  1766. callback(null, contract);
  1767. }
  1768. return contract;
  1769. };
  1770. /**
  1771. * Should be called to create new contract instance
  1772. *
  1773. * @method Contract
  1774. * @param {Array} abi
  1775. * @param {Address} contract address
  1776. */
  1777. var Contract = function (abi, address) {
  1778. this.address = address;
  1779. };
  1780. module.exports = contract;
  1781. },{"../solidity/coder":1,"../utils/utils":7,"../web3":9,"./allevents":10,"./event":16,"./function":19}],13:[function(require,module,exports){
  1782. /*
  1783. This file is part of ethereum.js.
  1784. ethereum.js is free software: you can redistribute it and/or modify
  1785. it under the terms of the GNU Lesser General Public License as published by
  1786. the Free Software Foundation, either version 3 of the License, or
  1787. (at your option) any later version.
  1788. ethereum.js is distributed in the hope that it will be useful,
  1789. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1790. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1791. GNU Lesser General Public License for more details.
  1792. You should have received a copy of the GNU Lesser General Public License
  1793. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  1794. */
  1795. /** @file db.js
  1796. * @authors:
  1797. * Marek Kotewicz <marek@ethdev.com>
  1798. * @date 2015
  1799. */
  1800. var Method = require('./method');
  1801. var putString = new Method({
  1802. name: 'putString',
  1803. call: 'db_putString',
  1804. params: 3
  1805. });
  1806. var getString = new Method({
  1807. name: 'getString',
  1808. call: 'db_getString',
  1809. params: 2
  1810. });
  1811. var putHex = new Method({
  1812. name: 'putHex',
  1813. call: 'db_putHex',
  1814. params: 3
  1815. });
  1816. var getHex = new Method({
  1817. name: 'getHex',
  1818. call: 'db_getHex',
  1819. params: 2
  1820. });
  1821. var methods = [
  1822. putString, getString, putHex, getHex
  1823. ];
  1824. module.exports = {
  1825. methods: methods
  1826. };
  1827. },{"./method":24}],14:[function(require,module,exports){
  1828. /*
  1829. This file is part of ethereum.js.
  1830. ethereum.js is free software: you can redistribute it and/or modify
  1831. it under the terms of the GNU Lesser General Public License as published by
  1832. the Free Software Foundation, either version 3 of the License, or
  1833. (at your option) any later version.
  1834. ethereum.js is distributed in the hope that it will be useful,
  1835. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1836. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1837. GNU Lesser General Public License for more details.
  1838. You should have received a copy of the GNU Lesser General Public License
  1839. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  1840. */
  1841. /**
  1842. * @file errors.js
  1843. * @author Marek Kotewicz <marek@ethdev.com>
  1844. * @date 2015
  1845. */
  1846. module.exports = {
  1847. InvalidNumberOfParams: function () {
  1848. return new Error('Invalid number of input parameters');
  1849. },
  1850. InvalidConnection: function (host){
  1851. return new Error('CONNECTION ERROR: Couldn\'t connect to node '+ host +', is it running?');
  1852. },
  1853. InvalidProvider: function () {
  1854. return new Error('Providor not set or invalid');
  1855. },
  1856. InvalidResponse: function (result){
  1857. var message = !!result && !!result.error && !!result.error.message ? result.error.message : 'Invalid JSON RPC response: '+ result;
  1858. return new Error(message);
  1859. }
  1860. };
  1861. },{}],15:[function(require,module,exports){
  1862. /*
  1863. This file is part of ethereum.js.
  1864. ethereum.js is free software: you can redistribute it and/or modify
  1865. it under the terms of the GNU Lesser General Public License as published by
  1866. the Free Software Foundation, either version 3 of the License, or
  1867. (at your option) any later version.
  1868. ethereum.js is distributed in the hope that it will be useful,
  1869. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1870. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1871. GNU Lesser General Public License for more details.
  1872. You should have received a copy of the GNU Lesser General Public License
  1873. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  1874. */
  1875. /**
  1876. * @file eth.js
  1877. * @author Marek Kotewicz <marek@ethdev.com>
  1878. * @author Fabian Vogelsteller <fabian@ethdev.com>
  1879. * @date 2015
  1880. */
  1881. /**
  1882. * Web3
  1883. *
  1884. * @module web3
  1885. */
  1886. /**
  1887. * Eth methods and properties
  1888. *
  1889. * An example method object can look as follows:
  1890. *
  1891. * {
  1892. * name: 'getBlock',
  1893. * call: blockCall,
  1894. * params: 2,
  1895. * outputFormatter: formatters.outputBlockFormatter,
  1896. * inputFormatter: [ // can be a formatter funciton or an array of functions. Where each item in the array will be used for one parameter
  1897. * utils.toHex, // formats paramter 1
  1898. * function(param){ return !!param; } // formats paramter 2
  1899. * ]
  1900. * },
  1901. *
  1902. * @class [web3] eth
  1903. * @constructor
  1904. */
  1905. "use strict";
  1906. var formatters = require('./formatters');
  1907. var utils = require('../utils/utils');
  1908. var Method = require('./method');
  1909. var Property = require('./property');
  1910. var blockCall = function (args) {
  1911. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? "eth_getBlockByHash" : "eth_getBlockByNumber";
  1912. };
  1913. var transactionFromBlockCall = function (args) {
  1914. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getTransactionByBlockHashAndIndex' : 'eth_getTransactionByBlockNumberAndIndex';
  1915. };
  1916. var uncleCall = function (args) {
  1917. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleByBlockHashAndIndex' : 'eth_getUncleByBlockNumberAndIndex';
  1918. };
  1919. var getBlockTransactionCountCall = function (args) {
  1920. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getBlockTransactionCountByHash' : 'eth_getBlockTransactionCountByNumber';
  1921. };
  1922. var uncleCountCall = function (args) {
  1923. return (utils.isString(args[0]) && args[0].indexOf('0x') === 0) ? 'eth_getUncleCountByBlockHash' : 'eth_getUncleCountByBlockNumber';
  1924. };
  1925. /// @returns an array of objects describing web3.eth api methods
  1926. var getBalance = new Method({
  1927. name: 'getBalance',
  1928. call: 'eth_getBalance',
  1929. params: 2,
  1930. inputFormatter: [utils.toAddress, formatters.inputDefaultBlockNumberFormatter],
  1931. outputFormatter: formatters.outputBigNumberFormatter
  1932. });
  1933. var getStorageAt = new Method({
  1934. name: 'getStorageAt',
  1935. call: 'eth_getStorageAt',
  1936. params: 3,
  1937. inputFormatter: [null, utils.toHex, formatters.inputDefaultBlockNumberFormatter]
  1938. });
  1939. var getCode = new Method({
  1940. name: 'getCode',
  1941. call: 'eth_getCode',
  1942. params: 2,
  1943. inputFormatter: [utils.toAddress, formatters.inputDefaultBlockNumberFormatter]
  1944. });
  1945. var getBlock = new Method({
  1946. name: 'getBlock',
  1947. call: blockCall,
  1948. params: 2,
  1949. inputFormatter: [formatters.inputBlockNumberFormatter, function (val) { return !!val; }],
  1950. outputFormatter: formatters.outputBlockFormatter
  1951. });
  1952. var getUncle = new Method({
  1953. name: 'getUncle',
  1954. call: uncleCall,
  1955. params: 2,
  1956. inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex],
  1957. outputFormatter: formatters.outputBlockFormatter,
  1958. });
  1959. var getCompilers = new Method({
  1960. name: 'getCompilers',
  1961. call: 'eth_getCompilers',
  1962. params: 0
  1963. });
  1964. var getBlockTransactionCount = new Method({
  1965. name: 'getBlockTransactionCount',
  1966. call: getBlockTransactionCountCall,
  1967. params: 1,
  1968. inputFormatter: [formatters.inputBlockNumberFormatter],
  1969. outputFormatter: utils.toDecimal
  1970. });
  1971. var getBlockUncleCount = new Method({
  1972. name: 'getBlockUncleCount',
  1973. call: uncleCountCall,
  1974. params: 1,
  1975. inputFormatter: [formatters.inputBlockNumberFormatter],
  1976. outputFormatter: utils.toDecimal
  1977. });
  1978. var getTransaction = new Method({
  1979. name: 'getTransaction',
  1980. call: 'eth_getTransactionByHash',
  1981. params: 1,
  1982. outputFormatter: formatters.outputTransactionFormatter
  1983. });
  1984. var getTransactionFromBlock = new Method({
  1985. name: 'getTransactionFromBlock',
  1986. call: transactionFromBlockCall,
  1987. params: 2,
  1988. inputFormatter: [formatters.inputBlockNumberFormatter, utils.toHex],
  1989. outputFormatter: formatters.outputTransactionFormatter
  1990. });
  1991. var getTransactionReceipt = new Method({
  1992. name: 'getTransactionReceipt',
  1993. call: 'eth_getTransactionReceipt',
  1994. params: 1,
  1995. outputFormatter: formatters.outputTransactionReceiptFormatter
  1996. });
  1997. var getTransactionCount = new Method({
  1998. name: 'getTransactionCount',
  1999. call: 'eth_getTransactionCount',
  2000. params: 2,
  2001. inputFormatter: [null, formatters.inputDefaultBlockNumberFormatter],
  2002. outputFormatter: utils.toDecimal
  2003. });
  2004. var sendRawTransaction = new Method({
  2005. name: 'sendRawTransaction',
  2006. call: 'eth_sendRawTransaction',
  2007. params: 1,
  2008. inputFormatter: [null]
  2009. });
  2010. var sendTransaction = new Method({
  2011. name: 'sendTransaction',
  2012. call: 'eth_sendTransaction',
  2013. params: 1,
  2014. inputFormatter: [formatters.inputTransactionFormatter]
  2015. });
  2016. var call = new Method({
  2017. name: 'call',
  2018. call: 'eth_call',
  2019. params: 2,
  2020. inputFormatter: [formatters.inputTransactionFormatter, formatters.inputDefaultBlockNumberFormatter]
  2021. });
  2022. var estimateGas = new Method({
  2023. name: 'estimateGas',
  2024. call: 'eth_estimateGas',
  2025. params: 1,
  2026. inputFormatter: [formatters.inputTransactionFormatter],
  2027. outputFormatter: utils.toDecimal
  2028. });
  2029. var compileSolidity = new Method({
  2030. name: 'compile.solidity',
  2031. call: 'eth_compileSolidity',
  2032. params: 1
  2033. });
  2034. var compileLLL = new Method({
  2035. name: 'compile.lll',
  2036. call: 'eth_compileLLL',
  2037. params: 1
  2038. });
  2039. var compileSerpent = new Method({
  2040. name: 'compile.serpent',
  2041. call: 'eth_compileSerpent',
  2042. params: 1
  2043. });
  2044. var submitWork = new Method({
  2045. name: 'submitWork',
  2046. call: 'eth_submitWork',
  2047. params: 3
  2048. });
  2049. var getWork = new Method({
  2050. name: 'getWork',
  2051. call: 'eth_getWork',
  2052. params: 0
  2053. });
  2054. var methods = [
  2055. getBalance,
  2056. getStorageAt,
  2057. getCode,
  2058. getBlock,
  2059. getUncle,
  2060. getCompilers,
  2061. getBlockTransactionCount,
  2062. getBlockUncleCount,
  2063. getTransaction,
  2064. getTransactionFromBlock,
  2065. getTransactionReceipt,
  2066. getTransactionCount,
  2067. call,
  2068. estimateGas,
  2069. sendRawTransaction,
  2070. sendTransaction,
  2071. compileSolidity,
  2072. compileLLL,
  2073. compileSerpent,
  2074. submitWork,
  2075. getWork
  2076. ];
  2077. /// @returns an array of objects describing web3.eth api properties
  2078. var properties = [
  2079. new Property({
  2080. name: 'coinbase',
  2081. getter: 'eth_coinbase'
  2082. }),
  2083. new Property({
  2084. name: 'mining',
  2085. getter: 'eth_mining'
  2086. }),
  2087. new Property({
  2088. name: 'hashrate',
  2089. getter: 'eth_hashrate',
  2090. outputFormatter: utils.toDecimal
  2091. }),
  2092. new Property({
  2093. name: 'gasPrice',
  2094. getter: 'eth_gasPrice',
  2095. outputFormatter: formatters.outputBigNumberFormatter
  2096. }),
  2097. new Property({
  2098. name: 'accounts',
  2099. getter: 'eth_accounts'
  2100. }),
  2101. new Property({
  2102. name: 'blockNumber',
  2103. getter: 'eth_blockNumber',
  2104. outputFormatter: utils.toDecimal
  2105. })
  2106. ];
  2107. module.exports = {
  2108. methods: methods,
  2109. properties: properties
  2110. };
  2111. },{"../utils/utils":7,"./formatters":18,"./method":24,"./property":27}],16:[function(require,module,exports){
  2112. /*
  2113. This file is part of ethereum.js.
  2114. ethereum.js is free software: you can redistribute it and/or modify
  2115. it under the terms of the GNU Lesser General Public License as published by
  2116. the Free Software Foundation, either version 3 of the License, or
  2117. (at your option) any later version.
  2118. ethereum.js is distributed in the hope that it will be useful,
  2119. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2120. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2121. GNU Lesser General Public License for more details.
  2122. You should have received a copy of the GNU Lesser General Public License
  2123. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  2124. */
  2125. /**
  2126. * @file event.js
  2127. * @author Marek Kotewicz <marek@ethdev.com>
  2128. * @date 2014
  2129. */
  2130. var utils = require('../utils/utils');
  2131. var coder = require('../solidity/coder');
  2132. var formatters = require('./formatters');
  2133. var sha3 = require('../utils/sha3');
  2134. var Filter = require('./filter');
  2135. var watches = require('./watches');
  2136. /**
  2137. * This prototype should be used to create event filters
  2138. */
  2139. var SolidityEvent = function (json, address) {
  2140. this._params = json.inputs;
  2141. this._name = utils.transformToFullName(json);
  2142. this._address = address;
  2143. this._anonymous = json.anonymous;
  2144. };
  2145. /**
  2146. * Should be used to get filtered param types
  2147. *
  2148. * @method types
  2149. * @param {Bool} decide if returned typed should be indexed
  2150. * @return {Array} array of types
  2151. */
  2152. SolidityEvent.prototype.types = function (indexed) {
  2153. return this._params.filter(function (i) {
  2154. return i.indexed === indexed;
  2155. }).map(function (i) {
  2156. return i.type;
  2157. });
  2158. };
  2159. /**
  2160. * Should be used to get event display name
  2161. *
  2162. * @method displayName
  2163. * @return {String} event display name
  2164. */
  2165. SolidityEvent.prototype.displayName = function () {
  2166. return utils.extractDisplayName(this._name);
  2167. };
  2168. /**
  2169. * Should be used to get event type name
  2170. *
  2171. * @method typeName
  2172. * @return {String} event type name
  2173. */
  2174. SolidityEvent.prototype.typeName = function () {
  2175. return utils.extractTypeName(this._name);
  2176. };
  2177. /**
  2178. * Should be used to get event signature
  2179. *
  2180. * @method signature
  2181. * @return {String} event signature
  2182. */
  2183. SolidityEvent.prototype.signature = function () {
  2184. return sha3(this._name);
  2185. };
  2186. /**
  2187. * Should be used to encode indexed params and options to one final object
  2188. *
  2189. * @method encode
  2190. * @param {Object} indexed
  2191. * @param {Object} options
  2192. * @return {Object} everything combined together and encoded
  2193. */
  2194. SolidityEvent.prototype.encode = function (indexed, options) {
  2195. indexed = indexed || {};
  2196. options = options || {};
  2197. var result = {};
  2198. ['fromBlock', 'toBlock'].filter(function (f) {
  2199. return options[f] !== undefined;
  2200. }).forEach(function (f) {
  2201. result[f] = formatters.inputBlockNumberFormatter(options[f]);
  2202. });
  2203. result.topics = [];
  2204. result.address = this._address;
  2205. if (!this._anonymous) {
  2206. result.topics.push('0x' + this.signature());
  2207. }
  2208. var indexedTopics = this._params.filter(function (i) {
  2209. return i.indexed === true;
  2210. }).map(function (i) {
  2211. var value = indexed[i.name];
  2212. if (value === undefined || value === null) {
  2213. return null;
  2214. }
  2215. if (utils.isArray(value)) {
  2216. return value.map(function (v) {
  2217. return '0x' + coder.encodeParam(i.type, v);
  2218. });
  2219. }
  2220. return '0x' + coder.encodeParam(i.type, value);
  2221. });
  2222. result.topics = result.topics.concat(indexedTopics);
  2223. return result;
  2224. };
  2225. /**
  2226. * Should be used to decode indexed params and options
  2227. *
  2228. * @method decode
  2229. * @param {Object} data
  2230. * @return {Object} result object with decoded indexed && not indexed params
  2231. */
  2232. SolidityEvent.prototype.decode = function (data) {
  2233. data.data = data.data || '';
  2234. data.topics = data.topics || [];
  2235. var argTopics = this._anonymous ? data.topics : data.topics.slice(1);
  2236. var indexedData = argTopics.map(function (topics) { return topics.slice(2); }).join("");
  2237. var indexedParams = coder.decodeParams(this.types(true), indexedData);
  2238. var notIndexedData = data.data.slice(2);
  2239. var notIndexedParams = coder.decodeParams(this.types(false), notIndexedData);
  2240. var result = formatters.outputLogFormatter(data);
  2241. result.event = this.displayName();
  2242. result.address = data.address;
  2243. result.args = this._params.reduce(function (acc, current) {
  2244. acc[current.name] = current.indexed ? indexedParams.shift() : notIndexedParams.shift();
  2245. return acc;
  2246. }, {});
  2247. delete result.data;
  2248. delete result.topics;
  2249. return result;
  2250. };
  2251. /**
  2252. * Should be used to create new filter object from event
  2253. *
  2254. * @method execute
  2255. * @param {Object} indexed
  2256. * @param {Object} options
  2257. * @return {Object} filter object
  2258. */
  2259. SolidityEvent.prototype.execute = function (indexed, options, callback) {
  2260. if (utils.isFunction(arguments[arguments.length - 1])) {
  2261. callback = arguments[arguments.length - 1];
  2262. if(arguments.length === 2)
  2263. options = null;
  2264. if(arguments.length === 1) {
  2265. options = null;
  2266. indexed = {};
  2267. }
  2268. }
  2269. var o = this.encode(indexed, options);
  2270. var formatter = this.decode.bind(this);
  2271. return new Filter(o, watches.eth(), formatter, callback);
  2272. };
  2273. /**
  2274. * Should be used to attach event to contract object
  2275. *
  2276. * @method attachToContract
  2277. * @param {Contract}
  2278. */
  2279. SolidityEvent.prototype.attachToContract = function (contract) {
  2280. var execute = this.execute.bind(this);
  2281. var displayName = this.displayName();
  2282. if (!contract[displayName]) {
  2283. contract[displayName] = execute;
  2284. }
  2285. contract[displayName][this.typeName()] = this.execute.bind(this, contract);
  2286. };
  2287. module.exports = SolidityEvent;
  2288. },{"../solidity/coder":1,"../utils/sha3":6,"../utils/utils":7,"./filter":17,"./formatters":18,"./watches":31}],17:[function(require,module,exports){
  2289. /*
  2290. This file is part of ethereum.js.
  2291. ethereum.js is free software: you can redistribute it and/or modify
  2292. it under the terms of the GNU Lesser General Public License as published by
  2293. the Free Software Foundation, either version 3 of the License, or
  2294. (at your option) any later version.
  2295. ethereum.js is distributed in the hope that it will be useful,
  2296. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2297. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2298. GNU Lesser General Public License for more details.
  2299. You should have received a copy of the GNU Lesser General Public License
  2300. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  2301. */
  2302. /** @file filter.js
  2303. * @authors:
  2304. * Jeffrey Wilcke <jeff@ethdev.com>
  2305. * Marek Kotewicz <marek@ethdev.com>
  2306. * Marian Oancea <marian@ethdev.com>
  2307. * Fabian Vogelsteller <fabian@ethdev.com>
  2308. * Gav Wood <g@ethdev.com>
  2309. * @date 2014
  2310. */
  2311. var RequestManager = require('./requestmanager');
  2312. var formatters = require('./formatters');
  2313. var utils = require('../utils/utils');
  2314. /**
  2315. * Converts a given topic to a hex string, but also allows null values.
  2316. *
  2317. * @param {Mixed} value
  2318. * @return {String}
  2319. */
  2320. var toTopic = function(value){
  2321. if(value === null || typeof value === 'undefined')
  2322. return null;
  2323. value = String(value);
  2324. if(value.indexOf('0x') === 0)
  2325. return value;
  2326. else
  2327. return utils.fromAscii(value);
  2328. };
  2329. /// This method should be called on options object, to verify deprecated properties && lazy load dynamic ones
  2330. /// @param should be string or object
  2331. /// @returns options string or object
  2332. var getOptions = function (options) {
  2333. if (utils.isString(options)) {
  2334. return options;
  2335. }
  2336. options = options || {};
  2337. // make sure topics, get converted to hex
  2338. options.topics = options.topics || [];
  2339. options.topics = options.topics.map(function(topic){
  2340. return (utils.isArray(topic)) ? topic.map(toTopic) : toTopic(topic);
  2341. });
  2342. // lazy load
  2343. return {
  2344. topics: options.topics,
  2345. to: options.to,
  2346. address: options.address,
  2347. fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock),
  2348. toBlock: formatters.inputBlockNumberFormatter(options.toBlock)
  2349. };
  2350. };
  2351. /**
  2352. Adds the callback and sets up the methods, to iterate over the results.
  2353. @method getLogsAtStart
  2354. @param {Object} self
  2355. @param {funciton}
  2356. */
  2357. var getLogsAtStart = function(self, callback){
  2358. // call getFilterLogs for the first watch callback start
  2359. if (!utils.isString(self.options)) {
  2360. self.get(function (err, messages) {
  2361. // don't send all the responses to all the watches again... just to self one
  2362. if (err) {
  2363. callback(err);
  2364. }
  2365. if(utils.isArray(messages)) {
  2366. messages.forEach(function (message) {
  2367. callback(null, message);
  2368. });
  2369. }
  2370. });
  2371. }
  2372. };
  2373. /**
  2374. Adds the callback and sets up the methods, to iterate over the results.
  2375. @method pollFilter
  2376. @param {Object} self
  2377. */
  2378. var pollFilter = function(self) {
  2379. var onMessage = function (error, messages) {
  2380. if (error) {
  2381. return self.callbacks.forEach(function (callback) {
  2382. callback(error);
  2383. });
  2384. }
  2385. messages.forEach(function (message) {
  2386. message = self.formatter ? self.formatter(message) : message;
  2387. self.callbacks.forEach(function (callback) {
  2388. callback(null, message);
  2389. });
  2390. });
  2391. };
  2392. RequestManager.getInstance().startPolling({
  2393. method: self.implementation.poll.call,
  2394. params: [self.filterId],
  2395. }, self.filterId, onMessage, self.stopWatching.bind(self));
  2396. };
  2397. var Filter = function (options, methods, formatter, callback) {
  2398. var self = this;
  2399. var implementation = {};
  2400. methods.forEach(function (method) {
  2401. method.attachToObject(implementation);
  2402. });
  2403. this.options = getOptions(options);
  2404. this.implementation = implementation;
  2405. this.filterId = null;
  2406. this.callbacks = [];
  2407. this.pollFilters = [];
  2408. this.formatter = formatter;
  2409. this.implementation.newFilter(this.options, function(error, id){
  2410. if(error) {
  2411. self.callbacks.forEach(function(cb){
  2412. cb(error);
  2413. });
  2414. } else {
  2415. self.filterId = id;
  2416. // get filter logs for the already existing watch calls
  2417. self.callbacks.forEach(function(cb){
  2418. getLogsAtStart(self, cb);
  2419. });
  2420. if(self.callbacks.length > 0)
  2421. pollFilter(self);
  2422. // start to watch immediately
  2423. if(callback) {
  2424. return self.watch(callback);
  2425. }
  2426. }
  2427. });
  2428. };
  2429. Filter.prototype.watch = function (callback) {
  2430. this.callbacks.push(callback);
  2431. if(this.filterId) {
  2432. getLogsAtStart(this, callback);
  2433. pollFilter(this);
  2434. }
  2435. return this;
  2436. };
  2437. Filter.prototype.stopWatching = function () {
  2438. RequestManager.getInstance().stopPolling(this.filterId);
  2439. // remove filter async
  2440. this.implementation.uninstallFilter(this.filterId, function(){});
  2441. this.callbacks = [];
  2442. };
  2443. Filter.prototype.get = function (callback) {
  2444. var self = this;
  2445. if (utils.isFunction(callback)) {
  2446. this.implementation.getLogs(this.filterId, function(err, res){
  2447. if (err) {
  2448. callback(err);
  2449. } else {
  2450. callback(null, res.map(function (log) {
  2451. return self.formatter ? self.formatter(log) : log;
  2452. }));
  2453. }
  2454. });
  2455. } else {
  2456. var logs = this.implementation.getLogs(this.filterId);
  2457. return logs.map(function (log) {
  2458. return self.formatter ? self.formatter(log) : log;
  2459. });
  2460. }
  2461. return this;
  2462. };
  2463. module.exports = Filter;
  2464. },{"../utils/utils":7,"./formatters":18,"./requestmanager":28}],18:[function(require,module,exports){
  2465. /*
  2466. This file is part of ethereum.js.
  2467. ethereum.js is free software: you can redistribute it and/or modify
  2468. it under the terms of the GNU Lesser General Public License as published by
  2469. the Free Software Foundation, either version 3 of the License, or
  2470. (at your option) any later version.
  2471. ethereum.js is distributed in the hope that it will be useful,
  2472. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2473. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2474. GNU Lesser General Public License for more details.
  2475. You should have received a copy of the GNU Lesser General Public License
  2476. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  2477. */
  2478. /**
  2479. * @file formatters.js
  2480. * @author Marek Kotewicz <marek@ethdev.com>
  2481. * @author Fabian Vogelsteller <fabian@ethdev.com>
  2482. * @date 2015
  2483. */
  2484. var utils = require('../utils/utils');
  2485. var config = require('../utils/config');
  2486. /**
  2487. * Should the format output to a big number
  2488. *
  2489. * @method outputBigNumberFormatter
  2490. * @param {String|Number|BigNumber}
  2491. * @returns {BigNumber} object
  2492. */
  2493. var outputBigNumberFormatter = function (number) {
  2494. return utils.toBigNumber(number);
  2495. };
  2496. var isPredefinedBlockNumber = function (blockNumber) {
  2497. return blockNumber === 'latest' || blockNumber === 'pending' || blockNumber === 'earliest';
  2498. };
  2499. var inputDefaultBlockNumberFormatter = function (blockNumber) {
  2500. if (blockNumber === undefined) {
  2501. return config.defaultBlock;
  2502. }
  2503. return inputBlockNumberFormatter(blockNumber);
  2504. };
  2505. var inputBlockNumberFormatter = function (blockNumber) {
  2506. if (blockNumber === undefined) {
  2507. return undefined;
  2508. } else if (isPredefinedBlockNumber(blockNumber)) {
  2509. return blockNumber;
  2510. }
  2511. return utils.toHex(blockNumber);
  2512. };
  2513. /**
  2514. * Formats the input of a transaction and converts all values to HEX
  2515. *
  2516. * @method inputTransactionFormatter
  2517. * @param {Object} transaction options
  2518. * @returns object
  2519. */
  2520. var inputTransactionFormatter = function (options){
  2521. options.from = options.from || config.defaultAccount;
  2522. // make code -> data
  2523. if (options.code) {
  2524. options.data = options.code;
  2525. delete options.code;
  2526. }
  2527. ['gasPrice', 'gas', 'value', 'nonce'].filter(function (key) {
  2528. return options[key] !== undefined;
  2529. }).forEach(function(key){
  2530. options[key] = utils.fromDecimal(options[key]);
  2531. });
  2532. return options;
  2533. };
  2534. /**
  2535. * Formats the output of a transaction to its proper values
  2536. *
  2537. * @method outputTransactionFormatter
  2538. * @param {Object} tx
  2539. * @returns {Object}
  2540. */
  2541. var outputTransactionFormatter = function (tx){
  2542. if(tx.blockNumber !== null)
  2543. tx.blockNumber = utils.toDecimal(tx.blockNumber);
  2544. if(tx.transactionIndex !== null)
  2545. tx.transactionIndex = utils.toDecimal(tx.transactionIndex);
  2546. tx.nonce = utils.toDecimal(tx.nonce);
  2547. tx.gas = utils.toDecimal(tx.gas);
  2548. tx.gasPrice = utils.toBigNumber(tx.gasPrice);
  2549. tx.value = utils.toBigNumber(tx.value);
  2550. return tx;
  2551. };
  2552. /**
  2553. * Formats the output of a transaction receipt to its proper values
  2554. *
  2555. * @method outputTransactionReceiptFormatter
  2556. * @param {Object} receipt
  2557. * @returns {Object}
  2558. */
  2559. var outputTransactionReceiptFormatter = function (receipt){
  2560. if(receipt.blockNumber !== null)
  2561. receipt.blockNumber = utils.toDecimal(receipt.blockNumber);
  2562. if(receipt.transactionIndex !== null)
  2563. receipt.transactionIndex = utils.toDecimal(receipt.transactionIndex);
  2564. receipt.cumulativeGasUsed = utils.toDecimal(receipt.cumulativeGasUsed);
  2565. receipt.gasUsed = utils.toDecimal(receipt.gasUsed);
  2566. if(utils.isArray(receipt.logs)) {
  2567. receipt.logs = receipt.logs.map(function(log){
  2568. return outputLogFormatter(log);
  2569. });
  2570. }
  2571. return receipt;
  2572. };
  2573. /**
  2574. * Formats the output of a block to its proper values
  2575. *
  2576. * @method outputBlockFormatter
  2577. * @param {Object} block
  2578. * @returns {Object}
  2579. */
  2580. var outputBlockFormatter = function(block) {
  2581. // transform to number
  2582. block.gasLimit = utils.toDecimal(block.gasLimit);
  2583. block.gasUsed = utils.toDecimal(block.gasUsed);
  2584. block.size = utils.toDecimal(block.size);
  2585. block.timestamp = utils.toDecimal(block.timestamp);
  2586. if(block.number !== null)
  2587. block.number = utils.toDecimal(block.number);
  2588. block.difficulty = utils.toBigNumber(block.difficulty);
  2589. block.totalDifficulty = utils.toBigNumber(block.totalDifficulty);
  2590. if (utils.isArray(block.transactions)) {
  2591. block.transactions.forEach(function(item){
  2592. if(!utils.isString(item))
  2593. return outputTransactionFormatter(item);
  2594. });
  2595. }
  2596. return block;
  2597. };
  2598. /**
  2599. * Formats the output of a log
  2600. *
  2601. * @method outputLogFormatter
  2602. * @param {Object} log object
  2603. * @returns {Object} log
  2604. */
  2605. var outputLogFormatter = function(log) {
  2606. if(log.blockNumber !== null)
  2607. log.blockNumber = utils.toDecimal(log.blockNumber);
  2608. if(log.transactionIndex !== null)
  2609. log.transactionIndex = utils.toDecimal(log.transactionIndex);
  2610. if(log.logIndex !== null)
  2611. log.logIndex = utils.toDecimal(log.logIndex);
  2612. return log;
  2613. };
  2614. /**
  2615. * Formats the input of a whisper post and converts all values to HEX
  2616. *
  2617. * @method inputPostFormatter
  2618. * @param {Object} transaction object
  2619. * @returns {Object}
  2620. */
  2621. var inputPostFormatter = function(post) {
  2622. post.payload = utils.toHex(post.payload);
  2623. post.ttl = utils.fromDecimal(post.ttl);
  2624. post.workToProve = utils.fromDecimal(post.workToProve);
  2625. post.priority = utils.fromDecimal(post.priority);
  2626. // fallback
  2627. if (!utils.isArray(post.topics)) {
  2628. post.topics = post.topics ? [post.topics] : [];
  2629. }
  2630. // format the following options
  2631. post.topics = post.topics.map(function(topic){
  2632. return utils.fromAscii(topic);
  2633. });
  2634. return post;
  2635. };
  2636. /**
  2637. * Formats the output of a received post message
  2638. *
  2639. * @method outputPostFormatter
  2640. * @param {Object}
  2641. * @returns {Object}
  2642. */
  2643. var outputPostFormatter = function(post){
  2644. post.expiry = utils.toDecimal(post.expiry);
  2645. post.sent = utils.toDecimal(post.sent);
  2646. post.ttl = utils.toDecimal(post.ttl);
  2647. post.workProved = utils.toDecimal(post.workProved);
  2648. post.payloadRaw = post.payload;
  2649. post.payload = utils.toAscii(post.payload);
  2650. if (utils.isJson(post.payload)) {
  2651. post.payload = JSON.parse(post.payload);
  2652. }
  2653. // format the following options
  2654. if (!post.topics) {
  2655. post.topics = [];
  2656. }
  2657. post.topics = post.topics.map(function(topic){
  2658. return utils.toAscii(topic);
  2659. });
  2660. return post;
  2661. };
  2662. module.exports = {
  2663. inputDefaultBlockNumberFormatter: inputDefaultBlockNumberFormatter,
  2664. inputBlockNumberFormatter: inputBlockNumberFormatter,
  2665. inputTransactionFormatter: inputTransactionFormatter,
  2666. inputPostFormatter: inputPostFormatter,
  2667. outputBigNumberFormatter: outputBigNumberFormatter,
  2668. outputTransactionFormatter: outputTransactionFormatter,
  2669. outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
  2670. outputBlockFormatter: outputBlockFormatter,
  2671. outputLogFormatter: outputLogFormatter,
  2672. outputPostFormatter: outputPostFormatter
  2673. };
  2674. },{"../utils/config":5,"../utils/utils":7}],19:[function(require,module,exports){
  2675. /*
  2676. This file is part of ethereum.js.
  2677. ethereum.js is free software: you can redistribute it and/or modify
  2678. it under the terms of the GNU Lesser General Public License as published by
  2679. the Free Software Foundation, either version 3 of the License, or
  2680. (at your option) any later version.
  2681. ethereum.js is distributed in the hope that it will be useful,
  2682. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2683. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2684. GNU Lesser General Public License for more details.
  2685. You should have received a copy of the GNU Lesser General Public License
  2686. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  2687. */
  2688. /**
  2689. * @file function.js
  2690. * @author Marek Kotewicz <marek@ethdev.com>
  2691. * @date 2015
  2692. */
  2693. var web3 = require('../web3');
  2694. var coder = require('../solidity/coder');
  2695. var utils = require('../utils/utils');
  2696. var formatters = require('./formatters');
  2697. var sha3 = require('../utils/sha3');
  2698. /**
  2699. * This prototype should be used to call/sendTransaction to solidity functions
  2700. */
  2701. var SolidityFunction = function (json, address) {
  2702. this._inputTypes = json.inputs.map(function (i) {
  2703. return i.type;
  2704. });
  2705. this._outputTypes = json.outputs.map(function (i) {
  2706. return i.type;
  2707. });
  2708. this._constant = json.constant;
  2709. this._name = utils.transformToFullName(json);
  2710. this._address = address;
  2711. };
  2712. SolidityFunction.prototype.extractCallback = function (args) {
  2713. if (utils.isFunction(args[args.length - 1])) {
  2714. return args.pop(); // modify the args array!
  2715. }
  2716. };
  2717. SolidityFunction.prototype.extractDefaultBlock = function (args) {
  2718. if (args.length > this._inputTypes.length && !utils.isObject(args[args.length -1])) {
  2719. return formatters.inputDefaultBlockNumberFormatter(args.pop()); // modify the args array!
  2720. }
  2721. };
  2722. /**
  2723. * Should be used to create payload from arguments
  2724. *
  2725. * @method toPayload
  2726. * @param {Array} solidity function params
  2727. * @param {Object} optional payload options
  2728. */
  2729. SolidityFunction.prototype.toPayload = function (args) {
  2730. var options = {};
  2731. if (args.length > this._inputTypes.length && utils.isObject(args[args.length -1])) {
  2732. options = args[args.length - 1];
  2733. }
  2734. options.to = this._address;
  2735. options.data = '0x' + this.signature() + coder.encodeParams(this._inputTypes, args);
  2736. return options;
  2737. };
  2738. /**
  2739. * Should be used to get function signature
  2740. *
  2741. * @method signature
  2742. * @return {String} function signature
  2743. */
  2744. SolidityFunction.prototype.signature = function () {
  2745. return sha3(this._name).slice(0, 8);
  2746. };
  2747. SolidityFunction.prototype.unpackOutput = function (output) {
  2748. if (!output) {
  2749. return;
  2750. }
  2751. output = output.length >= 2 ? output.slice(2) : output;
  2752. var result = coder.decodeParams(this._outputTypes, output);
  2753. return result.length === 1 ? result[0] : result;
  2754. };
  2755. /**
  2756. * Calls a contract function.
  2757. *
  2758. * @method call
  2759. * @param {...Object} Contract function arguments
  2760. * @param {function} If the last argument is a function, the contract function
  2761. * call will be asynchronous, and the callback will be passed the
  2762. * error and result.
  2763. * @return {String} output bytes
  2764. */
  2765. SolidityFunction.prototype.call = function () {
  2766. var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
  2767. var callback = this.extractCallback(args);
  2768. var defaultBlock = this.extractDefaultBlock(args);
  2769. var payload = this.toPayload(args);
  2770. if (!callback) {
  2771. var output = web3.eth.call(payload, defaultBlock);
  2772. return this.unpackOutput(output);
  2773. }
  2774. var self = this;
  2775. web3.eth.call(payload, defaultBlock, function (error, output) {
  2776. callback(error, self.unpackOutput(output));
  2777. });
  2778. };
  2779. /**
  2780. * Should be used to sendTransaction to solidity function
  2781. *
  2782. * @method sendTransaction
  2783. * @param {Object} options
  2784. */
  2785. SolidityFunction.prototype.sendTransaction = function () {
  2786. var args = Array.prototype.slice.call(arguments).filter(function (a) {return a !== undefined; });
  2787. var callback = this.extractCallback(args);
  2788. var payload = this.toPayload(args);
  2789. if (!callback) {
  2790. return web3.eth.sendTransaction(payload);
  2791. }
  2792. web3.eth.sendTransaction(payload, callback);
  2793. };
  2794. /**
  2795. * Should be used to estimateGas of solidity function
  2796. *
  2797. * @method estimateGas
  2798. * @param {Object} options
  2799. */
  2800. SolidityFunction.prototype.estimateGas = function () {
  2801. var args = Array.prototype.slice.call(arguments);
  2802. var callback = this.extractCallback(args);
  2803. var payload = this.toPayload(args);
  2804. if (!callback) {
  2805. return web3.eth.estimateGas(payload);
  2806. }
  2807. web3.eth.estimateGas(payload, callback);
  2808. };
  2809. /**
  2810. * Should be used to get function display name
  2811. *
  2812. * @method displayName
  2813. * @return {String} display name of the function
  2814. */
  2815. SolidityFunction.prototype.displayName = function () {
  2816. return utils.extractDisplayName(this._name);
  2817. };
  2818. /**
  2819. * Should be used to get function type name
  2820. *
  2821. * @method typeName
  2822. * @return {String} type name of the function
  2823. */
  2824. SolidityFunction.prototype.typeName = function () {
  2825. return utils.extractTypeName(this._name);
  2826. };
  2827. /**
  2828. * Should be called to get rpc requests from solidity function
  2829. *
  2830. * @method request
  2831. * @returns {Object}
  2832. */
  2833. SolidityFunction.prototype.request = function () {
  2834. var args = Array.prototype.slice.call(arguments);
  2835. var callback = this.extractCallback(args);
  2836. var payload = this.toPayload(args);
  2837. var format = this.unpackOutput.bind(this);
  2838. return {
  2839. method: this._constant ? 'eth_call' : 'eth_sendTransaction',
  2840. callback: callback,
  2841. params: [payload],
  2842. format: format
  2843. };
  2844. };
  2845. /**
  2846. * Should be called to execute function
  2847. *
  2848. * @method execute
  2849. */
  2850. SolidityFunction.prototype.execute = function () {
  2851. var transaction = !this._constant;
  2852. // send transaction
  2853. if (transaction) {
  2854. return this.sendTransaction.apply(this, Array.prototype.slice.call(arguments));
  2855. }
  2856. // call
  2857. return this.call.apply(this, Array.prototype.slice.call(arguments));
  2858. };
  2859. /**
  2860. * Should be called to attach function to contract
  2861. *
  2862. * @method attachToContract
  2863. * @param {Contract}
  2864. */
  2865. SolidityFunction.prototype.attachToContract = function (contract) {
  2866. var execute = this.execute.bind(this);
  2867. execute.request = this.request.bind(this);
  2868. execute.call = this.call.bind(this);
  2869. execute.sendTransaction = this.sendTransaction.bind(this);
  2870. execute.estimateGas = this.estimateGas.bind(this);
  2871. var displayName = this.displayName();
  2872. if (!contract[displayName]) {
  2873. contract[displayName] = execute;
  2874. }
  2875. contract[displayName][this.typeName()] = execute; // circular!!!!
  2876. };
  2877. module.exports = SolidityFunction;
  2878. },{"../solidity/coder":1,"../utils/sha3":6,"../utils/utils":7,"../web3":9,"./formatters":18}],20:[function(require,module,exports){
  2879. /*
  2880. This file is part of ethereum.js.
  2881. ethereum.js is free software: you can redistribute it and/or modify
  2882. it under the terms of the GNU Lesser General Public License as published by
  2883. the Free Software Foundation, either version 3 of the License, or
  2884. (at your option) any later version.
  2885. ethereum.js is distributed in the hope that it will be useful,
  2886. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2887. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2888. GNU Lesser General Public License for more details.
  2889. You should have received a copy of the GNU Lesser General Public License
  2890. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  2891. */
  2892. /** @file httpprovider.js
  2893. * @authors:
  2894. * Marek Kotewicz <marek@ethdev.com>
  2895. * Marian Oancea <marian@ethdev.com>
  2896. * Fabian Vogelsteller <fabian@ethdev.com>
  2897. * @date 2015
  2898. */
  2899. "use strict";
  2900. var XMLHttpRequest = (typeof window !== 'undefined' && window.XMLHttpRequest) ? window.XMLHttpRequest : require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line
  2901. var errors = require('./errors');
  2902. var HttpProvider = function (host) {
  2903. this.host = host || 'http://localhost:8545';
  2904. };
  2905. HttpProvider.prototype.isConnected = function() {
  2906. var request = new XMLHttpRequest();
  2907. request.open('POST', this.host, false);
  2908. request.setRequestHeader('Content-type','application/json');
  2909. try {
  2910. request.send(JSON.stringify({
  2911. id: 9999999999,
  2912. jsonrpc: '2.0',
  2913. method: 'net_listening',
  2914. params: []
  2915. }));
  2916. return true;
  2917. } catch(e) {
  2918. return false;
  2919. }
  2920. };
  2921. HttpProvider.prototype.send = function (payload) {
  2922. var request = new XMLHttpRequest();
  2923. request.open('POST', this.host, false);
  2924. request.setRequestHeader('Content-type','application/json');
  2925. try {
  2926. request.send(JSON.stringify(payload));
  2927. } catch(error) {
  2928. throw errors.InvalidConnection(this.host);
  2929. }
  2930. // check request.status
  2931. // TODO: throw an error here! it cannot silently fail!!!
  2932. //if (request.status !== 200) {
  2933. //return;
  2934. //}
  2935. var result = request.responseText;
  2936. try {
  2937. result = JSON.parse(result);
  2938. } catch(e) {
  2939. throw errors.InvalidResponse(request.responseText);
  2940. }
  2941. return result;
  2942. };
  2943. HttpProvider.prototype.sendAsync = function (payload, callback) {
  2944. var request = new XMLHttpRequest();
  2945. request.onreadystatechange = function() {
  2946. if (request.readyState === 4) {
  2947. var result = request.responseText;
  2948. var error = null;
  2949. try {
  2950. result = JSON.parse(result);
  2951. } catch(e) {
  2952. error = errors.InvalidResponse(request.responseText);
  2953. }
  2954. callback(error, result);
  2955. }
  2956. };
  2957. request.open('POST', this.host, true);
  2958. request.setRequestHeader('Content-type','application/json');
  2959. try {
  2960. request.send(JSON.stringify(payload));
  2961. } catch(error) {
  2962. callback(errors.InvalidConnection(this.host));
  2963. }
  2964. };
  2965. module.exports = HttpProvider;
  2966. },{"./errors":14,"xmlhttprequest":4}],21:[function(require,module,exports){
  2967. /*
  2968. This file is part of ethereum.js.
  2969. ethereum.js is free software: you can redistribute it and/or modify
  2970. it under the terms of the GNU Lesser General Public License as published by
  2971. the Free Software Foundation, either version 3 of the License, or
  2972. (at your option) any later version.
  2973. ethereum.js is distributed in the hope that it will be useful,
  2974. but WITHOUT ANY WARRANTY; without even the implied warranty of
  2975. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2976. GNU Lesser General Public License for more details.
  2977. You should have received a copy of the GNU Lesser General Public License
  2978. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  2979. */
  2980. /**
  2981. * @file icap.js
  2982. * @author Marek Kotewicz <marek@ethdev.com>
  2983. * @date 2015
  2984. */
  2985. var utils = require('../utils/utils');
  2986. /**
  2987. * This prototype should be used to extract necessary information from iban address
  2988. *
  2989. * @param {String} iban
  2990. */
  2991. var ICAP = function (iban) {
  2992. this._iban = iban;
  2993. };
  2994. /**
  2995. * Should be called to check if icap is correct
  2996. *
  2997. * @method isValid
  2998. * @returns {Boolean} true if it is, otherwise false
  2999. */
  3000. ICAP.prototype.isValid = function () {
  3001. return utils.isIBAN(this._iban);
  3002. };
  3003. /**
  3004. * Should be called to check if iban number is direct
  3005. *
  3006. * @method isDirect
  3007. * @returns {Boolean} true if it is, otherwise false
  3008. */
  3009. ICAP.prototype.isDirect = function () {
  3010. return this._iban.length === 34;
  3011. };
  3012. /**
  3013. * Should be called to check if iban number if indirect
  3014. *
  3015. * @method isIndirect
  3016. * @returns {Boolean} true if it is, otherwise false
  3017. */
  3018. ICAP.prototype.isIndirect = function () {
  3019. return this._iban.length === 20;
  3020. };
  3021. /**
  3022. * Should be called to get iban checksum
  3023. * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003)
  3024. *
  3025. * @method checksum
  3026. * @returns {String} checksum
  3027. */
  3028. ICAP.prototype.checksum = function () {
  3029. return this._iban.substr(2, 2);
  3030. };
  3031. /**
  3032. * Should be called to get institution identifier
  3033. * eg. XREG
  3034. *
  3035. * @method institution
  3036. * @returns {String} institution identifier
  3037. */
  3038. ICAP.prototype.institution = function () {
  3039. return this.isIndirect() ? this._iban.substr(7, 4) : '';
  3040. };
  3041. /**
  3042. * Should be called to get client identifier within institution
  3043. * eg. GAVOFYORK
  3044. *
  3045. * @method client
  3046. * @returns {String} client identifier
  3047. */
  3048. ICAP.prototype.client = function () {
  3049. return this.isIndirect() ? this._iban.substr(11) : '';
  3050. };
  3051. /**
  3052. * Should be called to get client direct address
  3053. *
  3054. * @method address
  3055. * @returns {String} client direct address
  3056. */
  3057. ICAP.prototype.address = function () {
  3058. return this.isDirect() ? this._iban.substr(4) : '';
  3059. };
  3060. module.exports = ICAP;
  3061. },{"../utils/utils":7}],22:[function(require,module,exports){
  3062. /*
  3063. This file is part of ethereum.js.
  3064. ethereum.js is free software: you can redistribute it and/or modify
  3065. it under the terms of the GNU Lesser General Public License as published by
  3066. the Free Software Foundation, either version 3 of the License, or
  3067. (at your option) any later version.
  3068. ethereum.js is distributed in the hope that it will be useful,
  3069. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3070. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3071. GNU Lesser General Public License for more details.
  3072. You should have received a copy of the GNU Lesser General Public License
  3073. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  3074. */
  3075. /** @file ipcprovider.js
  3076. * @authors:
  3077. * Fabian Vogelsteller <fabian@ethdev.com>
  3078. * @date 2015
  3079. */
  3080. "use strict";
  3081. var utils = require('../utils/utils');
  3082. var errors = require('./errors');
  3083. var errorTimeout = '{"jsonrpc": "2.0", "error": {"code": -32603, "message": "IPC Request timed out for method \'__method__\'"}, "id": "__id__"}';
  3084. var IpcProvider = function (path, net) {
  3085. var _this = this;
  3086. this.responseCallbacks = {};
  3087. this.path = path;
  3088. net = net || require('net');
  3089. this.connection = net.connect({path: this.path});
  3090. this.connection.on('error', function(e){
  3091. console.error('IPC Connection Error', e);
  3092. _this._timeout();
  3093. });
  3094. this.connection.on('end', function(){
  3095. _this._timeout();
  3096. });
  3097. // LISTEN FOR CONNECTION RESPONSES
  3098. this.connection.on('data', function(data) {
  3099. /*jshint maxcomplexity: 6 */
  3100. _this._parseResponse(data.toString()).forEach(function(result){
  3101. var id = null;
  3102. // get the id which matches the returned id
  3103. if(utils.isArray(result)) {
  3104. result.forEach(function(load){
  3105. if(_this.responseCallbacks[load.id])
  3106. id = load.id;
  3107. });
  3108. } else {
  3109. id = result.id;
  3110. }
  3111. // fire the callback
  3112. if(_this.responseCallbacks[id]) {
  3113. _this.responseCallbacks[id](null, result);
  3114. delete _this.responseCallbacks[id];
  3115. }
  3116. });
  3117. });
  3118. };
  3119. /**
  3120. Will parse the response and make an array out of it.
  3121. @method _parseResponse
  3122. @param {String} data
  3123. */
  3124. IpcProvider.prototype._parseResponse = function(data) {
  3125. var _this = this,
  3126. returnValues = [];
  3127. // DE-CHUNKER
  3128. var dechunkedData = data
  3129. .replace(/\}\{/g,'}|--|{') // }{
  3130. .replace(/\}\]\[\{/g,'}]|--|[{') // }][{
  3131. .replace(/\}\[\{/g,'}|--|[{') // }[{
  3132. .replace(/\}\]\{/g,'}]|--|{') // }]{
  3133. .split('|--|');
  3134. dechunkedData.forEach(function(data){
  3135. // prepend the last chunk
  3136. if(_this.lastChunk)
  3137. data = _this.lastChunk + data;
  3138. var result = null;
  3139. try {
  3140. result = JSON.parse(data);
  3141. } catch(e) {
  3142. _this.lastChunk = data;
  3143. // start timeout to cancel all requests
  3144. clearTimeout(_this.lastChunkTimeout);
  3145. _this.lastChunkTimeout = setTimeout(function(){
  3146. _this.timeout();
  3147. throw errors.InvalidResponse(data);
  3148. }, 1000 * 15);
  3149. return;
  3150. }
  3151. // cancel timeout and set chunk to null
  3152. clearTimeout(_this.lastChunkTimeout);
  3153. _this.lastChunk = null;
  3154. if(result)
  3155. returnValues.push(result);
  3156. });
  3157. return returnValues;
  3158. };
  3159. /**
  3160. Get the adds a callback to the responseCallbacks object,
  3161. which will be called if a response matching the response Id will arrive.
  3162. @method _addResponseCallback
  3163. */
  3164. IpcProvider.prototype._addResponseCallback = function(payload, callback) {
  3165. var id = payload.id || payload[0].id;
  3166. var method = payload.method || payload[0].method;
  3167. this.responseCallbacks[id] = callback;
  3168. this.responseCallbacks[id].method = method;
  3169. };
  3170. /**
  3171. Timeout all requests when the end/error event is fired
  3172. @method _timeout
  3173. */
  3174. IpcProvider.prototype._timeout = function() {
  3175. for(var key in this.responseCallbacks) {
  3176. if(this.responseCallbacks.hasOwnProperty(key)){
  3177. this.responseCallbacks[key](errorTimeout.replace('__id__', key).replace('__method__', this.responseCallbacks[key].method));
  3178. delete this.responseCallbacks[key];
  3179. }
  3180. }
  3181. };
  3182. /**
  3183. Check if the current connection is still valid.
  3184. @method isConnected
  3185. */
  3186. IpcProvider.prototype.isConnected = function() {
  3187. var _this = this;
  3188. // try reconnect, when connection is gone
  3189. if(!_this.connection.writable)
  3190. _this.connection.connect({path: _this.path});
  3191. return !!this.connection.writable;
  3192. };
  3193. IpcProvider.prototype.send = function (payload) {
  3194. if(this.connection.writeSync) {
  3195. var result;
  3196. // try reconnect, when connection is gone
  3197. if(!this.connection.writable)
  3198. this.connection.connect({path: this.path});
  3199. var data = this.connection.writeSync(JSON.stringify(payload));
  3200. try {
  3201. result = JSON.parse(data);
  3202. } catch(e) {
  3203. throw errors.InvalidResponse(data);
  3204. }
  3205. return result;
  3206. } else {
  3207. throw new Error('You tried to send "'+ payload.method +'" synchronously. Synchronous requests are not supported by the IPC provider.');
  3208. }
  3209. };
  3210. IpcProvider.prototype.sendAsync = function (payload, callback) {
  3211. // try reconnect, when connection is gone
  3212. if(!this.connection.writable)
  3213. this.connection.connect({path: this.path});
  3214. this.connection.write(JSON.stringify(payload));
  3215. this._addResponseCallback(payload, callback);
  3216. };
  3217. module.exports = IpcProvider;
  3218. },{"../utils/utils":7,"./errors":14,"net":32}],23:[function(require,module,exports){
  3219. /*
  3220. This file is part of ethereum.js.
  3221. ethereum.js is free software: you can redistribute it and/or modify
  3222. it under the terms of the GNU Lesser General Public License as published by
  3223. the Free Software Foundation, either version 3 of the License, or
  3224. (at your option) any later version.
  3225. ethereum.js is distributed in the hope that it will be useful,
  3226. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3227. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3228. GNU Lesser General Public License for more details.
  3229. You should have received a copy of the GNU Lesser General Public License
  3230. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  3231. */
  3232. /** @file jsonrpc.js
  3233. * @authors:
  3234. * Marek Kotewicz <marek@ethdev.com>
  3235. * @date 2015
  3236. */
  3237. var Jsonrpc = function () {
  3238. // singleton pattern
  3239. if (arguments.callee._singletonInstance) {
  3240. return arguments.callee._singletonInstance;
  3241. }
  3242. arguments.callee._singletonInstance = this;
  3243. this.messageId = 1;
  3244. };
  3245. /**
  3246. * @return {Jsonrpc} singleton
  3247. */
  3248. Jsonrpc.getInstance = function () {
  3249. var instance = new Jsonrpc();
  3250. return instance;
  3251. };
  3252. /**
  3253. * Should be called to valid json create payload object
  3254. *
  3255. * @method toPayload
  3256. * @param {Function} method of jsonrpc call, required
  3257. * @param {Array} params, an array of method params, optional
  3258. * @returns {Object} valid jsonrpc payload object
  3259. */
  3260. Jsonrpc.prototype.toPayload = function (method, params) {
  3261. if (!method)
  3262. console.error('jsonrpc method should be specified!');
  3263. return {
  3264. jsonrpc: '2.0',
  3265. method: method,
  3266. params: params || [],
  3267. id: this.messageId++
  3268. };
  3269. };
  3270. /**
  3271. * Should be called to check if jsonrpc response is valid
  3272. *
  3273. * @method isValidResponse
  3274. * @param {Object}
  3275. * @returns {Boolean} true if response is valid, otherwise false
  3276. */
  3277. Jsonrpc.prototype.isValidResponse = function (response) {
  3278. return !!response &&
  3279. !response.error &&
  3280. response.jsonrpc === '2.0' &&
  3281. typeof response.id === 'number' &&
  3282. response.result !== undefined; // only undefined is not valid json object
  3283. };
  3284. /**
  3285. * Should be called to create batch payload object
  3286. *
  3287. * @method toBatchPayload
  3288. * @param {Array} messages, an array of objects with method (required) and params (optional) fields
  3289. * @returns {Array} batch payload
  3290. */
  3291. Jsonrpc.prototype.toBatchPayload = function (messages) {
  3292. var self = this;
  3293. return messages.map(function (message) {
  3294. return self.toPayload(message.method, message.params);
  3295. });
  3296. };
  3297. module.exports = Jsonrpc;
  3298. },{}],24:[function(require,module,exports){
  3299. /*
  3300. This file is part of ethereum.js.
  3301. ethereum.js is free software: you can redistribute it and/or modify
  3302. it under the terms of the GNU Lesser General Public License as published by
  3303. the Free Software Foundation, either version 3 of the License, or
  3304. (at your option) any later version.
  3305. ethereum.js is distributed in the hope that it will be useful,
  3306. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3307. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3308. GNU Lesser General Public License for more details.
  3309. You should have received a copy of the GNU Lesser General Public License
  3310. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  3311. */
  3312. /**
  3313. * @file method.js
  3314. * @author Marek Kotewicz <marek@ethdev.com>
  3315. * @date 2015
  3316. */
  3317. var RequestManager = require('./requestmanager');
  3318. var utils = require('../utils/utils');
  3319. var errors = require('./errors');
  3320. var Method = function (options) {
  3321. this.name = options.name;
  3322. this.call = options.call;
  3323. this.params = options.params || 0;
  3324. this.inputFormatter = options.inputFormatter;
  3325. this.outputFormatter = options.outputFormatter;
  3326. };
  3327. /**
  3328. * Should be used to determine name of the jsonrpc method based on arguments
  3329. *
  3330. * @method getCall
  3331. * @param {Array} arguments
  3332. * @return {String} name of jsonrpc method
  3333. */
  3334. Method.prototype.getCall = function (args) {
  3335. return utils.isFunction(this.call) ? this.call(args) : this.call;
  3336. };
  3337. /**
  3338. * Should be used to extract callback from array of arguments. Modifies input param
  3339. *
  3340. * @method extractCallback
  3341. * @param {Array} arguments
  3342. * @return {Function|Null} callback, if exists
  3343. */
  3344. Method.prototype.extractCallback = function (args) {
  3345. if (utils.isFunction(args[args.length - 1])) {
  3346. return args.pop(); // modify the args array!
  3347. }
  3348. };
  3349. /**
  3350. * Should be called to check if the number of arguments is correct
  3351. *
  3352. * @method validateArgs
  3353. * @param {Array} arguments
  3354. * @throws {Error} if it is not
  3355. */
  3356. Method.prototype.validateArgs = function (args) {
  3357. if (args.length !== this.params) {
  3358. throw errors.InvalidNumberOfParams();
  3359. }
  3360. };
  3361. /**
  3362. * Should be called to format input args of method
  3363. *
  3364. * @method formatInput
  3365. * @param {Array}
  3366. * @return {Array}
  3367. */
  3368. Method.prototype.formatInput = function (args) {
  3369. if (!this.inputFormatter) {
  3370. return args;
  3371. }
  3372. return this.inputFormatter.map(function (formatter, index) {
  3373. return formatter ? formatter(args[index]) : args[index];
  3374. });
  3375. };
  3376. /**
  3377. * Should be called to format output(result) of method
  3378. *
  3379. * @method formatOutput
  3380. * @param {Object}
  3381. * @return {Object}
  3382. */
  3383. Method.prototype.formatOutput = function (result) {
  3384. return this.outputFormatter && result ? this.outputFormatter(result) : result;
  3385. };
  3386. /**
  3387. * Should attach function to method
  3388. *
  3389. * @method attachToObject
  3390. * @param {Object}
  3391. * @param {Function}
  3392. */
  3393. Method.prototype.attachToObject = function (obj) {
  3394. var func = this.send.bind(this);
  3395. func.request = this.request.bind(this);
  3396. func.call = this.call; // that's ugly. filter.js uses it
  3397. var name = this.name.split('.');
  3398. if (name.length > 1) {
  3399. obj[name[0]] = obj[name[0]] || {};
  3400. obj[name[0]][name[1]] = func;
  3401. } else {
  3402. obj[name[0]] = func;
  3403. }
  3404. };
  3405. /**
  3406. * Should create payload from given input args
  3407. *
  3408. * @method toPayload
  3409. * @param {Array} args
  3410. * @return {Object}
  3411. */
  3412. Method.prototype.toPayload = function (args) {
  3413. var call = this.getCall(args);
  3414. var callback = this.extractCallback(args);
  3415. var params = this.formatInput(args);
  3416. this.validateArgs(params);
  3417. return {
  3418. method: call,
  3419. params: params,
  3420. callback: callback
  3421. };
  3422. };
  3423. /**
  3424. * Should be called to create pure JSONRPC request which can be used in batch request
  3425. *
  3426. * @method request
  3427. * @param {...} params
  3428. * @return {Object} jsonrpc request
  3429. */
  3430. Method.prototype.request = function () {
  3431. var payload = this.toPayload(Array.prototype.slice.call(arguments));
  3432. payload.format = this.formatOutput.bind(this);
  3433. return payload;
  3434. };
  3435. /**
  3436. * Should send request to the API
  3437. *
  3438. * @method send
  3439. * @param list of params
  3440. * @return result
  3441. */
  3442. Method.prototype.send = function () {
  3443. var payload = this.toPayload(Array.prototype.slice.call(arguments));
  3444. if (payload.callback) {
  3445. var self = this;
  3446. return RequestManager.getInstance().sendAsync(payload, function (err, result) {
  3447. payload.callback(err, self.formatOutput(result));
  3448. });
  3449. }
  3450. return this.formatOutput(RequestManager.getInstance().send(payload));
  3451. };
  3452. module.exports = Method;
  3453. },{"../utils/utils":7,"./errors":14,"./requestmanager":28}],25:[function(require,module,exports){
  3454. /*
  3455. This file is part of ethereum.js.
  3456. ethereum.js is free software: you can redistribute it and/or modify
  3457. it under the terms of the GNU Lesser General Public License as published by
  3458. the Free Software Foundation, either version 3 of the License, or
  3459. (at your option) any later version.
  3460. ethereum.js is distributed in the hope that it will be useful,
  3461. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3462. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3463. GNU Lesser General Public License for more details.
  3464. You should have received a copy of the GNU Lesser General Public License
  3465. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  3466. */
  3467. /**
  3468. * @file namereg.js
  3469. * @author Marek Kotewicz <marek@ethdev.com>
  3470. * @date 2015
  3471. */
  3472. var contract = require('./contract');
  3473. var address = '0xc6d9d2cd449a754c494264e1809c50e34d64562b';
  3474. var abi = [
  3475. {"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"name","outputs":[{"name":"o_name","type":"bytes32"}],"type":"function"},
  3476. {"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"owner","outputs":[{"name":"","type":"address"}],"type":"function"},
  3477. {"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"content","outputs":[{"name":"","type":"bytes32"}],"type":"function"},
  3478. {"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"addr","outputs":[{"name":"","type":"address"}],"type":"function"},
  3479. {"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"reserve","outputs":[],"type":"function"},
  3480. {"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"subRegistrar","outputs":[{"name":"o_subRegistrar","type":"address"}],"type":"function"},
  3481. {"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_newOwner","type":"address"}],"name":"transfer","outputs":[],"type":"function"},
  3482. {"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_registrar","type":"address"}],"name":"setSubRegistrar","outputs":[],"type":"function"},
  3483. {"constant":false,"inputs":[],"name":"Registrar","outputs":[],"type":"function"},
  3484. {"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_a","type":"address"},{"name":"_primary","type":"bool"}],"name":"setAddress","outputs":[],"type":"function"},
  3485. {"constant":false,"inputs":[{"name":"_name","type":"bytes32"},{"name":"_content","type":"bytes32"}],"name":"setContent","outputs":[],"type":"function"},
  3486. {"constant":false,"inputs":[{"name":"_name","type":"bytes32"}],"name":"disown","outputs":[],"type":"function"},
  3487. {"constant":true,"inputs":[{"name":"_name","type":"bytes32"}],"name":"register","outputs":[{"name":"","type":"address"}],"type":"function"},
  3488. {"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"}],"name":"Changed","type":"event"},
  3489. {"anonymous":false,"inputs":[{"indexed":true,"name":"name","type":"bytes32"},{"indexed":true,"name":"addr","type":"address"}],"name":"PrimaryChanged","type":"event"}
  3490. ];
  3491. module.exports = contract(abi).at(address);
  3492. },{"./contract":12}],26:[function(require,module,exports){
  3493. /*
  3494. This file is part of ethereum.js.
  3495. ethereum.js is free software: you can redistribute it and/or modify
  3496. it under the terms of the GNU Lesser General Public License as published by
  3497. the Free Software Foundation, either version 3 of the License, or
  3498. (at your option) any later version.
  3499. ethereum.js is distributed in the hope that it will be useful,
  3500. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3501. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3502. GNU Lesser General Public License for more details.
  3503. You should have received a copy of the GNU Lesser General Public License
  3504. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  3505. */
  3506. /** @file eth.js
  3507. * @authors:
  3508. * Marek Kotewicz <marek@ethdev.com>
  3509. * @date 2015
  3510. */
  3511. var utils = require('../utils/utils');
  3512. var Property = require('./property');
  3513. /// @returns an array of objects describing web3.eth api methods
  3514. var methods = [
  3515. ];
  3516. /// @returns an array of objects describing web3.eth api properties
  3517. var properties = [
  3518. new Property({
  3519. name: 'listening',
  3520. getter: 'net_listening'
  3521. }),
  3522. new Property({
  3523. name: 'peerCount',
  3524. getter: 'net_peerCount',
  3525. outputFormatter: utils.toDecimal
  3526. })
  3527. ];
  3528. module.exports = {
  3529. methods: methods,
  3530. properties: properties
  3531. };
  3532. },{"../utils/utils":7,"./property":27}],27:[function(require,module,exports){
  3533. /*
  3534. This file is part of ethereum.js.
  3535. ethereum.js is free software: you can redistribute it and/or modify
  3536. it under the terms of the GNU Lesser General Public License as published by
  3537. the Free Software Foundation, either version 3 of the License, or
  3538. (at your option) any later version.
  3539. ethereum.js is distributed in the hope that it will be useful,
  3540. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3541. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3542. GNU Lesser General Public License for more details.
  3543. You should have received a copy of the GNU Lesser General Public License
  3544. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  3545. */
  3546. /**
  3547. * @file property.js
  3548. * @author Fabian Vogelsteller <fabian@frozeman.de>
  3549. * @author Marek Kotewicz <marek@ethdev.com>
  3550. * @date 2015
  3551. */
  3552. var RequestManager = require('./requestmanager');
  3553. var utils = require('../utils/utils');
  3554. var Property = function (options) {
  3555. this.name = options.name;
  3556. this.getter = options.getter;
  3557. this.setter = options.setter;
  3558. this.outputFormatter = options.outputFormatter;
  3559. this.inputFormatter = options.inputFormatter;
  3560. };
  3561. /**
  3562. * Should be called to format input args of method
  3563. *
  3564. * @method formatInput
  3565. * @param {Array}
  3566. * @return {Array}
  3567. */
  3568. Property.prototype.formatInput = function (arg) {
  3569. return this.inputFormatter ? this.inputFormatter(arg) : arg;
  3570. };
  3571. /**
  3572. * Should be called to format output(result) of method
  3573. *
  3574. * @method formatOutput
  3575. * @param {Object}
  3576. * @return {Object}
  3577. */
  3578. Property.prototype.formatOutput = function (result) {
  3579. return this.outputFormatter && result !== null ? this.outputFormatter(result) : result;
  3580. };
  3581. /**
  3582. * Should be used to extract callback from array of arguments. Modifies input param
  3583. *
  3584. * @method extractCallback
  3585. * @param {Array} arguments
  3586. * @return {Function|Null} callback, if exists
  3587. */
  3588. Property.prototype.extractCallback = function (args) {
  3589. if (utils.isFunction(args[args.length - 1])) {
  3590. return args.pop(); // modify the args array!
  3591. }
  3592. };
  3593. /**
  3594. * Should attach function to method
  3595. *
  3596. * @method attachToObject
  3597. * @param {Object}
  3598. * @param {Function}
  3599. */
  3600. Property.prototype.attachToObject = function (obj) {
  3601. var proto = {
  3602. get: this.get.bind(this),
  3603. };
  3604. var names = this.name.split('.');
  3605. var name = names[0];
  3606. if (names.length > 1) {
  3607. obj[names[0]] = obj[names[0]] || {};
  3608. obj = obj[names[0]];
  3609. name = names[1];
  3610. }
  3611. Object.defineProperty(obj, name, proto);
  3612. var toAsyncName = function (prefix, name) {
  3613. return prefix + name.charAt(0).toUpperCase() + name.slice(1);
  3614. };
  3615. var func = this.getAsync.bind(this);
  3616. func.request = this.request.bind(this);
  3617. obj[toAsyncName('get', name)] = func;
  3618. };
  3619. /**
  3620. * Should be used to get value of the property
  3621. *
  3622. * @method get
  3623. * @return {Object} value of the property
  3624. */
  3625. Property.prototype.get = function () {
  3626. return this.formatOutput(RequestManager.getInstance().send({
  3627. method: this.getter
  3628. }));
  3629. };
  3630. /**
  3631. * Should be used to asynchrounously get value of property
  3632. *
  3633. * @method getAsync
  3634. * @param {Function}
  3635. */
  3636. Property.prototype.getAsync = function (callback) {
  3637. var self = this;
  3638. RequestManager.getInstance().sendAsync({
  3639. method: this.getter
  3640. }, function (err, result) {
  3641. if (err) {
  3642. return callback(err);
  3643. }
  3644. callback(err, self.formatOutput(result));
  3645. });
  3646. };
  3647. /**
  3648. * Should be called to create pure JSONRPC request which can be used in batch request
  3649. *
  3650. * @method request
  3651. * @param {...} params
  3652. * @return {Object} jsonrpc request
  3653. */
  3654. Property.prototype.request = function () {
  3655. var payload = {
  3656. method: this.getter,
  3657. params: [],
  3658. callback: this.extractCallback(Array.prototype.slice.call(arguments))
  3659. };
  3660. payload.format = this.formatOutput.bind(this);
  3661. return payload;
  3662. };
  3663. module.exports = Property;
  3664. },{"../utils/utils":7,"./requestmanager":28}],28:[function(require,module,exports){
  3665. /*
  3666. This file is part of ethereum.js.
  3667. ethereum.js is free software: you can redistribute it and/or modify
  3668. it under the terms of the GNU Lesser General Public License as published by
  3669. the Free Software Foundation, either version 3 of the License, or
  3670. (at your option) any later version.
  3671. ethereum.js is distributed in the hope that it will be useful,
  3672. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3673. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3674. GNU Lesser General Public License for more details.
  3675. You should have received a copy of the GNU Lesser General Public License
  3676. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  3677. */
  3678. /**
  3679. * @file requestmanager.js
  3680. * @author Jeffrey Wilcke <jeff@ethdev.com>
  3681. * @author Marek Kotewicz <marek@ethdev.com>
  3682. * @author Marian Oancea <marian@ethdev.com>
  3683. * @author Fabian Vogelsteller <fabian@ethdev.com>
  3684. * @author Gav Wood <g@ethdev.com>
  3685. * @date 2014
  3686. */
  3687. var Jsonrpc = require('./jsonrpc');
  3688. var utils = require('../utils/utils');
  3689. var c = require('../utils/config');
  3690. var errors = require('./errors');
  3691. /**
  3692. * It's responsible for passing messages to providers
  3693. * It's also responsible for polling the ethereum node for incoming messages
  3694. * Default poll timeout is 1 second
  3695. * Singleton
  3696. */
  3697. var RequestManager = function (provider) {
  3698. // singleton pattern
  3699. if (arguments.callee._singletonInstance) {
  3700. return arguments.callee._singletonInstance;
  3701. }
  3702. arguments.callee._singletonInstance = this;
  3703. this.provider = provider;
  3704. this.polls = {};
  3705. this.timeout = null;
  3706. this.isPolling = false;
  3707. };
  3708. /**
  3709. * @return {RequestManager} singleton
  3710. */
  3711. RequestManager.getInstance = function () {
  3712. var instance = new RequestManager();
  3713. return instance;
  3714. };
  3715. /**
  3716. * Should be used to synchronously send request
  3717. *
  3718. * @method send
  3719. * @param {Object} data
  3720. * @return {Object}
  3721. */
  3722. RequestManager.prototype.send = function (data) {
  3723. if (!this.provider) {
  3724. console.error(errors.InvalidProvider());
  3725. return null;
  3726. }
  3727. var payload = Jsonrpc.getInstance().toPayload(data.method, data.params);
  3728. var result = this.provider.send(payload);
  3729. if (!Jsonrpc.getInstance().isValidResponse(result)) {
  3730. throw errors.InvalidResponse(result);
  3731. }
  3732. return result.result;
  3733. };
  3734. /**
  3735. * Should be used to asynchronously send request
  3736. *
  3737. * @method sendAsync
  3738. * @param {Object} data
  3739. * @param {Function} callback
  3740. */
  3741. RequestManager.prototype.sendAsync = function (data, callback) {
  3742. if (!this.provider) {
  3743. return callback(errors.InvalidProvider());
  3744. }
  3745. var payload = Jsonrpc.getInstance().toPayload(data.method, data.params);
  3746. this.provider.sendAsync(payload, function (err, result) {
  3747. if (err) {
  3748. return callback(err);
  3749. }
  3750. if (!Jsonrpc.getInstance().isValidResponse(result)) {
  3751. return callback(errors.InvalidResponse(result));
  3752. }
  3753. callback(null, result.result);
  3754. });
  3755. };
  3756. /**
  3757. * Should be called to asynchronously send batch request
  3758. *
  3759. * @method sendBatch
  3760. * @param {Array} batch data
  3761. * @param {Function} callback
  3762. */
  3763. RequestManager.prototype.sendBatch = function (data, callback) {
  3764. if (!this.provider) {
  3765. return callback(errors.InvalidProvider());
  3766. }
  3767. var payload = Jsonrpc.getInstance().toBatchPayload(data);
  3768. this.provider.sendAsync(payload, function (err, results) {
  3769. if (err) {
  3770. return callback(err);
  3771. }
  3772. if (!utils.isArray(results)) {
  3773. return callback(errors.InvalidResponse(results));
  3774. }
  3775. callback(err, results);
  3776. });
  3777. };
  3778. /**
  3779. * Should be used to set provider of request manager
  3780. *
  3781. * @method setProvider
  3782. * @param {Object}
  3783. */
  3784. RequestManager.prototype.setProvider = function (p) {
  3785. this.provider = p;
  3786. if (this.provider && !this.isPolling) {
  3787. this.poll();
  3788. this.isPolling = true;
  3789. }
  3790. };
  3791. /*jshint maxparams:4 */
  3792. /**
  3793. * Should be used to start polling
  3794. *
  3795. * @method startPolling
  3796. * @param {Object} data
  3797. * @param {Number} pollId
  3798. * @param {Function} callback
  3799. * @param {Function} uninstall
  3800. *
  3801. * @todo cleanup number of params
  3802. */
  3803. RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) {
  3804. this.polls['poll_'+ pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall};
  3805. };
  3806. /*jshint maxparams:3 */
  3807. /**
  3808. * Should be used to stop polling for filter with given id
  3809. *
  3810. * @method stopPolling
  3811. * @param {Number} pollId
  3812. */
  3813. RequestManager.prototype.stopPolling = function (pollId) {
  3814. delete this.polls['poll_'+ pollId];
  3815. };
  3816. /**
  3817. * Should be called to reset the polling mechanism of the request manager
  3818. *
  3819. * @method reset
  3820. */
  3821. RequestManager.prototype.reset = function () {
  3822. for (var key in this.polls) {
  3823. this.polls[key].uninstall();
  3824. }
  3825. this.polls = {};
  3826. if (this.timeout) {
  3827. clearTimeout(this.timeout);
  3828. this.timeout = null;
  3829. }
  3830. this.poll();
  3831. };
  3832. /**
  3833. * Should be called to poll for changes on filter with given id
  3834. *
  3835. * @method poll
  3836. */
  3837. RequestManager.prototype.poll = function () {
  3838. /*jshint maxcomplexity: 6 */
  3839. this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT);
  3840. if (Object.keys(this.polls).length === 0) {
  3841. return;
  3842. }
  3843. if (!this.provider) {
  3844. console.error(errors.InvalidProvider());
  3845. return;
  3846. }
  3847. var pollsData = [];
  3848. var pollsKeys = [];
  3849. for (var key in this.polls) {
  3850. pollsData.push(this.polls[key].data);
  3851. pollsKeys.push(key);
  3852. }
  3853. if (pollsData.length === 0) {
  3854. return;
  3855. }
  3856. var payload = Jsonrpc.getInstance().toBatchPayload(pollsData);
  3857. var self = this;
  3858. this.provider.sendAsync(payload, function (error, results) {
  3859. // TODO: console log?
  3860. if (error) {
  3861. return;
  3862. }
  3863. if (!utils.isArray(results)) {
  3864. throw errors.InvalidResponse(results);
  3865. }
  3866. results.map(function (result, index) {
  3867. var key = pollsKeys[index];
  3868. // make sure the filter is still installed after arrival of the request
  3869. if (self.polls[key]) {
  3870. result.callback = self.polls[key].callback;
  3871. return result;
  3872. } else
  3873. return false;
  3874. }).filter(function (result) {
  3875. return !!result;
  3876. }).filter(function (result) {
  3877. var valid = Jsonrpc.getInstance().isValidResponse(result);
  3878. if (!valid) {
  3879. result.callback(errors.InvalidResponse(result));
  3880. }
  3881. return valid;
  3882. }).filter(function (result) {
  3883. return utils.isArray(result.result) && result.result.length > 0;
  3884. }).forEach(function (result) {
  3885. result.callback(null, result.result);
  3886. });
  3887. });
  3888. };
  3889. module.exports = RequestManager;
  3890. },{"../utils/config":5,"../utils/utils":7,"./errors":14,"./jsonrpc":23}],29:[function(require,module,exports){
  3891. /*
  3892. This file is part of ethereum.js.
  3893. ethereum.js is free software: you can redistribute it and/or modify
  3894. it under the terms of the GNU Lesser General Public License as published by
  3895. the Free Software Foundation, either version 3 of the License, or
  3896. (at your option) any later version.
  3897. ethereum.js is distributed in the hope that it will be useful,
  3898. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3899. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3900. GNU Lesser General Public License for more details.
  3901. You should have received a copy of the GNU Lesser General Public License
  3902. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  3903. */
  3904. /** @file shh.js
  3905. * @authors:
  3906. * Marek Kotewicz <marek@ethdev.com>
  3907. * @date 2015
  3908. */
  3909. var Method = require('./method');
  3910. var formatters = require('./formatters');
  3911. var post = new Method({
  3912. name: 'post',
  3913. call: 'shh_post',
  3914. params: 1,
  3915. inputFormatter: [formatters.inputPostFormatter]
  3916. });
  3917. var newIdentity = new Method({
  3918. name: 'newIdentity',
  3919. call: 'shh_newIdentity',
  3920. params: 0
  3921. });
  3922. var hasIdentity = new Method({
  3923. name: 'hasIdentity',
  3924. call: 'shh_hasIdentity',
  3925. params: 1
  3926. });
  3927. var newGroup = new Method({
  3928. name: 'newGroup',
  3929. call: 'shh_newGroup',
  3930. params: 0
  3931. });
  3932. var addToGroup = new Method({
  3933. name: 'addToGroup',
  3934. call: 'shh_addToGroup',
  3935. params: 0
  3936. });
  3937. var methods = [
  3938. post,
  3939. newIdentity,
  3940. hasIdentity,
  3941. newGroup,
  3942. addToGroup
  3943. ];
  3944. module.exports = {
  3945. methods: methods
  3946. };
  3947. },{"./formatters":18,"./method":24}],30:[function(require,module,exports){
  3948. /*
  3949. This file is part of ethereum.js.
  3950. ethereum.js is free software: you can redistribute it and/or modify
  3951. it under the terms of the GNU Lesser General Public License as published by
  3952. the Free Software Foundation, either version 3 of the License, or
  3953. (at your option) any later version.
  3954. ethereum.js is distributed in the hope that it will be useful,
  3955. but WITHOUT ANY WARRANTY; without even the implied warranty of
  3956. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3957. GNU Lesser General Public License for more details.
  3958. You should have received a copy of the GNU Lesser General Public License
  3959. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  3960. */
  3961. /**
  3962. * @file transfer.js
  3963. * @author Marek Kotewicz <marek@ethdev.com>
  3964. * @date 2015
  3965. */
  3966. var web3 = require('../web3');
  3967. var ICAP = require('./icap');
  3968. var namereg = require('./namereg');
  3969. var contract = require('./contract');
  3970. /**
  3971. * Should be used to make ICAP transfer
  3972. *
  3973. * @method transfer
  3974. * @param {String} iban number
  3975. * @param {String} from (address)
  3976. * @param {Value} value to be tranfered
  3977. * @param {Function} callback, callback
  3978. */
  3979. var transfer = function (from, iban, value, callback) {
  3980. var icap = new ICAP(iban);
  3981. if (!icap.isValid()) {
  3982. throw new Error('invalid iban address');
  3983. }
  3984. if (icap.isDirect()) {
  3985. return transferToAddress(from, icap.address(), value, callback);
  3986. }
  3987. if (!callback) {
  3988. var address = namereg.addr(icap.institution());
  3989. return deposit(from, address, value, icap.client());
  3990. }
  3991. namereg.addr(icap.insitution(), function (err, address) {
  3992. return deposit(from, address, value, icap.client(), callback);
  3993. });
  3994. };
  3995. /**
  3996. * Should be used to transfer funds to certain address
  3997. *
  3998. * @method transferToAddress
  3999. * @param {String} address
  4000. * @param {String} from (address)
  4001. * @param {Value} value to be tranfered
  4002. * @param {Function} callback, callback
  4003. */
  4004. var transferToAddress = function (from, address, value, callback) {
  4005. return web3.eth.sendTransaction({
  4006. address: address,
  4007. from: from,
  4008. value: value
  4009. }, callback);
  4010. };
  4011. /**
  4012. * Should be used to deposit funds to generic Exchange contract (must implement deposit(bytes32) method!)
  4013. *
  4014. * @method deposit
  4015. * @param {String} address
  4016. * @param {String} from (address)
  4017. * @param {Value} value to be tranfered
  4018. * @param {String} client unique identifier
  4019. * @param {Function} callback, callback
  4020. */
  4021. var deposit = function (from, address, value, client, callback) {
  4022. var abi = [{"constant":false,"inputs":[{"name":"name","type":"bytes32"}],"name":"deposit","outputs":[],"type":"function"}];
  4023. return contract(abi).at(address).deposit(client, {
  4024. from: from,
  4025. value: value
  4026. }, callback);
  4027. };
  4028. module.exports = transfer;
  4029. },{"../web3":9,"./contract":12,"./icap":21,"./namereg":25}],31:[function(require,module,exports){
  4030. /*
  4031. This file is part of ethereum.js.
  4032. ethereum.js is free software: you can redistribute it and/or modify
  4033. it under the terms of the GNU Lesser General Public License as published by
  4034. the Free Software Foundation, either version 3 of the License, or
  4035. (at your option) any later version.
  4036. ethereum.js is distributed in the hope that it will be useful,
  4037. but WITHOUT ANY WARRANTY; without even the implied warranty of
  4038. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4039. GNU Lesser General Public License for more details.
  4040. You should have received a copy of the GNU Lesser General Public License
  4041. along with ethereum.js. If not, see <http://www.gnu.org/licenses/>.
  4042. */
  4043. /** @file watches.js
  4044. * @authors:
  4045. * Marek Kotewicz <marek@ethdev.com>
  4046. * @date 2015
  4047. */
  4048. var Method = require('./method');
  4049. /// @returns an array of objects describing web3.eth.filter api methods
  4050. var eth = function () {
  4051. var newFilterCall = function (args) {
  4052. var type = args[0];
  4053. switch(type) {
  4054. case 'latest':
  4055. args.shift();
  4056. this.params = 0;
  4057. return 'eth_newBlockFilter';
  4058. case 'pending':
  4059. args.shift();
  4060. this.params = 0;
  4061. return 'eth_newPendingTransactionFilter';
  4062. default:
  4063. return 'eth_newFilter';
  4064. }
  4065. };
  4066. var newFilter = new Method({
  4067. name: 'newFilter',
  4068. call: newFilterCall,
  4069. params: 1
  4070. });
  4071. var uninstallFilter = new Method({
  4072. name: 'uninstallFilter',
  4073. call: 'eth_uninstallFilter',
  4074. params: 1
  4075. });
  4076. var getLogs = new Method({
  4077. name: 'getLogs',
  4078. call: 'eth_getFilterLogs',
  4079. params: 1
  4080. });
  4081. var poll = new Method({
  4082. name: 'poll',
  4083. call: 'eth_getFilterChanges',
  4084. params: 1
  4085. });
  4086. return [
  4087. newFilter,
  4088. uninstallFilter,
  4089. getLogs,
  4090. poll
  4091. ];
  4092. };
  4093. /// @returns an array of objects describing web3.shh.watch api methods
  4094. var shh = function () {
  4095. var newFilter = new Method({
  4096. name: 'newFilter',
  4097. call: 'shh_newFilter',
  4098. params: 1
  4099. });
  4100. var uninstallFilter = new Method({
  4101. name: 'uninstallFilter',
  4102. call: 'shh_uninstallFilter',
  4103. params: 1
  4104. });
  4105. var getLogs = new Method({
  4106. name: 'getLogs',
  4107. call: 'shh_getMessages',
  4108. params: 1
  4109. });
  4110. var poll = new Method({
  4111. name: 'poll',
  4112. call: 'shh_getFilterChanges',
  4113. params: 1
  4114. });
  4115. return [
  4116. newFilter,
  4117. uninstallFilter,
  4118. getLogs,
  4119. poll
  4120. ];
  4121. };
  4122. module.exports = {
  4123. eth: eth,
  4124. shh: shh
  4125. };
  4126. },{"./method":24}],32:[function(require,module,exports){
  4127. },{}],33:[function(require,module,exports){
  4128. ;(function (root, factory) {
  4129. if (typeof exports === "object") {
  4130. // CommonJS
  4131. module.exports = exports = factory();
  4132. }
  4133. else if (typeof define === "function" && define.amd) {
  4134. // AMD
  4135. define([], factory);
  4136. }
  4137. else {
  4138. // Global (browser)
  4139. root.CryptoJS = factory();
  4140. }
  4141. }(this, function () {
  4142. /**
  4143. * CryptoJS core components.
  4144. */
  4145. var CryptoJS = CryptoJS || (function (Math, undefined) {
  4146. /**
  4147. * CryptoJS namespace.
  4148. */
  4149. var C = {};
  4150. /**
  4151. * Library namespace.
  4152. */
  4153. var C_lib = C.lib = {};
  4154. /**
  4155. * Base object for prototypal inheritance.
  4156. */
  4157. var Base = C_lib.Base = (function () {
  4158. function F() {}
  4159. return {
  4160. /**
  4161. * Creates a new object that inherits from this object.
  4162. *
  4163. * @param {Object} overrides Properties to copy into the new object.
  4164. *
  4165. * @return {Object} The new object.
  4166. *
  4167. * @static
  4168. *
  4169. * @example
  4170. *
  4171. * var MyType = CryptoJS.lib.Base.extend({
  4172. * field: 'value',
  4173. *
  4174. * method: function () {
  4175. * }
  4176. * });
  4177. */
  4178. extend: function (overrides) {
  4179. // Spawn
  4180. F.prototype = this;
  4181. var subtype = new F();
  4182. // Augment
  4183. if (overrides) {
  4184. subtype.mixIn(overrides);
  4185. }
  4186. // Create default initializer
  4187. if (!subtype.hasOwnProperty('init')) {
  4188. subtype.init = function () {
  4189. subtype.$super.init.apply(this, arguments);
  4190. };
  4191. }
  4192. // Initializer's prototype is the subtype object
  4193. subtype.init.prototype = subtype;
  4194. // Reference supertype
  4195. subtype.$super = this;
  4196. return subtype;
  4197. },
  4198. /**
  4199. * Extends this object and runs the init method.
  4200. * Arguments to create() will be passed to init().
  4201. *
  4202. * @return {Object} The new object.
  4203. *
  4204. * @static
  4205. *
  4206. * @example
  4207. *
  4208. * var instance = MyType.create();
  4209. */
  4210. create: function () {
  4211. var instance = this.extend();
  4212. instance.init.apply(instance, arguments);
  4213. return instance;
  4214. },
  4215. /**
  4216. * Initializes a newly created object.
  4217. * Override this method to add some logic when your objects are created.
  4218. *
  4219. * @example
  4220. *
  4221. * var MyType = CryptoJS.lib.Base.extend({
  4222. * init: function () {
  4223. * // ...
  4224. * }
  4225. * });
  4226. */
  4227. init: function () {
  4228. },
  4229. /**
  4230. * Copies properties into this object.
  4231. *
  4232. * @param {Object} properties The properties to mix in.
  4233. *
  4234. * @example
  4235. *
  4236. * MyType.mixIn({
  4237. * field: 'value'
  4238. * });
  4239. */
  4240. mixIn: function (properties) {
  4241. for (var propertyName in properties) {
  4242. if (properties.hasOwnProperty(propertyName)) {
  4243. this[propertyName] = properties[propertyName];
  4244. }
  4245. }
  4246. // IE won't copy toString using the loop above
  4247. if (properties.hasOwnProperty('toString')) {
  4248. this.toString = properties.toString;
  4249. }
  4250. },
  4251. /**
  4252. * Creates a copy of this object.
  4253. *
  4254. * @return {Object} The clone.
  4255. *
  4256. * @example
  4257. *
  4258. * var clone = instance.clone();
  4259. */
  4260. clone: function () {
  4261. return this.init.prototype.extend(this);
  4262. }
  4263. };
  4264. }());
  4265. /**
  4266. * An array of 32-bit words.
  4267. *
  4268. * @property {Array} words The array of 32-bit words.
  4269. * @property {number} sigBytes The number of significant bytes in this word array.
  4270. */
  4271. var WordArray = C_lib.WordArray = Base.extend({
  4272. /**
  4273. * Initializes a newly created word array.
  4274. *
  4275. * @param {Array} words (Optional) An array of 32-bit words.
  4276. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  4277. *
  4278. * @example
  4279. *
  4280. * var wordArray = CryptoJS.lib.WordArray.create();
  4281. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
  4282. * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
  4283. */
  4284. init: function (words, sigBytes) {
  4285. words = this.words = words || [];
  4286. if (sigBytes != undefined) {
  4287. this.sigBytes = sigBytes;
  4288. } else {
  4289. this.sigBytes = words.length * 4;
  4290. }
  4291. },
  4292. /**
  4293. * Converts this word array to a string.
  4294. *
  4295. * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
  4296. *
  4297. * @return {string} The stringified word array.
  4298. *
  4299. * @example
  4300. *
  4301. * var string = wordArray + '';
  4302. * var string = wordArray.toString();
  4303. * var string = wordArray.toString(CryptoJS.enc.Utf8);
  4304. */
  4305. toString: function (encoder) {
  4306. return (encoder || Hex).stringify(this);
  4307. },
  4308. /**
  4309. * Concatenates a word array to this word array.
  4310. *
  4311. * @param {WordArray} wordArray The word array to append.
  4312. *
  4313. * @return {WordArray} This word array.
  4314. *
  4315. * @example
  4316. *
  4317. * wordArray1.concat(wordArray2);
  4318. */
  4319. concat: function (wordArray) {
  4320. // Shortcuts
  4321. var thisWords = this.words;
  4322. var thatWords = wordArray.words;
  4323. var thisSigBytes = this.sigBytes;
  4324. var thatSigBytes = wordArray.sigBytes;
  4325. // Clamp excess bits
  4326. this.clamp();
  4327. // Concat
  4328. if (thisSigBytes % 4) {
  4329. // Copy one byte at a time
  4330. for (var i = 0; i < thatSigBytes; i++) {
  4331. var thatByte = (thatWords[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  4332. thisWords[(thisSigBytes + i) >>> 2] |= thatByte << (24 - ((thisSigBytes + i) % 4) * 8);
  4333. }
  4334. } else {
  4335. // Copy one word at a time
  4336. for (var i = 0; i < thatSigBytes; i += 4) {
  4337. thisWords[(thisSigBytes + i) >>> 2] = thatWords[i >>> 2];
  4338. }
  4339. }
  4340. this.sigBytes += thatSigBytes;
  4341. // Chainable
  4342. return this;
  4343. },
  4344. /**
  4345. * Removes insignificant bits.
  4346. *
  4347. * @example
  4348. *
  4349. * wordArray.clamp();
  4350. */
  4351. clamp: function () {
  4352. // Shortcuts
  4353. var words = this.words;
  4354. var sigBytes = this.sigBytes;
  4355. // Clamp
  4356. words[sigBytes >>> 2] &= 0xffffffff << (32 - (sigBytes % 4) * 8);
  4357. words.length = Math.ceil(sigBytes / 4);
  4358. },
  4359. /**
  4360. * Creates a copy of this word array.
  4361. *
  4362. * @return {WordArray} The clone.
  4363. *
  4364. * @example
  4365. *
  4366. * var clone = wordArray.clone();
  4367. */
  4368. clone: function () {
  4369. var clone = Base.clone.call(this);
  4370. clone.words = this.words.slice(0);
  4371. return clone;
  4372. },
  4373. /**
  4374. * Creates a word array filled with random bytes.
  4375. *
  4376. * @param {number} nBytes The number of random bytes to generate.
  4377. *
  4378. * @return {WordArray} The random word array.
  4379. *
  4380. * @static
  4381. *
  4382. * @example
  4383. *
  4384. * var wordArray = CryptoJS.lib.WordArray.random(16);
  4385. */
  4386. random: function (nBytes) {
  4387. var words = [];
  4388. var r = (function (m_w) {
  4389. var m_w = m_w;
  4390. var m_z = 0x3ade68b1;
  4391. var mask = 0xffffffff;
  4392. return function () {
  4393. m_z = (0x9069 * (m_z & 0xFFFF) + (m_z >> 0x10)) & mask;
  4394. m_w = (0x4650 * (m_w & 0xFFFF) + (m_w >> 0x10)) & mask;
  4395. var result = ((m_z << 0x10) + m_w) & mask;
  4396. result /= 0x100000000;
  4397. result += 0.5;
  4398. return result * (Math.random() > .5 ? 1 : -1);
  4399. }
  4400. });
  4401. for (var i = 0, rcache; i < nBytes; i += 4) {
  4402. var _r = r((rcache || Math.random()) * 0x100000000);
  4403. rcache = _r() * 0x3ade67b7;
  4404. words.push((_r() * 0x100000000) | 0);
  4405. }
  4406. return new WordArray.init(words, nBytes);
  4407. }
  4408. });
  4409. /**
  4410. * Encoder namespace.
  4411. */
  4412. var C_enc = C.enc = {};
  4413. /**
  4414. * Hex encoding strategy.
  4415. */
  4416. var Hex = C_enc.Hex = {
  4417. /**
  4418. * Converts a word array to a hex string.
  4419. *
  4420. * @param {WordArray} wordArray The word array.
  4421. *
  4422. * @return {string} The hex string.
  4423. *
  4424. * @static
  4425. *
  4426. * @example
  4427. *
  4428. * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
  4429. */
  4430. stringify: function (wordArray) {
  4431. // Shortcuts
  4432. var words = wordArray.words;
  4433. var sigBytes = wordArray.sigBytes;
  4434. // Convert
  4435. var hexChars = [];
  4436. for (var i = 0; i < sigBytes; i++) {
  4437. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  4438. hexChars.push((bite >>> 4).toString(16));
  4439. hexChars.push((bite & 0x0f).toString(16));
  4440. }
  4441. return hexChars.join('');
  4442. },
  4443. /**
  4444. * Converts a hex string to a word array.
  4445. *
  4446. * @param {string} hexStr The hex string.
  4447. *
  4448. * @return {WordArray} The word array.
  4449. *
  4450. * @static
  4451. *
  4452. * @example
  4453. *
  4454. * var wordArray = CryptoJS.enc.Hex.parse(hexString);
  4455. */
  4456. parse: function (hexStr) {
  4457. // Shortcut
  4458. var hexStrLength = hexStr.length;
  4459. // Convert
  4460. var words = [];
  4461. for (var i = 0; i < hexStrLength; i += 2) {
  4462. words[i >>> 3] |= parseInt(hexStr.substr(i, 2), 16) << (24 - (i % 8) * 4);
  4463. }
  4464. return new WordArray.init(words, hexStrLength / 2);
  4465. }
  4466. };
  4467. /**
  4468. * Latin1 encoding strategy.
  4469. */
  4470. var Latin1 = C_enc.Latin1 = {
  4471. /**
  4472. * Converts a word array to a Latin1 string.
  4473. *
  4474. * @param {WordArray} wordArray The word array.
  4475. *
  4476. * @return {string} The Latin1 string.
  4477. *
  4478. * @static
  4479. *
  4480. * @example
  4481. *
  4482. * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
  4483. */
  4484. stringify: function (wordArray) {
  4485. // Shortcuts
  4486. var words = wordArray.words;
  4487. var sigBytes = wordArray.sigBytes;
  4488. // Convert
  4489. var latin1Chars = [];
  4490. for (var i = 0; i < sigBytes; i++) {
  4491. var bite = (words[i >>> 2] >>> (24 - (i % 4) * 8)) & 0xff;
  4492. latin1Chars.push(String.fromCharCode(bite));
  4493. }
  4494. return latin1Chars.join('');
  4495. },
  4496. /**
  4497. * Converts a Latin1 string to a word array.
  4498. *
  4499. * @param {string} latin1Str The Latin1 string.
  4500. *
  4501. * @return {WordArray} The word array.
  4502. *
  4503. * @static
  4504. *
  4505. * @example
  4506. *
  4507. * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
  4508. */
  4509. parse: function (latin1Str) {
  4510. // Shortcut
  4511. var latin1StrLength = latin1Str.length;
  4512. // Convert
  4513. var words = [];
  4514. for (var i = 0; i < latin1StrLength; i++) {
  4515. words[i >>> 2] |= (latin1Str.charCodeAt(i) & 0xff) << (24 - (i % 4) * 8);
  4516. }
  4517. return new WordArray.init(words, latin1StrLength);
  4518. }
  4519. };
  4520. /**
  4521. * UTF-8 encoding strategy.
  4522. */
  4523. var Utf8 = C_enc.Utf8 = {
  4524. /**
  4525. * Converts a word array to a UTF-8 string.
  4526. *
  4527. * @param {WordArray} wordArray The word array.
  4528. *
  4529. * @return {string} The UTF-8 string.
  4530. *
  4531. * @static
  4532. *
  4533. * @example
  4534. *
  4535. * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
  4536. */
  4537. stringify: function (wordArray) {
  4538. try {
  4539. return decodeURIComponent(escape(Latin1.stringify(wordArray)));
  4540. } catch (e) {
  4541. throw new Error('Malformed UTF-8 data');
  4542. }
  4543. },
  4544. /**
  4545. * Converts a UTF-8 string to a word array.
  4546. *
  4547. * @param {string} utf8Str The UTF-8 string.
  4548. *
  4549. * @return {WordArray} The word array.
  4550. *
  4551. * @static
  4552. *
  4553. * @example
  4554. *
  4555. * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
  4556. */
  4557. parse: function (utf8Str) {
  4558. return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  4559. }
  4560. };
  4561. /**
  4562. * Abstract buffered block algorithm template.
  4563. *
  4564. * The property blockSize must be implemented in a concrete subtype.
  4565. *
  4566. * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
  4567. */
  4568. var BufferedBlockAlgorithm = C_lib.BufferedBlockAlgorithm = Base.extend({
  4569. /**
  4570. * Resets this block algorithm's data buffer to its initial state.
  4571. *
  4572. * @example
  4573. *
  4574. * bufferedBlockAlgorithm.reset();
  4575. */
  4576. reset: function () {
  4577. // Initial values
  4578. this._data = new WordArray.init();
  4579. this._nDataBytes = 0;
  4580. },
  4581. /**
  4582. * Adds new data to this block algorithm's buffer.
  4583. *
  4584. * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
  4585. *
  4586. * @example
  4587. *
  4588. * bufferedBlockAlgorithm._append('data');
  4589. * bufferedBlockAlgorithm._append(wordArray);
  4590. */
  4591. _append: function (data) {
  4592. // Convert string to WordArray, else assume WordArray already
  4593. if (typeof data == 'string') {
  4594. data = Utf8.parse(data);
  4595. }
  4596. // Append
  4597. this._data.concat(data);
  4598. this._nDataBytes += data.sigBytes;
  4599. },
  4600. /**
  4601. * Processes available data blocks.
  4602. *
  4603. * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
  4604. *
  4605. * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
  4606. *
  4607. * @return {WordArray} The processed data.
  4608. *
  4609. * @example
  4610. *
  4611. * var processedData = bufferedBlockAlgorithm._process();
  4612. * var processedData = bufferedBlockAlgorithm._process(!!'flush');
  4613. */
  4614. _process: function (doFlush) {
  4615. // Shortcuts
  4616. var data = this._data;
  4617. var dataWords = data.words;
  4618. var dataSigBytes = data.sigBytes;
  4619. var blockSize = this.blockSize;
  4620. var blockSizeBytes = blockSize * 4;
  4621. // Count blocks ready
  4622. var nBlocksReady = dataSigBytes / blockSizeBytes;
  4623. if (doFlush) {
  4624. // Round up to include partial blocks
  4625. nBlocksReady = Math.ceil(nBlocksReady);
  4626. } else {
  4627. // Round down to include only full blocks,
  4628. // less the number of blocks that must remain in the buffer
  4629. nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  4630. }
  4631. // Count words ready
  4632. var nWordsReady = nBlocksReady * blockSize;
  4633. // Count bytes ready
  4634. var nBytesReady = Math.min(nWordsReady * 4, dataSigBytes);
  4635. // Process blocks
  4636. if (nWordsReady) {
  4637. for (var offset = 0; offset < nWordsReady; offset += blockSize) {
  4638. // Perform concrete-algorithm logic
  4639. this._doProcessBlock(dataWords, offset);
  4640. }
  4641. // Remove processed words
  4642. var processedWords = dataWords.splice(0, nWordsReady);
  4643. data.sigBytes -= nBytesReady;
  4644. }
  4645. // Return processed words
  4646. return new WordArray.init(processedWords, nBytesReady);
  4647. },
  4648. /**
  4649. * Creates a copy of this object.
  4650. *
  4651. * @return {Object} The clone.
  4652. *
  4653. * @example
  4654. *
  4655. * var clone = bufferedBlockAlgorithm.clone();
  4656. */
  4657. clone: function () {
  4658. var clone = Base.clone.call(this);
  4659. clone._data = this._data.clone();
  4660. return clone;
  4661. },
  4662. _minBufferSize: 0
  4663. });
  4664. /**
  4665. * Abstract hasher template.
  4666. *
  4667. * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
  4668. */
  4669. var Hasher = C_lib.Hasher = BufferedBlockAlgorithm.extend({
  4670. /**
  4671. * Configuration options.
  4672. */
  4673. cfg: Base.extend(),
  4674. /**
  4675. * Initializes a newly created hasher.
  4676. *
  4677. * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
  4678. *
  4679. * @example
  4680. *
  4681. * var hasher = CryptoJS.algo.SHA256.create();
  4682. */
  4683. init: function (cfg) {
  4684. // Apply config defaults
  4685. this.cfg = this.cfg.extend(cfg);
  4686. // Set initial values
  4687. this.reset();
  4688. },
  4689. /**
  4690. * Resets this hasher to its initial state.
  4691. *
  4692. * @example
  4693. *
  4694. * hasher.reset();
  4695. */
  4696. reset: function () {
  4697. // Reset data buffer
  4698. BufferedBlockAlgorithm.reset.call(this);
  4699. // Perform concrete-hasher logic
  4700. this._doReset();
  4701. },
  4702. /**
  4703. * Updates this hasher with a message.
  4704. *
  4705. * @param {WordArray|string} messageUpdate The message to append.
  4706. *
  4707. * @return {Hasher} This hasher.
  4708. *
  4709. * @example
  4710. *
  4711. * hasher.update('message');
  4712. * hasher.update(wordArray);
  4713. */
  4714. update: function (messageUpdate) {
  4715. // Append
  4716. this._append(messageUpdate);
  4717. // Update the hash
  4718. this._process();
  4719. // Chainable
  4720. return this;
  4721. },
  4722. /**
  4723. * Finalizes the hash computation.
  4724. * Note that the finalize operation is effectively a destructive, read-once operation.
  4725. *
  4726. * @param {WordArray|string} messageUpdate (Optional) A final message update.
  4727. *
  4728. * @return {WordArray} The hash.
  4729. *
  4730. * @example
  4731. *
  4732. * var hash = hasher.finalize();
  4733. * var hash = hasher.finalize('message');
  4734. * var hash = hasher.finalize(wordArray);
  4735. */
  4736. finalize: function (messageUpdate) {
  4737. // Final message update
  4738. if (messageUpdate) {
  4739. this._append(messageUpdate);
  4740. }
  4741. // Perform concrete-hasher logic
  4742. var hash = this._doFinalize();
  4743. return hash;
  4744. },
  4745. blockSize: 512/32,
  4746. /**
  4747. * Creates a shortcut function to a hasher's object interface.
  4748. *
  4749. * @param {Hasher} hasher The hasher to create a helper for.
  4750. *
  4751. * @return {Function} The shortcut function.
  4752. *
  4753. * @static
  4754. *
  4755. * @example
  4756. *
  4757. * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
  4758. */
  4759. _createHelper: function (hasher) {
  4760. return function (message, cfg) {
  4761. return new hasher.init(cfg).finalize(message);
  4762. };
  4763. },
  4764. /**
  4765. * Creates a shortcut function to the HMAC's object interface.
  4766. *
  4767. * @param {Hasher} hasher The hasher to use in this HMAC helper.
  4768. *
  4769. * @return {Function} The shortcut function.
  4770. *
  4771. * @static
  4772. *
  4773. * @example
  4774. *
  4775. * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
  4776. */
  4777. _createHmacHelper: function (hasher) {
  4778. return function (message, key) {
  4779. return new C_algo.HMAC.init(hasher, key).finalize(message);
  4780. };
  4781. }
  4782. });
  4783. /**
  4784. * Algorithm namespace.
  4785. */
  4786. var C_algo = C.algo = {};
  4787. return C;
  4788. }(Math));
  4789. return CryptoJS;
  4790. }));
  4791. },{}],34:[function(require,module,exports){
  4792. ;(function (root, factory, undef) {
  4793. if (typeof exports === "object") {
  4794. // CommonJS
  4795. module.exports = exports = factory(require("./core"), require("./x64-core"));
  4796. }
  4797. else if (typeof define === "function" && define.amd) {
  4798. // AMD
  4799. define(["./core", "./x64-core"], factory);
  4800. }
  4801. else {
  4802. // Global (browser)
  4803. factory(root.CryptoJS);
  4804. }
  4805. }(this, function (CryptoJS) {
  4806. (function (Math) {
  4807. // Shortcuts
  4808. var C = CryptoJS;
  4809. var C_lib = C.lib;
  4810. var WordArray = C_lib.WordArray;
  4811. var Hasher = C_lib.Hasher;
  4812. var C_x64 = C.x64;
  4813. var X64Word = C_x64.Word;
  4814. var C_algo = C.algo;
  4815. // Constants tables
  4816. var RHO_OFFSETS = [];
  4817. var PI_INDEXES = [];
  4818. var ROUND_CONSTANTS = [];
  4819. // Compute Constants
  4820. (function () {
  4821. // Compute rho offset constants
  4822. var x = 1, y = 0;
  4823. for (var t = 0; t < 24; t++) {
  4824. RHO_OFFSETS[x + 5 * y] = ((t + 1) * (t + 2) / 2) % 64;
  4825. var newX = y % 5;
  4826. var newY = (2 * x + 3 * y) % 5;
  4827. x = newX;
  4828. y = newY;
  4829. }
  4830. // Compute pi index constants
  4831. for (var x = 0; x < 5; x++) {
  4832. for (var y = 0; y < 5; y++) {
  4833. PI_INDEXES[x + 5 * y] = y + ((2 * x + 3 * y) % 5) * 5;
  4834. }
  4835. }
  4836. // Compute round constants
  4837. var LFSR = 0x01;
  4838. for (var i = 0; i < 24; i++) {
  4839. var roundConstantMsw = 0;
  4840. var roundConstantLsw = 0;
  4841. for (var j = 0; j < 7; j++) {
  4842. if (LFSR & 0x01) {
  4843. var bitPosition = (1 << j) - 1;
  4844. if (bitPosition < 32) {
  4845. roundConstantLsw ^= 1 << bitPosition;
  4846. } else /* if (bitPosition >= 32) */ {
  4847. roundConstantMsw ^= 1 << (bitPosition - 32);
  4848. }
  4849. }
  4850. // Compute next LFSR
  4851. if (LFSR & 0x80) {
  4852. // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
  4853. LFSR = (LFSR << 1) ^ 0x71;
  4854. } else {
  4855. LFSR <<= 1;
  4856. }
  4857. }
  4858. ROUND_CONSTANTS[i] = X64Word.create(roundConstantMsw, roundConstantLsw);
  4859. }
  4860. }());
  4861. // Reusable objects for temporary values
  4862. var T = [];
  4863. (function () {
  4864. for (var i = 0; i < 25; i++) {
  4865. T[i] = X64Word.create();
  4866. }
  4867. }());
  4868. /**
  4869. * SHA-3 hash algorithm.
  4870. */
  4871. var SHA3 = C_algo.SHA3 = Hasher.extend({
  4872. /**
  4873. * Configuration options.
  4874. *
  4875. * @property {number} outputLength
  4876. * The desired number of bits in the output hash.
  4877. * Only values permitted are: 224, 256, 384, 512.
  4878. * Default: 512
  4879. */
  4880. cfg: Hasher.cfg.extend({
  4881. outputLength: 512
  4882. }),
  4883. _doReset: function () {
  4884. var state = this._state = []
  4885. for (var i = 0; i < 25; i++) {
  4886. state[i] = new X64Word.init();
  4887. }
  4888. this.blockSize = (1600 - 2 * this.cfg.outputLength) / 32;
  4889. },
  4890. _doProcessBlock: function (M, offset) {
  4891. // Shortcuts
  4892. var state = this._state;
  4893. var nBlockSizeLanes = this.blockSize / 2;
  4894. // Absorb
  4895. for (var i = 0; i < nBlockSizeLanes; i++) {
  4896. // Shortcuts
  4897. var M2i = M[offset + 2 * i];
  4898. var M2i1 = M[offset + 2 * i + 1];
  4899. // Swap endian
  4900. M2i = (
  4901. (((M2i << 8) | (M2i >>> 24)) & 0x00ff00ff) |
  4902. (((M2i << 24) | (M2i >>> 8)) & 0xff00ff00)
  4903. );
  4904. M2i1 = (
  4905. (((M2i1 << 8) | (M2i1 >>> 24)) & 0x00ff00ff) |
  4906. (((M2i1 << 24) | (M2i1 >>> 8)) & 0xff00ff00)
  4907. );
  4908. // Absorb message into state
  4909. var lane = state[i];
  4910. lane.high ^= M2i1;
  4911. lane.low ^= M2i;
  4912. }
  4913. // Rounds
  4914. for (var round = 0; round < 24; round++) {
  4915. // Theta
  4916. for (var x = 0; x < 5; x++) {
  4917. // Mix column lanes
  4918. var tMsw = 0, tLsw = 0;
  4919. for (var y = 0; y < 5; y++) {
  4920. var lane = state[x + 5 * y];
  4921. tMsw ^= lane.high;
  4922. tLsw ^= lane.low;
  4923. }
  4924. // Temporary values
  4925. var Tx = T[x];
  4926. Tx.high = tMsw;
  4927. Tx.low = tLsw;
  4928. }
  4929. for (var x = 0; x < 5; x++) {
  4930. // Shortcuts
  4931. var Tx4 = T[(x + 4) % 5];
  4932. var Tx1 = T[(x + 1) % 5];
  4933. var Tx1Msw = Tx1.high;
  4934. var Tx1Lsw = Tx1.low;
  4935. // Mix surrounding columns
  4936. var tMsw = Tx4.high ^ ((Tx1Msw << 1) | (Tx1Lsw >>> 31));
  4937. var tLsw = Tx4.low ^ ((Tx1Lsw << 1) | (Tx1Msw >>> 31));
  4938. for (var y = 0; y < 5; y++) {
  4939. var lane = state[x + 5 * y];
  4940. lane.high ^= tMsw;
  4941. lane.low ^= tLsw;
  4942. }
  4943. }
  4944. // Rho Pi
  4945. for (var laneIndex = 1; laneIndex < 25; laneIndex++) {
  4946. // Shortcuts
  4947. var lane = state[laneIndex];
  4948. var laneMsw = lane.high;
  4949. var laneLsw = lane.low;
  4950. var rhoOffset = RHO_OFFSETS[laneIndex];
  4951. // Rotate lanes
  4952. if (rhoOffset < 32) {
  4953. var tMsw = (laneMsw << rhoOffset) | (laneLsw >>> (32 - rhoOffset));
  4954. var tLsw = (laneLsw << rhoOffset) | (laneMsw >>> (32 - rhoOffset));
  4955. } else /* if (rhoOffset >= 32) */ {
  4956. var tMsw = (laneLsw << (rhoOffset - 32)) | (laneMsw >>> (64 - rhoOffset));
  4957. var tLsw = (laneMsw << (rhoOffset - 32)) | (laneLsw >>> (64 - rhoOffset));
  4958. }
  4959. // Transpose lanes
  4960. var TPiLane = T[PI_INDEXES[laneIndex]];
  4961. TPiLane.high = tMsw;
  4962. TPiLane.low = tLsw;
  4963. }
  4964. // Rho pi at x = y = 0
  4965. var T0 = T[0];
  4966. var state0 = state[0];
  4967. T0.high = state0.high;
  4968. T0.low = state0.low;
  4969. // Chi
  4970. for (var x = 0; x < 5; x++) {
  4971. for (var y = 0; y < 5; y++) {
  4972. // Shortcuts
  4973. var laneIndex = x + 5 * y;
  4974. var lane = state[laneIndex];
  4975. var TLane = T[laneIndex];
  4976. var Tx1Lane = T[((x + 1) % 5) + 5 * y];
  4977. var Tx2Lane = T[((x + 2) % 5) + 5 * y];
  4978. // Mix rows
  4979. lane.high = TLane.high ^ (~Tx1Lane.high & Tx2Lane.high);
  4980. lane.low = TLane.low ^ (~Tx1Lane.low & Tx2Lane.low);
  4981. }
  4982. }
  4983. // Iota
  4984. var lane = state[0];
  4985. var roundConstant = ROUND_CONSTANTS[round];
  4986. lane.high ^= roundConstant.high;
  4987. lane.low ^= roundConstant.low;;
  4988. }
  4989. },
  4990. _doFinalize: function () {
  4991. // Shortcuts
  4992. var data = this._data;
  4993. var dataWords = data.words;
  4994. var nBitsTotal = this._nDataBytes * 8;
  4995. var nBitsLeft = data.sigBytes * 8;
  4996. var blockSizeBits = this.blockSize * 32;
  4997. // Add padding
  4998. dataWords[nBitsLeft >>> 5] |= 0x1 << (24 - nBitsLeft % 32);
  4999. dataWords[((Math.ceil((nBitsLeft + 1) / blockSizeBits) * blockSizeBits) >>> 5) - 1] |= 0x80;
  5000. data.sigBytes = dataWords.length * 4;
  5001. // Hash final blocks
  5002. this._process();
  5003. // Shortcuts
  5004. var state = this._state;
  5005. var outputLengthBytes = this.cfg.outputLength / 8;
  5006. var outputLengthLanes = outputLengthBytes / 8;
  5007. // Squeeze
  5008. var hashWords = [];
  5009. for (var i = 0; i < outputLengthLanes; i++) {
  5010. // Shortcuts
  5011. var lane = state[i];
  5012. var laneMsw = lane.high;
  5013. var laneLsw = lane.low;
  5014. // Swap endian
  5015. laneMsw = (
  5016. (((laneMsw << 8) | (laneMsw >>> 24)) & 0x00ff00ff) |
  5017. (((laneMsw << 24) | (laneMsw >>> 8)) & 0xff00ff00)
  5018. );
  5019. laneLsw = (
  5020. (((laneLsw << 8) | (laneLsw >>> 24)) & 0x00ff00ff) |
  5021. (((laneLsw << 24) | (laneLsw >>> 8)) & 0xff00ff00)
  5022. );
  5023. // Squeeze state to retrieve hash
  5024. hashWords.push(laneLsw);
  5025. hashWords.push(laneMsw);
  5026. }
  5027. // Return final computed hash
  5028. return new WordArray.init(hashWords, outputLengthBytes);
  5029. },
  5030. clone: function () {
  5031. var clone = Hasher.clone.call(this);
  5032. var state = clone._state = this._state.slice(0);
  5033. for (var i = 0; i < 25; i++) {
  5034. state[i] = state[i].clone();
  5035. }
  5036. return clone;
  5037. }
  5038. });
  5039. /**
  5040. * Shortcut function to the hasher's object interface.
  5041. *
  5042. * @param {WordArray|string} message The message to hash.
  5043. *
  5044. * @return {WordArray} The hash.
  5045. *
  5046. * @static
  5047. *
  5048. * @example
  5049. *
  5050. * var hash = CryptoJS.SHA3('message');
  5051. * var hash = CryptoJS.SHA3(wordArray);
  5052. */
  5053. C.SHA3 = Hasher._createHelper(SHA3);
  5054. /**
  5055. * Shortcut function to the HMAC's object interface.
  5056. *
  5057. * @param {WordArray|string} message The message to hash.
  5058. * @param {WordArray|string} key The secret key.
  5059. *
  5060. * @return {WordArray} The HMAC.
  5061. *
  5062. * @static
  5063. *
  5064. * @example
  5065. *
  5066. * var hmac = CryptoJS.HmacSHA3(message, key);
  5067. */
  5068. C.HmacSHA3 = Hasher._createHmacHelper(SHA3);
  5069. }(Math));
  5070. return CryptoJS.SHA3;
  5071. }));
  5072. },{"./core":33,"./x64-core":35}],35:[function(require,module,exports){
  5073. ;(function (root, factory) {
  5074. if (typeof exports === "object") {
  5075. // CommonJS
  5076. module.exports = exports = factory(require("./core"));
  5077. }
  5078. else if (typeof define === "function" && define.amd) {
  5079. // AMD
  5080. define(["./core"], factory);
  5081. }
  5082. else {
  5083. // Global (browser)
  5084. factory(root.CryptoJS);
  5085. }
  5086. }(this, function (CryptoJS) {
  5087. (function (undefined) {
  5088. // Shortcuts
  5089. var C = CryptoJS;
  5090. var C_lib = C.lib;
  5091. var Base = C_lib.Base;
  5092. var X32WordArray = C_lib.WordArray;
  5093. /**
  5094. * x64 namespace.
  5095. */
  5096. var C_x64 = C.x64 = {};
  5097. /**
  5098. * A 64-bit word.
  5099. */
  5100. var X64Word = C_x64.Word = Base.extend({
  5101. /**
  5102. * Initializes a newly created 64-bit word.
  5103. *
  5104. * @param {number} high The high 32 bits.
  5105. * @param {number} low The low 32 bits.
  5106. *
  5107. * @example
  5108. *
  5109. * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
  5110. */
  5111. init: function (high, low) {
  5112. this.high = high;
  5113. this.low = low;
  5114. }
  5115. /**
  5116. * Bitwise NOTs this word.
  5117. *
  5118. * @return {X64Word} A new x64-Word object after negating.
  5119. *
  5120. * @example
  5121. *
  5122. * var negated = x64Word.not();
  5123. */
  5124. // not: function () {
  5125. // var high = ~this.high;
  5126. // var low = ~this.low;
  5127. // return X64Word.create(high, low);
  5128. // },
  5129. /**
  5130. * Bitwise ANDs this word with the passed word.
  5131. *
  5132. * @param {X64Word} word The x64-Word to AND with this word.
  5133. *
  5134. * @return {X64Word} A new x64-Word object after ANDing.
  5135. *
  5136. * @example
  5137. *
  5138. * var anded = x64Word.and(anotherX64Word);
  5139. */
  5140. // and: function (word) {
  5141. // var high = this.high & word.high;
  5142. // var low = this.low & word.low;
  5143. // return X64Word.create(high, low);
  5144. // },
  5145. /**
  5146. * Bitwise ORs this word with the passed word.
  5147. *
  5148. * @param {X64Word} word The x64-Word to OR with this word.
  5149. *
  5150. * @return {X64Word} A new x64-Word object after ORing.
  5151. *
  5152. * @example
  5153. *
  5154. * var ored = x64Word.or(anotherX64Word);
  5155. */
  5156. // or: function (word) {
  5157. // var high = this.high | word.high;
  5158. // var low = this.low | word.low;
  5159. // return X64Word.create(high, low);
  5160. // },
  5161. /**
  5162. * Bitwise XORs this word with the passed word.
  5163. *
  5164. * @param {X64Word} word The x64-Word to XOR with this word.
  5165. *
  5166. * @return {X64Word} A new x64-Word object after XORing.
  5167. *
  5168. * @example
  5169. *
  5170. * var xored = x64Word.xor(anotherX64Word);
  5171. */
  5172. // xor: function (word) {
  5173. // var high = this.high ^ word.high;
  5174. // var low = this.low ^ word.low;
  5175. // return X64Word.create(high, low);
  5176. // },
  5177. /**
  5178. * Shifts this word n bits to the left.
  5179. *
  5180. * @param {number} n The number of bits to shift.
  5181. *
  5182. * @return {X64Word} A new x64-Word object after shifting.
  5183. *
  5184. * @example
  5185. *
  5186. * var shifted = x64Word.shiftL(25);
  5187. */
  5188. // shiftL: function (n) {
  5189. // if (n < 32) {
  5190. // var high = (this.high << n) | (this.low >>> (32 - n));
  5191. // var low = this.low << n;
  5192. // } else {
  5193. // var high = this.low << (n - 32);
  5194. // var low = 0;
  5195. // }
  5196. // return X64Word.create(high, low);
  5197. // },
  5198. /**
  5199. * Shifts this word n bits to the right.
  5200. *
  5201. * @param {number} n The number of bits to shift.
  5202. *
  5203. * @return {X64Word} A new x64-Word object after shifting.
  5204. *
  5205. * @example
  5206. *
  5207. * var shifted = x64Word.shiftR(7);
  5208. */
  5209. // shiftR: function (n) {
  5210. // if (n < 32) {
  5211. // var low = (this.low >>> n) | (this.high << (32 - n));
  5212. // var high = this.high >>> n;
  5213. // } else {
  5214. // var low = this.high >>> (n - 32);
  5215. // var high = 0;
  5216. // }
  5217. // return X64Word.create(high, low);
  5218. // },
  5219. /**
  5220. * Rotates this word n bits to the left.
  5221. *
  5222. * @param {number} n The number of bits to rotate.
  5223. *
  5224. * @return {X64Word} A new x64-Word object after rotating.
  5225. *
  5226. * @example
  5227. *
  5228. * var rotated = x64Word.rotL(25);
  5229. */
  5230. // rotL: function (n) {
  5231. // return this.shiftL(n).or(this.shiftR(64 - n));
  5232. // },
  5233. /**
  5234. * Rotates this word n bits to the right.
  5235. *
  5236. * @param {number} n The number of bits to rotate.
  5237. *
  5238. * @return {X64Word} A new x64-Word object after rotating.
  5239. *
  5240. * @example
  5241. *
  5242. * var rotated = x64Word.rotR(7);
  5243. */
  5244. // rotR: function (n) {
  5245. // return this.shiftR(n).or(this.shiftL(64 - n));
  5246. // },
  5247. /**
  5248. * Adds this word with the passed word.
  5249. *
  5250. * @param {X64Word} word The x64-Word to add with this word.
  5251. *
  5252. * @return {X64Word} A new x64-Word object after adding.
  5253. *
  5254. * @example
  5255. *
  5256. * var added = x64Word.add(anotherX64Word);
  5257. */
  5258. // add: function (word) {
  5259. // var low = (this.low + word.low) | 0;
  5260. // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
  5261. // var high = (this.high + word.high + carry) | 0;
  5262. // return X64Word.create(high, low);
  5263. // }
  5264. });
  5265. /**
  5266. * An array of 64-bit words.
  5267. *
  5268. * @property {Array} words The array of CryptoJS.x64.Word objects.
  5269. * @property {number} sigBytes The number of significant bytes in this word array.
  5270. */
  5271. var X64WordArray = C_x64.WordArray = Base.extend({
  5272. /**
  5273. * Initializes a newly created word array.
  5274. *
  5275. * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
  5276. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  5277. *
  5278. * @example
  5279. *
  5280. * var wordArray = CryptoJS.x64.WordArray.create();
  5281. *
  5282. * var wordArray = CryptoJS.x64.WordArray.create([
  5283. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  5284. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  5285. * ]);
  5286. *
  5287. * var wordArray = CryptoJS.x64.WordArray.create([
  5288. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  5289. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  5290. * ], 10);
  5291. */
  5292. init: function (words, sigBytes) {
  5293. words = this.words = words || [];
  5294. if (sigBytes != undefined) {
  5295. this.sigBytes = sigBytes;
  5296. } else {
  5297. this.sigBytes = words.length * 8;
  5298. }
  5299. },
  5300. /**
  5301. * Converts this 64-bit word array to a 32-bit word array.
  5302. *
  5303. * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
  5304. *
  5305. * @example
  5306. *
  5307. * var x32WordArray = x64WordArray.toX32();
  5308. */
  5309. toX32: function () {
  5310. // Shortcuts
  5311. var x64Words = this.words;
  5312. var x64WordsLength = x64Words.length;
  5313. // Convert
  5314. var x32Words = [];
  5315. for (var i = 0; i < x64WordsLength; i++) {
  5316. var x64Word = x64Words[i];
  5317. x32Words.push(x64Word.high);
  5318. x32Words.push(x64Word.low);
  5319. }
  5320. return X32WordArray.create(x32Words, this.sigBytes);
  5321. },
  5322. /**
  5323. * Creates a copy of this word array.
  5324. *
  5325. * @return {X64WordArray} The clone.
  5326. *
  5327. * @example
  5328. *
  5329. * var clone = x64WordArray.clone();
  5330. */
  5331. clone: function () {
  5332. var clone = Base.clone.call(this);
  5333. // Clone "words" array
  5334. var words = clone.words = this.words.slice(0);
  5335. // Clone each X64Word object
  5336. var wordsLength = words.length;
  5337. for (var i = 0; i < wordsLength; i++) {
  5338. words[i] = words[i].clone();
  5339. }
  5340. return clone;
  5341. }
  5342. });
  5343. }());
  5344. return CryptoJS;
  5345. }));
  5346. },{"./core":33}],"bignumber.js":[function(require,module,exports){
  5347. 'use strict';
  5348. module.exports = BigNumber; // jshint ignore:line
  5349. },{}],"web3":[function(require,module,exports){
  5350. var web3 = require('./lib/web3');
  5351. web3.providers.HttpProvider = require('./lib/web3/httpprovider');
  5352. web3.providers.IpcProvider = require('./lib/web3/ipcprovider');
  5353. web3.eth.contract = require('./lib/web3/contract');
  5354. web3.eth.namereg = require('./lib/web3/namereg');
  5355. web3.eth.sendIBANTransaction = require('./lib/web3/transfer');
  5356. // dont override global variable
  5357. if (typeof window !== 'undefined' && typeof window.web3 === 'undefined') {
  5358. window.web3 = web3;
  5359. }
  5360. module.exports = web3;
  5361. },{"./lib/web3":9,"./lib/web3/contract":12,"./lib/web3/httpprovider":20,"./lib/web3/ipcprovider":22,"./lib/web3/namereg":25,"./lib/web3/transfer":30}]},{},["web3"])
  5362. //# sourceMappingURL=web3-light.js.map
  5363. `