Adding more chain integrations

main
lza_menace 3 years ago
parent 9df95c1f7c
commit 7a3924cd81

@ -0,0 +1,27 @@
"""meme approval
Revision ID: f15cd9fa0f06
Revises: c548cc54ee17
Create Date: 2021-12-30 13:11:10.706513
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'f15cd9fa0f06'
down_revision = 'c548cc54ee17'
branch_labels = None
depends_on = None
def upgrade():
with op.batch_alter_table('memes', schema=None) as batch_op:
batch_op.add_column(sa.Column('approved', sa.Boolean(), nullable=True))
def downgrade():
with op.batch_alter_table('memes', schema=None) as batch_op:
batch_op.drop_column('approved')

@ -102,6 +102,7 @@ class Meme(db.Model):
title = db.Column(db.String(50))
description = db.Column(db.String(400), nullable=True)
minted = db.Column(db.Boolean, default=False)
approved = db.Column(db.Boolean, default=False)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'))
user = db.relationship('User', back_populates='memes')

@ -19,7 +19,7 @@ bp = Blueprint('meme', 'meme')
@bp.route('/')
def index():
memes = Meme.query.filter(
Meme.meta_ipfs_hash != None
Meme.approved == True
).order_by(Meme.create_date.desc())
w3 = Web3(Web3.HTTPProvider('http://127.0.0.1:9650'))
contract_address = w3.toChecksumAddress(config.CONTRACT_ADDRESS)
@ -38,7 +38,7 @@ def mod():
flash('You are not a moderator', 'warning')
return redirect(url_for('meme.index'))
memes = Meme.query.filter(
Meme.meta_ipfs_hash == None
Meme.approved != True
).order_by(Meme.create_date.asc())
return render_template('index.html', memes=memes)
@ -105,10 +105,10 @@ def show(meme_id):
meme = Meme.query.filter(Meme.id == meme_id).first()
if not meme:
return redirect('/')
if not meme.meta_ipfs_hash and not current_user.is_authenticated:
flash('You need to be a moderator to view that meme.', 'warning')
if not meme.approved and not current_user.is_authenticated:
flash('You need to be logged in to view that meme.', 'warning')
return redirect(url_for('meme.index'))
elif not meme.meta_ipfs_hash and not current_user.is_moderator():
elif not meme.approved and not current_user.is_moderator():
flash('You need to be a moderator to view that meme.', 'warning')
return redirect(url_for('meme.index'))
return render_template('meme.html', meme=meme)
@ -126,8 +126,8 @@ def approve(meme_id, action):
if not meme:
flash('That meme does not exist.', 'warning')
return redirect(url_for('meme.index'))
if meme.meta_ipfs_hash != None:
flash('That meme already has been published to IPFS.', 'warning')
if meme.approved is True:
flash('That meme already has been approved.', 'warning')
return redirect(url_for('meme.show', meme_id=meme.id))
if action == 'approve':
res = upload_to_ipfs(meme.id)
@ -145,8 +145,9 @@ def approve(meme_id, action):
return redirect(url_for('meme.show', meme_id=meme.id))
meme.meta_ipfs_hash = res[0]
meme.meme_ipfs_hash = res[1]
meme.approved = True
db.session.commit()
flash('Published new meme to IPFS.', 'success')
flash('Approved meme and published new meme to local IPFS server.', 'success')
elif action == 'deny':
# delete image
# delete from database

@ -19,7 +19,6 @@ async function onboardMetaMask(){
const connectButton = async () => {
if (!MetaMaskOnboarding.isMetaMaskInstalled()) {
onboardButton.innerText = 'Click here to install MetaMask!';
onboardButton.onclick = () => {
onboardButton.classList.add('is-loading');
onboardButton.disabled = true;

@ -2,7 +2,7 @@
<div class="card">
<div class="card-image">
<figure class="image">
<a href="{{ url_for('meme.show', meme_id=meme.id) }}" up-preload up-follow=".container">
<a href="{{ url_for('meme.show', meme_id=meme.id) }}">
{% if meme.file_name.endswith('mp4') %}
<video class="img-fluid" {% if not request.MOBILE %}autoplay{% else %}controls{% endif %} muted loop>
<source src="{{ url_for('meta.uploaded_file', filename=meme.file_name) }}" type="video/mp4">

@ -2,7 +2,7 @@
<script type="text/javascript">
let contractABI = {{ config.CONTRACT_ABI | tojson }};
let contractAddress = "{{ config.CONTRACT_ADDRESS }}";
const w3 = new Web3(Web3.givenProvider || "http://127.0.0.1:7545");
const w3 = new Web3(Web3.givenProvider);
const contract = new w3.eth.Contract(contractABI, contractAddress);
async function getMetamaskAccount() {
@ -12,4 +12,24 @@
const account = accounts[0];
return account
}
async function getTokenID(ipfsHash) {
if (ipfsHash != '') {
const tokenId = await contract.methods.metadataTokenId(ipfsHash).call();
return tokenId;
}
}
async function isMinted(ipfsHash) {
if (ipfsHash != '') {
const tokenId = await getTokenID(ipfsHash)
if (tokenId == 0) {
return false;
} else {
return true;
}
} else {
return false
}
}
</script>

@ -38,7 +38,19 @@
<p>Meme IPFS: <a href="{{ meme_url }}" target=_self up-preload up-follow=".container">{{ meme.meme_ipfs_hash }}</a></p>
{% endif %}
<p>Meme ID: <code>{{ meme }}</code></p>
{% if not meme.meta_ipfs_hash %}
<div id="profileModal" class="modal">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Modal title</p>
<button class="delete" aria-label="close"></button>
</header>
<section class="modal-card-body">
<p style="word-wrap: break-word;">Wownero Address: {{ meme.user.wownero_address }}</p>
</section>
</div>
</div>
{% if not meme.approved %}
<br/>
<div class="columns">
<div class="column">
@ -50,23 +62,22 @@
</div>
{% else %}
<br/>
<div class="columns">
{% if meme.minted %}
<div id="tipButtons" class="columns" style="display:none;">
<div class="column">
<a class="button is-info is-12 column">Tip AVAX</a>
<a class="button is-info is-12 column" onclick="tipAVAX()">Tip AVAX</a>
</div>
<div class="column">
<a class="button is-info is-12 column">Tip WOWX</a>
<a class="button is-info is-12 column" onclick="tipWOWX()">Tip WOWX</a>
</div>
<div class="column">
<a class="button is-info is-12 column">Tip WOW</a>
<a class="button is-info is-12 column" onclick="tipWOW()">Tip WOW</a>
</div>
{% else %}
</div>
<div id="mintButton" class="columns" style="display:none;">
<div class="column">
<a class="button is-danger is-12 column" onclick="mint()">Mint</a>
</div>
{% endif %}
</div>
</div>
{% endif %}
</div>
</div>
@ -75,31 +86,53 @@
</div>
</section>
{% include 'includes/footer.html' %}
{% if meme.approved %}
{% include 'includes/web3.html' %}
<script type="text/javascript">
async function isMinted() {
const ipfsHash = '{{ meme.meta_ipfs_hash }}';
if (ipfsHash != '') {
const tokenId = await contract.methods.metadataTokenId(ipfsHash).call();
console.log(tokenId);
return
window.addEventListener('DOMContentLoaded', async () => {
let minted = await isMinted('{{ meme.meta_ipfs_hash }}');
if (minted) {
document.getElementById('tipButtons').style.display = "flex";
} else {
document.getElementById('mintButton').style.display = "flex";
}
});
async function tipAVAX() {
const tokenId = await getTokenID('{{ meme.meta_ipfs_hash }}');
const walletAddress = await getMetamaskAccount();
const gasPrice = await w3.eth.getGasPrice();
const gasLimit = await contract.methods.tipAVAX(tokenId).estimateGas({from: walletAddress}, function(err, gas){
return gas;
});
try {
notif(`Tipping meme "{{ meme.id | shorten_address }}" by "{{ meme.user.handle }} ({{ meme.user.public_address | shorten_address }})" to the Avalanche blockchain.`, 'info');
let res = await contract.methods.tipAVAX(tokenId).send({
from: walletAddress,
value: 1000000000000000,
gasPrice: gasPrice,
gas: gasLimit
});
console.log(res);
window.location.href = "";
} catch(e) {
notif(e.message, 'warning');
}
// if (userProfile.userHandle){document.getElementById('userHandle').innerHTML = userProfile.userHandle};
// if (userProfile.wowneroAddress){document.getElementById('wowneroAddress').innerHTML = userProfile.wowneroAddress};
// if (userProfile.metadataIPFSHash){document.getElementById('metadataIPFSHash').innerHTML = userProfile.metadataIPFSHash};
// if (userProfile.tippedAVAX){document.getElementById('tippedAVAX').innerHTML = userProfile.tippedAVAX};
// document.getElementById('tippedWOWX').innerHTML = 0;
// return
}
async function mint() {
if (await isMinted('{{ meme.meta_ipfs_hash }}')) {
notif('Already minted!', 'warning');
return
}
const walletAddress = await getMetamaskAccount();
const gasPrice = await w3.eth.getGasPrice();
const gasLimit = await contract.methods.mint("{{ meme.meta_ipfs_hash }}", "{{ meme.user.public_address }}").estimateGas({from: walletAddress}, function(err, gas){
return gas;
});
try {
notif(`Minting meme "{{ meme.id }}" by "{{ meme.user.handle }} ({{ meme.user.public_address | shorten_address }})" to the Avalanche blockchain.`, 'info');
notif(`Minting meme "{{ meme.id | shorten_address }}" by "{{ meme.user.handle }} ({{ meme.user.public_address | shorten_address }})" to the Avalanche blockchain.`, 'info');
let res = await contract.methods.mint("{{ meme.meta_ipfs_hash }}", "{{ meme.user.public_address }}").send({
from: walletAddress,
value: 0,
@ -113,5 +146,6 @@
}
}
</script>
{% endif %}
</body>
</html>

Loading…
Cancel
Save