Beispiel #1
0
def upload_file_to_arweave(filepath, url, tags):
    wallet_path = os.path.join(settings.BASE_DIR, 'wallet')

    files = [f for f in listdir(wallet_path) if isfile(join(wallet_path, f))]

    if len(files) > 0:
        filename = files[0]
    else:
        raise FileNotFoundError(
            "Unable to load a wallet JSON file from wallet/ ")

    wallet_path = join(wallet_path, filename)

    wallet = Wallet(wallet_path)

    tx = {id: None}

    logger.error("Loading {}", format(filepath))

    with open(filepath, 'r') as file_to_upload:
        logger.error("Loaded {}", format(filepath))
        data = file_to_upload.read()

        tx = Transaction(wallet, data=data.encode())

        tx.add_tag("app", "Arkive")
        tx.add_tag('created', str(arrow.now().timestamp))
        tx.add_tag('url', url)

        for tag in tags:
            tx.add_tag("keyword", tag['keyword'])

        tx.sign(wallet)

        tx.post()

    return tx
Beispiel #2
0
                page['transaction_id'] = tx.id.decode()
            except Exception as e:
                logger.debug(e)

        self.save_project_json()

    def save_project_json(self):
        json_output = json.dumps(self.project, indent=4, sort_keys=True)
        output_filename = "wwproj-{}-{}.json".format(
            self.project.get('root_url'),
            arrow.now().timestamp)

        with open(output_filename, "w") as opf:
            opf.write(json_output)


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)

    depth = 2
    if len(sys.argv) < 3:
        print("Not engough arguments no URL or wallet file supplied")

    if len(sys.argv) > 3:
        depth = int(sys.argv[3])

    wallet = Wallet(sys.argv[2])

    ww = WebWhacker(wallet, sys.argv[1], depth=depth)
    ww.save_to_blockchain()
import sys, os
from jose.utils import base64url_decode
from arweave import Wallet, Transaction

if len(sys.argv) < 3:
    print("Usage: {} <wallet> <transaction id> [output.pdf]".format(
        sys.argv[0]))
    sys.exit(1)

wallet = Wallet(sys.argv[1])
txn = Transaction(wallet, id=sys.argv[2])
txn.get_transaction()

tags_decoded = {
    base64url_decode(tag["name"].encode()).decode():
    base64url_decode(tag["value"].encode()).decode()
    for tag in txn.tags
}

if len(sys.argv) == 4:
    outfile = sys.argv[3]
elif "id" in tags_decoded:
    outfile = tags_decoded["id"] + ".pdf"
else:
    outfile = "output.pdf"

with open(outfile, "wb+") as f:
    f.write(base64url_decode(txn.data.encode()))

print("Info for transaction {}".format(txn.id))
print()
from arweave import Wallet
import arweave
import responses
from arweave.utils import winston_to_ar
import pytest

wallet = Wallet("test_jwk_file.json")


@responses.activate
def test_get_balance():
    mock_balance = "12345678"
    mock_url = '{}/wallet/{}/balance'.format(wallet.api_url, wallet.address)
    # register successful response
    responses.add(responses.GET, mock_url, body=mock_balance, status=200)
    # register unsuccessful response
    responses.add(responses.GET,
                  mock_url,
                  body="some error occurred",
                  status=400)

    # execute test against mocked response
    balance = wallet.balance
    assert balance == winston_to_ar(mock_balance)
    with pytest.raises(arweave.arweave_lib.ArweaveTransactionException):
        balance = wallet.balance


@responses.activate
def test_get_last_transaction_id():
    # register successful response
Beispiel #5
0
from arweave import Transaction, Wallet

wallet = Wallet("wallet.json")

with open('index.html', 'r') as mypdf:
    pdf_string_data = mypdf.read()
    transaction = Transaction(wallet, data=pdf_string_data)
    transaction.sign()
    transaction.send()
from webhook import report_balance
from time import sleep
from arweave import Wallet
import sys

wallet = Wallet(sys.argv[1])

while True:
    report_balance(wallet.get_balance())

    sleep(60)