Commit 256124d2 authored by Bitcoin Please's avatar Bitcoin Please
Browse files

Updated Mecenas Oracle contract.

parent b204ddb6
......@@ -69,11 +69,9 @@ contract MecenasOracle(
* Oracle signatures, as that would reduce the payout amount.
*/
if (pk == oraclePk) {
/* require(tx.age >= 144); */
require(tx.age >= 0);
require(tx.age >= 144);
} else {
/* require(tx.age >= 162); */
require(tx.age >= 1);
require(tx.age >= 162);
}
/* Set oracle-defined block height. */
......@@ -96,7 +94,8 @@ contract MecenasOracle(
int oraclePayoutAmt = int(oracleMsg.split(8)[1]);
/* Set (hardcoded) miner fee. */
int minerFee = 1337;
/* int minerFee = 1337; */
int minerFee = 2000; // required for 2 inputs+outputs
/* Retrieve the coin's value and cast it to an integer. */
int coinValue = int(bytes(tx.value));
......
......@@ -12,7 +12,7 @@ const addAssurance = async ({ rootGetters }, _assurance) => {
/* Set api target. */
const target = 'http://localhost:6767/v1/assurance'
// const target = 'https://api.causes.cash/v1/campaigns'
// const target = 'https://api.causes.cash/v1/assurance'
const result = await superagent
.post(target)
......
......@@ -109,7 +109,7 @@
<input
ref="pledgeAuth"
class="form-control"
class="form-control pledge-auth"
type="text"
id="pledge-auth"
placeholder="waiting for authorization message..."
......@@ -190,6 +190,21 @@ export default {
return this.getAddress('deposit')
},
pledgedValue() {
/* Calculate pledged (satoshis). */
const pledged = this.campaign.assurance.pledges
.reduce((accumulator, pledge) => {
if (pledge.isSpent === true) {
return accumulator
} else {
return accumulator + pledge.satoshis
}
}, 0)
console.log('PLEDGED', pledged)
return pledged
},
pledgeDetails() {
/* Build (pledge) package. */
const pkg = {
......@@ -268,7 +283,8 @@ export default {
onRangeChange() {
/* Calculate remaining (satoshis). */
const remaining = this.pledgeGoal / 2 // FOR DEV ONLY
const remaining = this.pledgeGoal - this.pledgedValue
console.log('REMAINING', remaining)
/* Calculate satoshis. */
const satoshis = parseInt(remaining * (this.pledgeRange / 100.0))
......@@ -303,6 +319,11 @@ export default {
},
handleAuth() {
/* Validate pledge authorization. */
if (!this.pledgeAuth) {
return
}
/* Wait a tick. */
setTimeout(() => {
/* Initialize pledge authorization. */
......@@ -321,6 +342,14 @@ export default {
console.log('PLEDGE AUTH', pledgeAuth)
this.addAssurance(pledgeAuth)
/* Calculate remaining (satoshis). */
const remaining = this.pledgeGoal - this.pledgedValue
console.log('REMAINING', remaining)
if (remaining <= 0) {
this.broadcast()
}
} catch (err) {
console.error(err)
}
......@@ -336,6 +365,13 @@ export default {
}, 10)
},
broadcast() {
console.log('STARTED BROADCASTING...')
const pledges = this.campaign.assurance.pledges.filter(pledge => !pledge.isSpent)
console.log('BROADCAST (pledges):', pledges)
},
/**
* Set Clipboard
*/
......@@ -380,7 +416,6 @@ export default {
created: async function () {
this.usd = await Nito.Markets.getTicker('BCH', 'USD')
// console.info(`Market price (USD)`, this.usd)
console.log('ASSURANCE', this.campaign.assurance)
/* Initialize pledge range. */
this.pledgeRange = 5
......@@ -443,5 +478,8 @@ form {
width: 90%;
height: 100px;
}
.pledge-auth {
width: 90%;
}
</style>
<template>
<div id="funds" class="tabs">
<h1>Use of Funds</h1>
<div v-if="budget">
<h1>Use of Funds</h1>
<p>
Every campaign has a fixed budget that will be followed strictly.
</p>
<p>
Every campaign has a fixed budget that will be followed strictly.
</p>
<table>
<tbody>
<tr>
<th>Label</th>
<th>Allocation</th>
<th>Comments</th>
</tr>
<tr v-for="item of budget" :key="item.txid">
<td>{{item.label}}</td>
<td>{{item.amount}}</td>
<td>{{item.comments}}</td>
</tr>
<!-- <tr>
<td>Andrew</td>
<td>$80</td>
<td>June 15, 2017</td>
</tr> -->
</tbody>
</table>
<table>
<tbody>
<tr>
<th>Label</th>
<th>Allocation</th>
<th>Comments</th>
</tr>
<tr v-for="item of budget" :key="item.txid">
<td>{{item.label}}</td>
<td>{{item.amount}}</td>
<td>{{item.comments}}</td>
</tr>
<!-- <tr>
<td>Andrew</td>
<td>$80</td>
<td>June 15, 2017</td>
</tr> -->
</tbody>
</table>
<hr />
<hr />
<h1>Campaign Expenses</h1>
<h1>Campaign Expenses</h1>
<p>
Every campaign has a fixed expenses that will be reported publicly.
</p>
<p>
Every campaign has a fixed expenses that will be reported publicly.
</p>
<table>
<tbody>
<tr>
<th>Label</th>
<th>Amount</th>
<th>Comments</th>
</tr>
<tr v-for="item of expenses" :key="item.txid">
<td>{{item.label}}</td>
<td>{{item.amount}}</td>
<td>{{item.comments}}</td>
</tr>
<!-- <tr>
<td>Andrew</td>
<td>$80</td>
<td>June 15, 2017</td>
</tr> -->
</tbody>
</table>
<table>
<tbody>
<tr>
<th>Label</th>
<th>Amount</th>
<th>Comments</th>
</tr>
<tr v-for="item of expenses" :key="item.txid">
<td>{{item.label}}</td>
<td>{{item.amount}}</td>
<td>{{item.comments}}</td>
</tr>
<!-- <tr>
<td>Andrew</td>
<td>$80</td>
<td>June 15, 2017</td>
</tr> -->
</tbody>
</table>
</div>
<div v-else class="campaigns">
<h1>Use of funds</h1>
<p class="m-3">
There is no budget available
</p>
</div>
</div>
</template>
......@@ -64,30 +74,30 @@ export default {
},
data: () => {
return {
budget: [],
expenses: [],
budget: null,
expenses: null,
}
},
created: function () {
/* Sample budget. */
const budget = {
txid: 'some-random-transaction-id',
label: 'Development',
amount: '100%',
comments: 'To be determined',
}
// const budget = {
// txid: 'some-random-transaction-id',
// label: 'Development',
// amount: '100%',
// comments: 'To be determined',
// }
this.budget.push(budget)
// this.budget.push(budget)
/* Sample expenses. */
const expense = {
this.expenses = [{
txid: 'some-random-transaction-id',
label: 'Food',
amount: '$10',
comments: 'To be determined',
}
}]
this.expenses.push(expense)
// this.expenses.push(expense)
},
}
</script>
......
......@@ -5,14 +5,16 @@
<table class="mt-3">
<tbody>
<tr>
<th>Name</th>
<th>Donate Amount</th>
<th>Date</th>
<th>Nickname / Alias</th>
<th class="text-center">Comment</th>
<th class="text-center">Amount (USD)</th>
<th class="text-right">Time</th>
</tr>
<tr v-for="pledge of pledges" :key="pledge.previousTransactionHash">
<td>{{pledge.alias}}</td>
<td>{{pledge.satoshis}}</td>
<td>{{formatDate(pledge.createdAt)}}</td>
<td class="text-center">{{pledge.comment}}</td>
<td class="text-center">{{formatAmount(pledge.satoshis)}}</td>
<td class="text-right">{{formatDate(pledge.createdAt)}}</td>
</tr>
</tbody>
</table>
......@@ -22,6 +24,7 @@
<script>
/* Import modules. */
import moment from 'moment'
import Nito from 'nitojs'
import numeral from 'numeral'
export default {
......@@ -30,21 +33,31 @@ export default {
},
data: () => {
return {
pledges: [],
usd: null,
pledges: null,
}
},
watch: {
campaign: function (_campaign) {
console.log('SUPPORTERS CAMPAIGN UPDATE', _campaign);
/* Handle campaign supporters. */
if (_campaign && _campaign.assurance) {
this.pledges = _campaign.assurance.pledges
this.pledges = _campaign.assurance.pledges.filter(pledge => {
return pledge.isSpent === false
})
/* Sort pledges (decending). */
this.pledges.sort((a, b) => {
return b.satoshis - a.satoshis
})
}
},
},
methods: {
formatAmount(_value) {
if (_value) {
return numeral(_value).format('$0,0[.]00')
formatAmount(_amount) {
const value = (_amount / 100000000) * this.usd
if (value) {
return numeral(value).format('$0,0[.]00')
} else {
return '$0.00'
}
......@@ -52,22 +65,18 @@ export default {
formatDate(_date) {
if (_date) {
return moment.unix(_date).format('lll')
return moment.unix(_date).fromNow()
} else {
return 'n/a'
}
},
},
created: function () {
/* Sample pledge. */
const pledge = {
txid: 'some-random-transaction-id',
name: 'Satoshi N.',
pledgeAmount: '$13.37',
pledgedAt: moment().subtract(3, 'hours').format('lll'),
}
created: async function () {
this.usd = await Nito.Markets.getTicker('BCH', 'USD')
// console.info(`Market price (USD)`, this.usd)
this.pledges.push(pledge)
/* Initialize pledges. */
this.pledges = []
},
}
</script>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment