Example #1
0
def ipfsFileAdd(filename):
    api = ipfshttpclient.Client()
    ipfsLoadedFile = api.add(filename, recursive=True)
    ipfsHash = (ipfsLoadedFile['Hash'])
    ipfshttpclient.Client.close
    print(ipfsHash)
    return ipfsHash
def _generate_client(
        ipfs_is_available: bool,
        offline: bool) -> ty.Generator[ipfshttpclient.Client, None, None]:
    if ipfs_is_available:
        with ipfshttpclient.Client(offline=offline) as client:
            yield client
    else:
        pytest.skip("Running IPFS node required")
Example #3
0
def test_client_session_param():
    client = ipfshttpclient.Client(session=True)
    assert client._client._session is not None
    try:
        with pytest.raises(Exception):
            with client:
                pass  # Should fail because a session is already open
        assert client._client._session is not None
    finally:
        client.close()
    assert client._client._session is None
Example #4
0
def test_client_session_context():
    client = ipfshttpclient.Client()
    assert client._client._session is None
    with client:
        assert client._client._session is not None
    assert client._client._session is None
Example #5
0
def createIPFSClient(daemonMultiaddr=IPFSAPI_MUTLIADDRESS):
    try:
        return ipfsapi.Client(daemonMultiaddr)
    except (StringParseError, AddressError):
        return None  # Malformed multiaddress for the daemon
Example #6
0
import json
from web3 import Web3
import numpy as np
import webbrowser

try:
    ganache_url = 'http://127.0.0.1:7545'
    web3 = Web3(Web3.HTTPProvider(ganache_url))
except:
    print('Check ganache is running or not?')
    exit(0)

web3.eth.defaultAccount = web3.eth.accounts[0]

try:
    client = ipfshttpclient.Client('/dns/localhost/tcp/5001/http')
except:
    print('check ipfs client url')
    exit(0)

abi = json.loads(
    '[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"string","name":"hashOfIpfs","type":"string"},{"internalType":"uint16","name":"hashNo","type":"uint16"}],"name":"addHash","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"hashOfIpfs","type":"string"},{"internalType":"uint16","name":"hashNo","type":"uint16"}],"name":"deleteHash","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"destroy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"hashNo","type":"uint16"}],"name":"displayHash","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"hashOfIpfs","type":"string"},{"internalType":"string","name":"currentHash","type":"string"},{"internalType":"uint16","name":"hashNo","type":"uint16"}],"name":"updateHash","outputs":[],"stateMutability":"nonpayable","type":"function"}]'
)
address = web3.toChecksumAddress('0x970ec18eF7CFC69AadE1fB2c14bAC8e10b3042Ef')
contract = web3.eth.contract(address=address, abi=abi)

print(contract.functions.addHash('adfasf', 1).call())


class StartupWindow:
    def __init__(self, master):
Example #7
0
def get_client(offline=False):
    if is_available():
        return ipfshttpclient.Client(offline=offline)
    else:
        pytest.skip("Running IPFS node required")
Example #8
0
def create_ipfs_client(daemonMultiaddr=IPFSAPI_MUTLIADDRESS):
    """Create and return IPFS client."""
    try:
        return ipfshttpclient.Client(daemonMultiaddr)
    except Exception as err:
        raise Exception('Cannot create an IPFS client.') from err
Example #9
0
def ipfsFileget(hash):
    api = ipfshttpclient.Client()
    api.get(hash)