Commit 843b2a6e authored by Bitcoin Please's avatar Bitcoin Please
Browse files

Added support for metadata.

parent 91724137
......@@ -7,6 +7,7 @@ import getCampaign from './campaigns/getters/getCampaign'
import getCampaigns from './campaigns/getters/getCampaigns'
/* Import modules (actions). */
import addAssurance from './campaigns/actions/addAssurance'
import updateAsset from './campaigns/actions/updateAsset'
import updateCampaign from './campaigns/actions/updateCampaign'
......@@ -34,6 +35,7 @@ const getters = {
/* Actions. */
const actions = {
addAssurance,
updateAsset,
updateCampaign,
}
......
/* Import modules. */
import superagent from 'superagent'
/**
* Add Assurance
*/
const addAssurance = async ({ rootGetters }, _assurance) => {
// console.log('ADD ASSURANCE:', _assurance)
const signedPkg = rootGetters['profile/getSignedMessage'](JSON.stringify(_assurance))
// console.log('SIGNED PACKAGE', signedPkg)
/* Set api target. */
const target = 'http://localhost:6767/v1/assurance'
// const target = 'https://api.causes.cash/v1/campaigns'
const result = await superagent
.post(target)
.send(signedPkg)
// console.log('RESULT', result)
/* Return result. */
return result
}
/* Export module. */
export default addAssurance
......@@ -11,7 +11,8 @@ const updateCampaign = async ({ rootGetters }, _campaign) => {
// console.log('SIGNED PACKAGE', signedPkg)
/* Set api target. */
const target = 'https://api.causes.cash/v1/campaigns'
const target = 'http://localhost:6767/v1/campaigns'
// const target = 'https://api.causes.cash/v1/campaigns'
const result = await superagent
.put(target)
......
......@@ -53,14 +53,14 @@ const getSignedMessage = (state, getters, rootState, rootGetters) => (_message)
const wif = childNode.privateKey.toWIF()
// console.log('GET SIGNED MESSAGE (wif):', wif)
/* Request signature. */
const signature = Nito.Message.sign(_message, wif)
// console.log('GET SIGNED MESSAGE (signature):', signature)
/* Set nonce. */
const nonce = moment().unix()
// console.log('NONCE', nonce)
/* Request signature. */
const signature = Nito.Message.sign(`${_message}:${nonce}`, wif)
// console.log('GET SIGNED MESSAGE (signature):', signature)
/* Build package. */
const pkg = {
message: _message,
......
......@@ -8,6 +8,7 @@ import getDustAmount from './wallet/getters/getDustAmount'
import getHDNode from './wallet/getters/getHDNode'
import getHistory from './wallet/getters/getHistory'
import getMasterSeed from './wallet/getters/getMasterSeed'
import getMeta from './wallet/getters/getMeta'
import getMnemonic from './wallet/getters/getMnemonic'
import getWallet from './wallet/getters/getWallet'
......@@ -74,6 +75,7 @@ const getters = {
getHDNode,
getHistory,
getMasterSeed,
getMeta,
getMnemonic,
getWallet,
}
......
......@@ -57,6 +57,8 @@ const initWallet = ({ commit }) => {
/* Build metadata. */
const meta = {
label: 'My Causes Wallet',
addresses: {},
coins: {},
createdAt: moment().unix(),
}
......
/**
* Update Metadata
*
* Metadata is used to store details about addresses.
*
* {
* "addresses": [{
* <address>: {
* "label": <string>,
* "comment": <string>,
* "lock": {
* "isActive": <boolean>,
* "label": <string>,
* "comment": <string>,
* "campaignid": <string>,
* "createdAt": <datetime>,
* "expiresAt": <datetime>
* }
* }
* }],
* }
*
* Metadata is used to store details about coins.
*
* {
* "coins": [{
* <coinid>: {
* "label": <string>,
* "comment": <string>,
* "cashfusion": {
* "isActive": <boolean>,
* "label": <string>,
* "comment": <string>,
* "rounds": <integer>,
* "createdAt": <datetime>,
* "updatedAt": <datetime>
* },
* "cashshuffle": {
* "isActive": <boolean>,
* "label": <string>,
* "comment": <string>,
* "rounds": <integer>,
* "createdAt": <datetime>,
* "updatedAt": <datetime>
* },
* "lock": {
* "isActive": <boolean>,
* "label": <string>,
* "comment": <string>,
* "campaignid": <string>,
* "createdAt": <datetime>,
* "expiresAt": <datetime>
* }
* }
* }]
* }
*/
const updateMeta = ({ commit }, _meta) => {
/* Commit metadata. */
......
......@@ -134,6 +134,7 @@
import { mapActions, mapGetters } from 'vuex'
/* Import modules. */
import moment from 'moment'
import Nito from 'nitojs'
/* Import components. */
......@@ -161,6 +162,8 @@ export default {
pledgeDetails: null,
pledgeAuth: null,
campaignAddress: null,
campaignValue: null,
}
},
computed: {
......@@ -169,6 +172,7 @@ export default {
'getBalance',
'getDerivationPath',
'getHDNode',
'getMeta',
'getWallet',
]),
......@@ -206,6 +210,7 @@ export default {
methods: {
...mapActions('wallet', [
'updateCoins',
'updateMeta',
]),
/**
......@@ -254,19 +259,19 @@ export default {
let value = null
/* Set campaign value. */
const campaignValue = this.userPledge.outputs[0].value
console.log('Campaign value:', campaignValue)
this.campaignValue = this.userPledge.outputs[0].value
console.log('Campaign value:', this.campaignValue)
/* Set value. */
value = Nito.Utils.encodeNumber(campaignValue)
value = Nito.Utils.encodeNumber(this.campaignValue)
console.log('Encoded value:', value)
/* Set campaign address. */
const campaignAddress = this.userPledge.outputs[0].address
console.log('Campaign address:', campaignAddress)
this.campaignAddress = this.userPledge.outputs[0].address
console.log('Campaign address:', this.campaignAddress)
/* Set locking script. */
const locking_script = Nito.Address.toPubKeyHash(campaignAddress)
const locking_script = Nito.Address.toPubKeyHash(this.campaignAddress)
console.log('Campaign (locking_script):', locking_script)
/* Set current output. */
......@@ -375,14 +380,27 @@ export default {
satoshis: _satoshis,
}
]
console.log('RECEIVERS', receivers)
const campaignValue = this.userPledge.outputs[0].value
console.log('CAMPAIGN VALUE', campaignValue);
/* Set change address. */
const changeAddress = this.getAddress('change')
console.log('CHANGE ADDRESS', changeAddress)
/* Set auto fee (flag). */
const autoFee = false
// const autoFee = false
const results = await Nito.Transaction
.sendCoin(_coin, receivers, autoFee)
.catch(err => console.error(err))
console.log('OUTBOX SEND COIN (results):', results)
const results = false
// const results = await Nito.Transaction
// .sendCoin(_coin, receivers, autoFee)
// .catch(err => console.error(err))
// console.log('OUTBOX SEND COIN (results):', results)
if (results) {
/* Set message. */
......@@ -434,7 +452,11 @@ export default {
async confirmFlipstarter() {
/* Initialize wallet. */
const wallet = this.getWallet
console.log('WALLET', wallet)
// console.log('WALLET', wallet)
/* Initialize meta. */
const meta = this.getMeta
console.log('META', meta)
/* Set accounts. */
const accounts = wallet.accounts
......@@ -482,19 +504,8 @@ export default {
if (!isPledged) {
console.error('MAKE THE DEPOSIT')
/* Initialize current (coin) index. */
const currentIndex = accounts['causes']
console.log('FLIPSTARTER (currentIndex):', currentIndex)
/* Set (Causes Cash) chain. */
const chain = 6767
/* Set derivation path. */
const path = this.getDerivationPath(chain, currentIndex)
console.log('FLIPSTARTER (path)', path)
/* Set source coin. */
sourceCoin = coins[spendable[1]] // FIXME: Search for minimum sufficient coin(s).
sourceCoin = coins[spendable[0]] // FIXME: Search for minimum sufficient coin(s).
console.log('SOURCE COIN', sourceCoin)
/* Set pledge address. */
......@@ -598,8 +609,42 @@ export default {
/* Update pledge authorization. */
this.pledgeAuth = encodedPledge
/* Initialize meta. */
const meta = this.getMeta
console.log('META', meta)
/* Set coin id. */
const coinid = `${_coin.txid}:${_coin.vout}`
/* Validate coins. */
// NOTE: Added to schema on 2020.7.27
if (!meta.coins) {
meta.coins = {}
}
/* Update meta data. */
meta['coins'][coinid] = {
lock: {
isActive: true,
label: alias,
comment,
campaignAddr: this.campaignAddress,
createdAt: moment().unix(),
}
}
/* Update metadata. */
this.updateMeta(meta)
},
/**
* Cancel Pledge
*/
cancelPledge(_coin) {
console.log('TODO', _coin)
}
},
created: function () {
/* Set owner slug. */
......
......@@ -99,7 +99,25 @@
Pledge Details
</label>
<textarea v-model="pledge" class="pledge-output" id="pledge-details" />
<textarea v-model="pledgeDetails" class="pledge-output" id="pledge-details" />
</div>
<div class="form-group row pledge-group">
<label for="pledge-auth">
Pledge Authorization
</label>
<input
ref="pledgeAuth"
class="form-control"
type="text"
id="pledge-auth"
placeholder="waiting for authorization message..."
v-model="pledgeAuth"
@change="handleAuth"
@keyup="handleAuth"
@paste="handleAuth"
/>
</div>
</form>
</div>
......@@ -155,6 +173,7 @@ export default {
pledgeComment: null,
pledgeRange: null,
pledgeGoal: null,
pledgeAuth: null,
}
},
computed: {
......@@ -171,7 +190,7 @@ export default {
return this.getAddress('deposit')
},
pledge() {
pledgeDetails() {
/* Build (pledge) package. */
const pkg = {
outputs: [
......@@ -232,7 +251,7 @@ export default {
},
methods: {
...mapActions('campaigns', [
'addCampaign',
'addAssurance',
]),
_setPledgeUSD(_satoshis) {
......@@ -278,6 +297,41 @@ export default {
/* Update pledge display. */
this._setPledgeUSD(satoshis)
},
handleAuth() {
/* Wait a tick. */
setTimeout(() => {
/* Initialize pledge authorization. */
let pledgeAuth = null
try {
/* Decode base-64. */
pledgeAuth = Buffer.from(this.pledgeAuth, 'base64')
// console.log('PLEDGE AUTH (buffer)', pledgeAuth.toString())
/* Parse JSON. */
pledgeAuth = JSON.parse(pledgeAuth)
/* Add campaign id. */
pledgeAuth.campaignid = this.campaign.id
console.log('PLEDGE AUTH', pledgeAuth)
this.addAssurance(pledgeAuth)
} catch (err) {
console.error(err)
}
// const previousTransactionHash = null
// const previousTransactionIndex = null
// const unlockScript = null
// const sequenceNumber = null
// const satoshis = null
// const alias = null
// const comment = null
// const createdAt = null
}, 10)
},
},
created: async function () {
this.usd = await Nito.Markets.getTicker('BCH', 'USD')
......
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