#!/usr/bin/python3 # Copyright (c) 2015 Davide Gessa # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. # # Modified by Emanuele Muggiri. from libcontractvm import Wallet, WalletExplorer, ConsensusManager from dappforum import ForumManager import sys import time import os consMan = ConsensusManager.ConsensusManager() consMan.bootstrap("http://127.0.0.1:8181") wallet = WalletExplorer.WalletExplorer(wallet_file='A.wallet') forumMan = ForumManager.ForumManager(consMan, wallet=wallet) os.system('clear') commentId = input('Insert comment ID: ') try: print('Broadcasted:', forumMan.deleteComment(commentId)) except: print('Error.')
#!/usr/bin/python3 # Copyright (c) 2015 Davide Gessa # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. from libcontractvm import Wallet, WalletExplorer, ConsensusManager from dapptest import DappTestManager import sys import time consMan = ConsensusManager.ConsensusManager() consMan.bootstrap("http://127.0.0.1:8181") wallet = WalletExplorer.WalletExplorer(wallet_file='test.wallet') dtMan = DappTestManager.DappTestManager(consMan, wallet=wallet) pollID = input('Insert ID of the poll you want to vote: ') vote = input('Insert the answer you are voting: ') try: print('tento il broadcast') print('Broadcasted:', dtMan.vote(pollID, vote)) except: print('Error.')
#!/usr/bin/python3 # Copyright (c) 2015 Davide Gessa # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. from libcontractvm import Wallet, WalletExplorer, ConsensusManager from dapptest import DappTestManager import sys import time consMan = ConsensusManager.ConsensusManager() consMan.bootstrap("http://127.0.0.1:8181") wallet1 = WalletExplorer.WalletExplorer(wallet_file='test.wallet') wallet2 = WalletExplorer.WalletExplorer(wallet_file='test2.wallet') aMan = DappTestManager.DappTestManager(consMan, wallet=wallet1) bMan = DappTestManager.DappTestManager(consMan, wallet=wallet2) #Basic postID = aMan.createPost('Hello post', 'Post di test') print('Posted a post with ID', postID, 'from A') notFound = True while (notFound): postList = aMan.getList() if not postList: print('No posts in database') else: print('Listing posts') for post in postList: print('\t', post['postID']) if postID == post['postID']:
#!/usr/bin/python3 # Copyright (c) 2015 Mattia Setzu # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. from libcontractvm import Wallet, WalletExplorer, ConsensusManager from forum import ForumManager import os import sys import time consMan = ConsensusManager.ConsensusManager() consMan.bootstrap("http://127.0.0.1:8181") #PORTAFOGLIO A walletA = WalletExplorer.WalletExplorer(wallet_file='test.walletA') AMan = ForumManager.ForumManager(consMan, wallet=walletA) #PORTAFOGLIO B walletB = WalletExplorer.WalletExplorer(wallet_file='test.walletB') BMan = ForumManager.ForumManager(consMan, wallet=walletB) #Viene creato un nuovo post col metodo createPost ("","") dall'utente con portafoglio A. #L'id viene memorizzato nella variabile postid. try: postid = AMan.createPost('Hello post', 'Post di test') print('POST-A >', postid) except: print('Error') time.sleep(5)
'PLUGINFO': 'purple', 'INFO': 'white', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'red', }, style='%') stream = logging.StreamHandler() stream.setFormatter(formatter) logger.addHandler(stream) consMan = ConsensusManager.ConsensusManager() consMan.bootstrap("http://127.0.0.1:8181") # Wallets A and B walletA = WalletExplorer.WalletExplorer(wallet_file='A.wallet') walletB = WalletExplorer.WalletExplorer(wallet_file='B.wallet') # Forum managers for users A and B forumManA = ForumManager.ForumManager(consMan, wallet=walletA) forumManB = ForumManager.ForumManager(consMan, wallet=walletB) # returns the string representation of a post def postToStr(p): msg = '\t author:' + p['author'] + '\n\t title:' + p[ 'title'] + '\n\t body:' + p['body'] msg += '\n\t comments:' comments = p['comments'] for commentId in p['comments']: c = forumManA.getCommentInfo(commentId)
if __name__ == "__main__" and len(sys.argv) == 2: player = sys.argv[1].lower() if player == 'spawn': cvmutils.spawn(3) while True: time.sleep(5) sys.exit() consensusManager = ConsensusManager.ConsensusManager() for x in range(3): consensusManager.addNode('http://localhost:' + str(2818 + x)) if player == 'worker': wallet = WalletExplorer.WalletExplorer(wallet_file='testa.wallet') else: wallet = WalletExplorer.WalletExplorer(wallet_file='testb.wallet') cm = ContractManager.ContractManager(consensusManager, wallet=wallet) print(player, 'Chain:', cm.getChainCode()) print(player, 'Address:', cm.getWallet().getAddress()) print(player, 'Network time:', cm.getTime()) print(player, 'Balance:', cm.getWallet().getBalance(), cm.getChainCode()) print(player, 'Time:', cm.getTime()) if player == 'worker': cm.tell( cm.translate('?x.?eps{;t}.!y{t<5}.(?ok & ?no{;t}.!culpable{t<5})'))