Ejemplo n.º 1
0
 async def _execute(self, request: dict) -> dict:
     if self.adapter.local_pow is True:
         from pow import ccurl_interface
         powed_trytes = ccurl_interface.attach_to_tangle(
             request['trytes'],
             request['branchTransaction'],
             request['trunkTransaction'],
             request['minWeightMagnitude']
         )
         return await async_return({'trytes': powed_trytes})
     else:
         return await super(FilterCommand, self)._execute(request)
Ejemplo n.º 2
0
    def test_wrongly_ordered_bundle(self):
        """
        Supply bundle trytes in wrong order.
        `attach_to_tangle` constructs a bundle object from the trytes,
        that should reorder transactions in correct order based on index.
        """
        wrong_bundle_trytes = []
        for txn in reversed(self.bundle.as_tryte_strings()):
            wrong_bundle_trytes.append(txn)

        test_trytes = ccurl_interface.attach_to_tangle(wrong_bundle_trytes,
                                                       self.branch,
                                                       self.trunk,
                                                       mwm=14)

        test_bundle = Bundle.from_tryte_strings(test_trytes)

        validator = BundleValidator(test_bundle)
        if not validator.is_valid():
            raise ValueError(
                'Bundle failed validation:\n{errors}'.format(errors='\n'.join(
                    ('  - ' + e) for e in validator.errors), ), )

        self.assertTrue(validator.is_valid())
