57 lines
7.1 KiB
Python
57 lines
7.1 KiB
Python
|
import binascii
|
||
|
import pbkdf2
|
||
|
import pyaes
|
||
|
import calendar
|
||
|
import time
|
||
|
from Crypto.Hash import keccak
|
||
|
from web3 import Web3
|
||
|
from hexbytes import HexBytes
|
||
|
# from MNF.settings import PRIVATE_KEY,ACCOUNT
|
||
|
|
||
|
web3 = Web3(Web3.HTTPProvider("https://rpc-mumbai.maticvigil.com/"))
|
||
|
# CAddress = '0x3B1646233bDec2A4B644de5C88a3FC9972B17E38'
|
||
|
CAddress = '0xCE5F0873c6CDf37003E9B69dA0110B023005DA34'
|
||
|
# privatekey = "0x6f06e1108b833b1918067042e13e60eda262705b80385a02d0330ce0db31d3ad"
|
||
|
abi = '[{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"_userId","type":"uint256"},{"internalType":"string","name":"_module","type":"string"},{"internalType":"string","name":"_services","type":"string"},{"internalType":"uint256","name":"project","type":"uint256"}],"name":"addApprovedUser","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_userId","type":"uint256"},{"internalType":"string","name":"_module","type":"string"},{"internalType":"string","name":"_services","type":"string"},{"internalType":"uint256","name":"project","type":"uint256"},{"internalType":"string","name":"payloadData","type":"string"},{"internalType":"string[]","name":"_files","type":"string[]"},{"internalType":"address[]","name":"publickey","type":"address[]"}],"name":"setCertainUsersData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"user_id","type":"uint256"},{"internalType":"string","name":"module","type":"string"},{"internalType":"string","name":"services","type":"string"},{"internalType":"uint256","name":"project","type":"uint256"},{"internalType":"string","name":"_data","type":"string"},{"internalType":"string[]","name":"Files","type":"string[]"}],"name":"setMNFOrOwnerData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"user_id","type":"uint256"},{"internalType":"string","name":"module","type":"string"},{"internalType":"string","name":"services","type":"string"},{"internalType":"uint256","name":"project","type":"uint256"},{"internalType":"string","name":"_data","type":"string"},{"internalType":"string[]","name":"Files","type":"string[]"}],"name":"setPrivateData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"user_id","type":"uint256"},{"internalType":"string","name":"module","type":"string"},{"internalType":"string","name":"services","type":"string"},{"internalType":"uint256","name":"project","type":"uint256"},{"internalType":"string","name":"_data","type":"string"},{"internalType":"string[]","name":"Files","type":"string[]"}],"name":"setpublicData","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"uint256","name":"_userId","type":"uint256"},{"internalType":"string","name":"_module","type":"string"},{"internalType":"string","name":"_services","type":"string"},{"internalType":"uint256","name":"_project","type":"uint256"}],"name":"getCertainUsersData","outputs":[{"internalType":"string","name":"","type":"string"},{"internalType":"string[]","name":"","type":"string[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"user_id","type":"uint256"},{"internalType":"string","name":"module","type":"string"},{"internalType":"string","name":"services","type":"string"},{"internalType":"uint256","name":"project","type":"uint256"}],"name":"getMNFOrOwnerData","outputs":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"string","name":"mydata","type":"string"},{"internalType":"string[]","name":"files","type":"string[]"}],"internalType":"struct MNFAccessableDataBase.MNFOwnerData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"user_id","type":"uint256"},{"internalType":"string","name":"module","type":"string"},{"internalType":"string","name":"services","type":"string"},{"internalType":"uint256","name":"project","type":"uint256"}],"name":"getPrivateData","outputs":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"string","name":"mydata","type":"string"},{"internalType":"string[]","name":"files","type":"string[]"}],"internalType":"struct MNFAccessableDataBase.privateData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","
|
||
|
|
||
|
contractInst = web3.eth.contract(address=CAddress, abi=abi)
|
||
|
|
||
|
def fetchFromBlockchainForOwner(private_key,user_id,module,services,project):
|
||
|
ACCOUNT = web3.eth.account.from_key(private_key).address
|
||
|
try:
|
||
|
getDataForOwner = contractInst.functions.getPrivateData(user_id,module,services,project).call({'from':ACCOUNT})
|
||
|
return True ,getDataForOwner
|
||
|
except Exception as e:
|
||
|
print("Error calling function:", e)
|
||
|
return False,e
|
||
|
|
||
|
def fetchFromBlockchainForOwner_Mnf(private_key,user_id,module,services,project):
|
||
|
try:
|
||
|
ACCOUNT = web3.eth.account.from_key(private_key).address
|
||
|
getDataForOwnerAndMNF = contractInst.functions. getMNFOrOwnerData(user_id,module,services,project).call({'from':ACCOUNT})
|
||
|
return True ,getDataForOwnerAndMNF
|
||
|
except Exception as e:
|
||
|
return False, e
|
||
|
|
||
|
def fetchFromBlockchainForPublic(private_key,user_id,module,services,project):
|
||
|
try:
|
||
|
ACCOUNT = web3.eth.account.from_key(private_key).address
|
||
|
getDataForPublic = contractInst.functions. getPublicData(user_id,module,services,project).call({'from':ACCOUNT})
|
||
|
return getDataForPublic
|
||
|
except Exception as e:
|
||
|
return False, e
|
||
|
|
||
|
def getcertainUsrsandApprovedUsers(private_key,user_id,module,services,project):
|
||
|
try:
|
||
|
ACCOUNT = web3.eth.account.from_key(private_key).address
|
||
|
getDataCertainAndApprovedUsers = contractInst.functions. getCertainUsersData(user_id,module,services,project).call({'from':ACCOUNT})
|
||
|
return True, getDataCertainAndApprovedUsers
|
||
|
except Exception as e:
|
||
|
return False, e
|
||
|
def getUserprojectIds(user_id,module,services):
|
||
|
try:
|
||
|
getProjectId = contractInst.functions. getProjectId(user_id,module,services).call()
|
||
|
return getProjectId
|
||
|
except Exception as e:
|
||
|
return e
|