def create_vote(Title, username, originaltorAccount, options): options = options.split(",") w3 = blockchainManager.getWeb3() options = [w3.toBytes(text=option) for option in options] # options = [option for option in options] args = (Title, username, options) address = blockchainManager.getBlockchainManager().deploy_contract(originaltorAccount, args) return insertVoteInfo(Title, address, username)
def getTransactionInfo(txhash): blockchainmanager = blockchainManager.getBlockchainManager() info = blockchainmanager.getTransaction(txhash) print('---- info -----') print(info) # 投票 if info['to'] == '0x0': txaddress = info['hash'] txreceipt = blockchainmanager.getTransactionReceipt(txaddress) transactionRecord = getSqlVoteInfo(txreceipt['contractAddress']) info['votingTo'] = transactionRecord['title'] info['votingPromoter'] = transactionRecord['username'] else: txHash = info['hash'] voteRecord = getVoteRecordInfo(txHash) info['votingTo'] = voteRecord['option'] info['votingFrom'] = voteRecord['username'] return info
def getBlocks(pagesize, currentpage): blockchainmanager = blockchainManager.getBlockchainManager() maxBlockNum = blockchainmanager.getMaxBlockNum() ret, ffrom, llimit = pageUtil.pageing(maxBlockNum, pagesize, currentpage) if not ret: return False, [] res = [] for index in range(ffrom + 1, ffrom + llimit): print(index) info = blockchainmanager.getBlockInfoByIndex(index) if info != None: newTransactions = [] for transaction in info['transactions']: newTransactions.append(transaction.hex()) temp = { 'number': info['number'], 'transactionnum': len(info['transactions']), 'transactions': newTransactions, 'hash': info['hash'].hex() } res.append(temp) else: break return True, res
def getVoteRecords(address): blockmanager = blockchainManager.getBlockchainManager() return blockmanager.getVotesRecords(address)
def vote(address, option, account): blockchainmanager = blockchainManager.getBlockchainManager() ret, hash = blockchainmanager.vote(address, option, account) if ret: insertVoteRecord(hash, option, account) return ret, hash
def getVoteInfo(address): blockchainmanager = blockchainManager.getBlockchainManager() contractInfo = blockchainmanager.getContractInfo(address) title = blockchainmanager.getTitle(contractInfo) options = blockchainmanager.getOptions(contractInfo) return {'title': title, 'options': options}
def getTransactions(index): blockchainmanager = blockchainManager.getBlockchainManager() info = blockchainmanager.getBlockInfoByIndex(index) return info['transactions']
def register(username, password): account = blockchainManager.getBlockchainManager().register(password) if insertUserlib(username, password, account): return True, account else: return False, ''
def getTransactionInfo(txhash): blockchainmanager = blockchainManager.getBlockchainManager() info = blockchainmanager.getTransaction(txhash) return info
def makeRecord(date,time,place, content, attList,title): meetingRecords = (date, time, place, (base64.b64encode(content.encode())).decode(), attList, title) tempcontent = '_'.join(meetingRecords) args = [tempcontent] address = blockchainManager.getBlockchainManager().deploy_contract('', args) return recordservice.insertRecordlib(date,time,place, content, attList,title, address)