コード例 #1
0
def createChain(twitterid):

    tweet_id = twitterid
    fct_address = FCT_ADDRESS
    ec_address = EC_ADDRESS

    factomd = Factomd(host='http://YourHostAddress:8088',
                      fct_address=fct_address,
                      ec_address=ec_address,
                      username='******',
                      password='******')

    walletd = FactomWalletd(host='http://YourHostAddress:8089',
                            fct_address=fct_address,
                            ec_address=ec_address,
                            username='******',
                            password='******')

    resp = walletd.new_chain(
        factomd, ["TwitterBank Record",
                  str(tweet_id), "frontendrefinement32"],
        "This is the start of this users TwitterBank Records",
        ec_address=EC_ADDRESS)

    chain_ID = resp['chainid']
    time.sleep(1)

    return chain_ID
コード例 #2
0
#!/usr/bin/python

from factom import Factomd, FactomWalletd
import settings, time, re, os
factomd = Factomd()
walletd = FactomWalletd()

walletd.host = settings.WalletdHost
factomd.host = settings.FactomdHost

Extid1 = 'Test chain entries '
Extid2 = time.strftime("%Y-%m-%d %H:%M")
Extid3 = 'Chain creation  '
Content = 'Chain entries are dummy values'

print factomd.entry_credit_balance(settings.EntryCredits)
result = walletd.new_chain(factomd, [Extid1, Extid2, Extid3], Content,
                           settings.EntryCredits)
print factomd.entry_credit_balance(settings.EntryCredits)

if "chainid" in result:
    print "CHAIN_ID = " + result["chainid"]
else:
    print "No chain created"
    print result
コード例 #3
0
    chain_ext_ids = user_input.split()

    print('chain content: ', chain_content)
    print('chain ext_ids: ', chain_ext_ids)
    print(type(chain_ext_ids), 'CONVERTED!')

    read_file = input("readするfile name: ")
    print (read_file)


    
    # Create new chain!
    # The cost of creating a new chain is 10 ECs.
    try:
        new_chain = walletd.new_chain(factomd=factomd,
                                      ext_ids= chain_ext_ids,
                                      content= chain_content,
                                      ec_address=EC_ADDR)
                                        
        # Store chain ID and entry hash
        chain_id = new_chain['chainid']
        entry_hash = new_chain['entryhash']
        
        # Print result
        print(f'#### New chain created with chain ID: {chain_id} and entry hash: {entry_hash}')
        
        print('      Waiting for the newly created chain to appear on the blockchain')
        # Wait for the new chain to appear on the blockchain
        wait_for_entry(entryhash=entry_hash)
        
    except FactomAPIError as e:
        print(f'{e.data}.\n')
コード例 #4
0
ファイル: app.py プロジェクト: consensusnetworks/ScribeFlask
    def post(self):
        #Step 1 get the posted data
        postedData = request.get_json()

        print(postedData)
        #Step 2 is to read the data
        username = users.find_one("Username")
        # password = postedData["password"]
        handle = postedData["handle"]
        twitterid = str(postedData["twitterid"])

        # Step3 Generate Chain for Twitter Account
        factomd = Factomd(host=factom_url,
                          ec_address=ec_address,
                          fct_address=fct_address,
                          username='******',
                          password='******')
        walletd = FactomWalletd(host=wallet_url,
                                ec_address=ec_address,
                                fct_address=fct_address,
                                username='******',
                                password='******')
        try:
            resp = walletd.new_chain(
                factomd, ['TwitterBank Record',
                          str(twitterid), 'fulltest10'],
                'This is the start of this users TwitterBank Records',
                ec_address=ec_address)
            chain_ID = resp['chainid']
            chainid = chain_ID

        except FactomAPIError as e:
            print(e.data)
            print('ERROR')
            chainid = str(e.data)

        # Step 4 Store the Account in the database for a user
        users.update({
            "Username": username,
        }, {
            "$set": {
                "Accounts": [{
                    "handle": handle,
                    "twitterid": twitterid,
                    "chainid": chainid,
                    "tracking": "yes"
                }]
            }
        })

        #Step 5 Send Account to Faust
        time.sleep(1)
        account = {
            "handle": handle,
            "twitterid": twitterid,
            "chainid": chainid,
        }

        kafka = KafkaClient("kafka:9093")
        producer = SimpleProducer(
            kafka, value_serializer=lambda v: json.dumps(v).encode('utf-8'))
        try:
            logging.info('sending message %s to kafka', chainid)
            producer.send_messages('Scribe',
                                   json.dumps(account).encode('utf-8'))
            logging.info('%s sent!', account)
        except KafkaError as error:
            logging.warning(
                'The message was not sent to the mempool, caused by %s', error)

        print('Sending Condition to Mempool!')

        retJSON = {
            'handle': handle,
            'twitterid': twitterid,
            'chainid': str(chainid),
        }

        return jsonify(retJSON)