Ejemplo n.º 3
0
    def setUpClass(self):
        # This is a valid bundle taken from the Tangle
        self.bundle = Bundle.from_tryte_strings([
            TransactionTrytes(
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999999999999999999999999999999999999999999999999'
                '999999999999999999999999999GTSOCZLYYATDVK9FYRZXRFEHYUWTSXNALBGHO9T9GHANN'
                '9YTJIZHOBWZHYSLDRTIVSYRRBUJZFUKWVNJAJSNA99999999999999999999999FBNGLE9BE'
                'AT9CYCLUX999999999RFAVOBD99999999999B99999999BGNBAIUZAHWWAIHAWHXIDGYQYKI'
                'LEWDCBQXYBNQBFNPOIICLCJKHSX9KLPECYBGWW9CGILRKTVEYTL99AAVSD99RCNCYGIVIRVI'
                'TNVOVQNQE9RFJIRAXCEXQEHEXQEKFXSDQVBQGJQWBRTRSAUPMXJLMFKUJKZ9999UIBLZWXJQ'
                'DMZCPEQRLSFYJLEPIFTOCY9ODVKIYAMXMKYKHFWKEHNGLVKEYDGR9GOXWWNXLOCQFD999999'
                'TANGLE9BEAT9CYCLUX999999999FIAMTJGOF999999999MMMMMMMMMZCJOZALASXIERYTDLY'
                'WMZTJF9HQ'),
            TransactionTrytes(
                '9PTKKTOZFZBKCJTYHMKZZDRHCOYXHOTDQY9ALYIBNGD9UDPTUKPHJBORIICRNLDTECKLGPOGE'
                'VQIVFHIYI9UUYWYEKGRDDGAAXD9EMFSKX9TDWGGPKTIXBCWQKPERPUIRYEEYXYPXGHBSRGQAH'
                'ZOIBPERAWSCMIFJZGYAFQ9XBVYDXVJAXXX9XPTXJTSDMJSLNCBACGQ9CHVCYMEKOKSEBRUGTX'
                'KMU9HLWRNWOZJGIOIKLPZEHDZKCQXFDMYOA9DRK9CJVRQSWZSDUWDCXWFPZIL9PJDQUQNMMBM'
                'STGMOFCXKKCRZKDCRCBYSVDSKXTDKFBYIRVSTIVHGWTBFRGNNAYXZBVNSZDQDQRSJBNMBRZTG'
                'VDWYAHHFEMSWF9CLSZPQYKFD9MOIR9CUZCPQAGBZSPSCRHSYVDKX9ZVEQONHOO9EAAHZSTHAW'
                'SLSVI9HSOYKIGDWSKXCHHPFXMKCIBEASGQXHEIGOAETCBLHWPUBSLMELCUVARTPHGOG9BEQTM'
                'NHA9MJHCRVNKXZTZTMEMSHFKJMWNBXLBLMVJDONO9JDYALFCBQ9GELAXSOEGOLNCPYGSKWRFF'
                'IZNUGVHECQKRIZ9NTCPAXEKIAZLTXCBM9PJCOKSFDL99YPEVKOMWEXED9IAAOVPZLLFBZHVAM'
                'DXEXCAZBGKWVQCXPFSEUNTPYVSLPEYKCTTGPVBSXQYFVWFUCGYLARMB9HA9PTRXAXKEOQLVXQ'
                'TTHYZEXSOLFSEHMVJ9QOLMBGFHPTEQAYDZWSAPADJSSHTBWOZGVSLLPTMOLFZWUQFVKJZQPMZ'
                'T9QACMCOEKJVWBOSKQHUTGLHAWMQHPDHCZEDKVUTYVMZCSMR9YPLRJGLUNTRGSEXLNBYJXLAR'
                'MWWAWVPLZXYAYACMJCNYWISCHBMQAAMGTCFOZN9OZCITSFGBUJVERM9FRYHJYVKXLBALTHKWM'
                'JMECDKGPKNWFWNHXAFQ9UEWBTUJADYFFMD9WAWE9PYEZIHGO9DSRBLLHCKIIVLHRPYR9UIYRN'
                'VDYAL9Y9AEPVYOKBEDXJDYYBKEOLOAZCNLSBOULLOHEYAAJBZDNTNKVULUSUAME9LTAIEEUJV'
                'QRVFXSDDTNDMNRSLAXKZTRCAGLIDVJJVGEJWSGDIH9HGVHDKLXVEEFTHAMLSUVEDMMVSDRPOI'
                'UJTSNZJVMGBCFZYOMUSARYNXTRMFVMZOCZYPTBSOZUXXSYBRKKLZEAQDPNGLYAKAWTSEJKLBK'
                'NASQQPZAB9MKOUZN9TO9ZYUVSTAPWGTMGO9ZARUWBVQT9ZLHAYEVJM9FNJCQNSBIRZ9AIXZEX'
                'N9QMLPZBHTVNVKRPIXMQIA9OAWQFPNHMXOOPEUJQCKXZQOOYLMMJXXQAIVHRLGDKLGBOSKERQ'
                'ZYNQOTVJW9IKMWZSORHMXFNOLSR9SIKBNTOANAZBGPGIPVVIFYWTUMATZAJPMUGYVITWCBBSQ'
                'RVAY9MXJCECVTYASSAVUGKKQBDXYVWLTSL9HCAD9NUEWEHQXQUCDJC9WPVAZEDLTGTLZXUUOH'
                'WCEUXCDYHATVRSJXJNLWCPEOENOBLXHTDOXSQCIDSEOHZHWBAYJV9ALDOBYMLXKNUQYQTEYAW'
                'ZFSWGQOAHFXHZDBNCJDIJXRJDGRIOPCLPGPLG9AVFGQQBWPKNJROPIQDLXHNDGWGZOVBXHRBP'
                'JQ9YHIJ9MNJFFLDTVLXJA9EBVPGVIAIHCDDHHTNX9KZARELDIZVQYUQGCPPCRTU9CDUXCVBYZ'
                'RAUJDUMGGTKKOFQQTEGXRQKYPQTGHBGRCJ9IENKLNBIZNRSPVQ9VBKQLCG9YPYBEKJEYNAIDJ'
                'PHABZJXBWHZLMADR9SDEWICFGRRTVAGZYCMJ9CANUSGIUKKHWUSWBQIBC9TXONXYDURJJWWE9'
                'FKPPRWEJVWVJVKFKLMD9HCYASRUYCZPKM9VUCLOUVBYSMWIRFYJMTNOYXNKLNDWZJSRRZKLQL'
                'YCODRSAKLMIRSPFYOANY9DUCYZYLEXDTGEJAKUDFWZNEGIBLMXZTW9OKF9SQGNNMHMUWIICFX'
                'LFQMSLLSVJIMDEEWGOG9PDAPTZCRAL9TJRFPIOPMSFJOTLPRMEOUWGLTTXODGD9LSDJBTKX9Y'
                '9JNNIYNERDRQWJGICGHUFJCMGBBUZWLHQJUSUMUXNWRNIVHSFSRGMBMO9VTBGBBFOMHGNZQYI'
                'OIIITMJDZLCJGNUWRJPJKOSSKRLUMGDXNRZFUFTZTSKXEZOCHUEWBONL9OBRYNWLPKSGCFE9W'
                'TBVEXQHMZ99999999999999999999999999999999999999999999999999RFAVOBD99A9999'
                '9999B99999999BGNBAIUZAHWWAIHAWHXIDGYQYKILEWDCBQXYBNQBFNPOIICLCJKHSX9KLPEC'
                'YBGWW9CGILRKTVEYTL99AYUMYMXIZRU9IIWNDROROZOINKOLXPOFCRZZTXAWDXUKVV9LMEMNG'
                'HYZUMAPCESBINZGITBMIOQYX99999UIBLZWXJQDMZCPEQRLSFYJLEPIFTOCY9ODVKIYAMXMKY'
                'KHFWKEHNGLVKEYDGR9GOXWWNXLOCQFD999999999999999999999999999999999ZS9MTJGOF'
                '999999999MMMMMMMMMMJVAHLRNJKJGTOLKSKNZWBTJNQP'),
            TransactionTrytes(
                'M9STFJDJXSROWSPZTZXDYCWQDOQPBPAGATRY9SOXIXJOQL99OMWXPNXKCKJHHRPGWEDBLT9EO'
                'IBTFDKZYXFMELEBQABMPIXUKYZKONEQESB9XHXYMQBULQVQLEEPHCZSFSMJKDGKEDRVBKLFKZ'
                'JFNKLZWQPMTQGJKWQNAN9NQRKGWHEMIVZNODTNQNPXOTISDNWT9WZKC9DGLYWHUD9EQ9VTZRF'
                'YUYU9BDHZULDGNUGUOUUXQTXZJVCBPZWYVTBEWVUJAOCZVNUJNMSMSVN9CPXWDSFCMRSWAMLP'
                'AJRAEGSCOPLWYEGWPKKSXYJSBNLGMBLDEQ9NQEM9XDCSYZLUHLLEICKFHBFPIYDNGEZJEJXBE'
                '9HJGFRMHAHNXIGDDZRPAOTUZPEEUGLZYDEJYIYFCMOUNRLZFBYC9BDPWUVIR9DE9QGBEPVMDL'
                'J9HUDJMGVDQNIDQQTCRXLCPNSLZXSUUPNKUCDHKWCMQ9HPVWXSZXKGXCDKX9BXNOFDUYUBBGD'
                'DOJEZISFJLFUMKJJHXNBMLUWZWBQ9QDITUUZWHFEXQVAAKBUEXCO9XFBPAD9IKEODAPALAGSG'
                'XFDLORKHCXSPINKO9HSJF9BXUIBRXNUX9APPTPIUYXVVWIYXGARPKDYNEGQXPWYCRAPZMZYKW'
                'ICPYJWUEBIBPTXNJTBSSQDFKH9ZFQXNNH9MUTVKEYQIYOJTLFJLAQOFZFIVMTHESCNDLGXZXA'
                'OWHXPEDVVBFJHIKCNFGPLUZQBYVRRMYCIAJOOJINAHSATUVCLQNMOAERIAJESBZOABTMBMJVQ'
                'DVBMLDBBONGRW9QJUAXS9LQWRRKH9PLQUEVUDHWRZFP9FPYSWOQQRINOCHSJYPVKEUQPDOHXQ'
                'WZFKOLZFXYQF9WDHKTHBVMACJMNUVYFLDBCCCHKTBJINNBPKVXYTVLVGADMYEYVLYROARFBWE'
                'ATEIHEENZVRNOJRJYIMQJRAOFKUWSDKFTNNDTLCFHXQNRFEUFJN9GFFJXWDPKIQUQBXDARMRK'
                'LSGUSATHVZMJSXFTWIJPCWNG9UWDGQYUGPMSGJSZBCSUPAKQKIHP9EGIXNRNMDGUVJNVMW9RL'
                'TOHXUXI9UZTCRLVMMREWFSRUOBKFVQYH9PUVOWATYNDULLZ9RCBHDUVNJDMOJETQ9H9RKOSQF'
                'XEVDVVJNZZSMFMLLQJTYXAALRIHQJWDCZYFZBLODYGYUP9XGPZVILG9WBGOVVYRUTHDGF9TRZ'
                'GSFIYHAAAGXJTJKRG9ZYBFDSRQPQAOIJHDENVQAPJMBLOIVUZIGHMVXHBKZOFUJVEWCZJNCTS'
                'TDEPQTYCPGGG9ZEDEYTSDBOMLOO9QO9LMJKNRXHLWNJUOLVNGXMLNHXZVKTRJGDD9CERBOTKR'
                'EDGEGUQDBFIKPYPOXXF9KLYAX9SDCCDTCFULSOZRYJSORRZUUN9CCNRQKTCDCOGIYHAHWYBUX'
                'EYVIJTGXCPGIGBFQWOTJX9APYNDCPQ9FSNXUZF9MDRLZIJSYDGYKBQGWTQLEKZSATDKVWFFMH'
                'QNTMNWWJNBKVGI9QDXYYWOFAKI9OZRBOWMZZHLXUJQKIICFTBZAHUTZFIZIAUO9CWSTYMGZPO'
                'PBKIO9ZYNSRHXCCIMKD9SPDQNXALFLNTXWVVYDAFHWLD9YSDGGRQJUBWZXQHVULYVDON9WADY'
                'XPEVAGKTXIUTDRMLE9TTKD9TSHXFHQSOLHOCQ9SYWJWTOC99GAKHRSREJKHCBLYSHPOEYJNYX'
                'IYNSQITTFSMKFL9HRNEKDZSJSYEBJACGTVBRVQGUREAYZEIQQIGWVRWIWSDGBRLAMPKQGZCEO'
                'JPHANGFVYRXZJCDO9MGKBPYPQYVHQWDJVSUKA9VGLJELXFJKTNMQYZYGBHNFLGETZ9SWLDRNO'
                'OUCAWNFOTBFICNEQJNPAZABLPOR99DPWTZZWLIRA9MFPXXHMJL9QWVJOAPYA9REAHBATJYJYJ'
                'DYAGCKFDRSVTXMFFIBDPIBXBINGXTWMM9PSRVAKQEEQGRDJNOHKJDCCFBZZRLIVXPGEZYAV9G'
                'CUGCATAQLMSOABNYLSNSTRPOGIRMKCGDDITKO9TEVOWPRGQHJDYWPZTZ9RVLPWGFDZOZICSUZ'
                'AUPZJVTXCMUEADAKPZMNOTHLMGDJKTQWJQBK9TIGUTLDWYEPNDLJLDDYHQUWNLLH9MJUFAQYI'
                'OIIITMJDZLCJGNUWRJPJKOSSKRLUMGDXNRZFUFTZTSKXEZOCHUEWBONL9OBRYNWLPKSGCFE9W'
                'TBVEX999999999999999999999999999999999999999999999999999999RFAVOBD99B9999'
                '9999B99999999BGNBAIUZAHWWAIHAWHXIDGYQYKILEWDCBQXYBNQBFNPOIICLCJKHSX9KLPEC'
                'YBGWW9CGILRKTVEYTL99AUIBLZWXJQDMZCPEQRLSFYJLEPIFTOCY9ODVKIYAMXMKYKHFWKEHN'
                'GLVKEYDGR9GOXWWNXLOCQFD999999IFJ9JLPZON9CZJWMKJWPMUWHKOYTUOSBWQYCTCGBXAJG'
                'T9KRVDDLBCNXFYKRXDEKJYQMTAMYJXJRA9999999999999999999999999999999BGYMTJGOF'
                '999999999MMMMMMMMMOGZMHCGFJIGGC9JYILNUCHZSDGV')
        ])

        self.single_tx_bundle = Bundle.from_tryte_strings([
            TransactionTrytes(
                'VBCDFDTCADEAXCDDGDIDADEASCCD9DCDFDEAGDXCHDEAPCADTCHDQAEARCCDBDGDTCRCHDTCH'
                'DIDFDEAPCSCXCDDXCGDRCXCBDVCEATC9DXCHDSAEASBBDEABDCDBDEA9DXCQCTCFDCDEAXCSC'
                'EABDXCQCWCEAUCPCRCXC9DXCGDXCGDEAXCADDDTCFDSCXCTCHDEATCIDEAGDTCSCEAGDPCDDX'
                'CTCBDSAEABCTCSCEASCXCVCBDXCGDGDXCADEA9DXCVCID9DPCEAXCBDEATCGDHDEAADPC9DTC'
                'GDIDPCSCPCEA9DCDQCCDFDHDXCGDSAEAOBHDXCPCADEAJDPCFDXCIDGDEAADCD9DTCGDHDXCT'
                'CEABDID9D9DPCEADDFDTCHDXCIDADEAHDXCBDRCXCSCIDBDHDSAEAXBPCADEAJDTCWCXCRCID'
                '9DPCEA9DPCRCXCBDXCPCEA9DXCQCTCFDCDSAEAMBIDFDPCQCXCHDIDFDEAXCBDEACDFDBDPCF'
                'DTCEA9DTCCDSAEAMBFDPCGDEATCIDEASCCD9DCDFDEAEDIDXCGDEAHDCDFDHDCDFDEAXCADDD'
                'TCFDSCXCTCHDEAPC9DXCEDIDTCHDSAEANBCDBDTCRCEAPCEAHDTC9D9DIDGDEATCFDPCHDSAE'
                'AXBIDBDRCEAXCSCEAXCPCRCID9DXCGDEASCIDXCSA99999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999MZW'
                'YYLQNAKEWITJSJZJCPFZWMEYGOVYOKUZYUWMUDLGAAAHTBYNQQNGHLUMSGZNQCJCHOULIZSDC'
                'ATEXD999999999999999999999999999VHURLINTERFACE9TEST9TX999999KGVOBD9999999'
                '9999999999999DLWTLGSTHZKRDSIRWCZ9HCJWNUJBKTWHCBZGRIFTASCTBIBZZNNWFVGHEGJB'
                'EWWXKRFOXD9GLTXPFGRBY9999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999999999999999999999999999999999999999'
                '9999999999999999999999999999999999999CCURLINTERFACE9TEST9TX99999999999999'
                '999999999999999999999999999999999999999999999')
        ])

        self.trunk = TransactionHash('TRUNKTXHASH9TESTVALUEONLY')
        self.branch = TransactionHash('BRANCHTXHASH9TESTVALUEONLY')

        # Result is reused accross tests, no need to calculate it
        # multiple times.
        # Mock away current time calculation, timestamps are imaginary from
        # this point on.
        self.before = 99
        with patch('pow.ccurl_interface.get_current_ms',
                   MagicMock(return_value=100)):
            self.powed = ccurl_interface.attach_to_tangle(
                self.bundle.as_tryte_strings(),
                self.branch,
                self.trunk,
                mwm=14)
        self.after = 101
        self.powed_bundle = Bundle.from_tryte_strings(self.powed)
Ejemplo n.º 4
0
# Generate bundle hash
pb.finalize()

# Declare an api instance
api = iota.Iota("https://nodes.thetangle.org:443")

# Get tips to be approved by your bundle
gta = api.get_transactions_to_approve(
    depth=3)  # Depth = how many milestones back

minimum_weight_magnitude = 14  # target is mainnet

# perform PoW locally
bundle_trytes =\
    ccurl_interface.attach_to_tangle(
        pb.as_tryte_strings(),
        gta['trunkTransaction'],
        gta['branchTransaction'],
        minimum_weight_magnitude
    )

# Broadcast transactions on the Tangle
broadcasted = api.broadcast_and_store(bundle_trytes)

# Returned transactions, can be stored...

bundle_broadcasted = iota.Bundle.from_tryte_strings(broadcasted['trytes'])

pprint('Local pow broadcasted transactions are:')
pprint(bundle_broadcasted.as_json_compatible())
Ejemplo n.º 5
0
# generate bundle hash using sponge/absorb function + normalize bundle hash + copy bundle hash into each transaction / bundle is finalized
pb.finalize()

#bundle is finalized, let's print it
print("\nGenerated bundle hash: %s" % (pb.hash))
print("\nTail Transaction in the Bundle is a transaction #%s." %
      (pb.tail_transaction.current_index))

api = iota.Iota("https://nodes.thetangle.org:443")  # selecting IOTA node

gta = api.get_transactions_to_approve(
    depth=3)  # get tips to be approved by your bundle

mwm = 14  # target is mainnet

bundle_trytes =\
    ccurl_interface.attach_to_tangle(
        pb.as_tryte_strings(),
        gta['trunkTransaction'],
        gta['branchTransaction'],
        mwm
    )

# Broadcast transactions on the Tangle
broadcasted = api.broadcast_and_store(bundle_trytes)

bundle_broadcasted = iota.Bundle.from_tryte_strings(broadcasted['trytes'])

pprint('Local pow broadcasted transactions are:')
pprint(bundle_broadcasted.as_json_compatible())