mirror of
https://github.com/fullstack-cash/fullstack-gatsby-theme-bch-wallet.git
synced 2026-09-21 16:52:06 -07:00
Leaving notes on the issues for daniel to look at
This commit is contained in:
@@ -8,6 +8,9 @@ import { getWalletInfo } from '../localWallet'
|
||||
// Get the IPFS hash from the BCH Blockchain.
|
||||
import MemoGet from 'memo-get-gatsby'
|
||||
|
||||
// Get the IPFS hash from the BCH Blockchain.
|
||||
import Memo from '../../services/memo-hash'
|
||||
|
||||
let _this
|
||||
|
||||
class Footer extends React.Component {
|
||||
@@ -19,6 +22,10 @@ class Footer extends React.Component {
|
||||
ipfsHash: 'No Result',
|
||||
ipfsHashLink: ''
|
||||
}
|
||||
|
||||
this.memoAddr = 'bitcoincash:qr7u857krgsvq0dwe8rzlt5rcx35r6hnmu6glavtx0'
|
||||
this.memo = new Memo({ bchAddr: this.memoAddr })
|
||||
|
||||
// memo-get-gatsby Instance
|
||||
this.memoGet = _this.instantiateMemoLib()
|
||||
}
|
||||
|
||||
@@ -41,6 +41,9 @@ export default function HTML (props) {
|
||||
{/* minimal-slp-wallet */}
|
||||
<script src='https://unpkg.com/minimal-slp-wallet' />
|
||||
|
||||
{/* bch-message-lib */}
|
||||
<script src='https://unpkg.com/bch-message-lib' />
|
||||
|
||||
{props.headComponents}
|
||||
</head>
|
||||
<body {...props.bodyAttributes}>
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
This service file contains functions for retrieving an IPFS hash from the
|
||||
BCH blockchain, in a fasion similar to PS001:
|
||||
https://github.com/Permissionless-Software-Foundation/specifications/blob/master/ps001-media-sharing.md
|
||||
*/
|
||||
|
||||
// These libraries are retrieved in /src/html.js
|
||||
// minimal-slp-wallet-web
|
||||
const BchWallet = typeof window !== 'undefined' ? window.SlpWallet : null
|
||||
// bch-message-lib
|
||||
// const BchMessage = typeof window !== 'undefined' ? window.BchMessage : null
|
||||
|
||||
class Memo {
|
||||
constructor (config) {
|
||||
// Throw an error if this class is instantiated without passing a BCH address.
|
||||
if (!config || !config.bchAddr) {
|
||||
throw new Error('Must pass a BCH address to Memo constructor.')
|
||||
} else this.bchAddr = config.bchAddr
|
||||
|
||||
if (BchWallet) {
|
||||
// Note: Uncommenting the line below will throw an error. I think it's
|
||||
// a collision in the name space?
|
||||
// this.wallet = new BchWallet()
|
||||
|
||||
// this.bchjs = this.wallet.bchjs
|
||||
} else {
|
||||
console.error('Could not access minimal-slp-wallet library.')
|
||||
}
|
||||
|
||||
// if (BchMessage) {
|
||||
// this.bchMessage = new BchMessage({ bchjs: this.bchjs })
|
||||
// } else {
|
||||
// console.error('Could not access bch-message-lib library.')
|
||||
// }
|
||||
}
|
||||
|
||||
// Walk the transactions associated with an address until a proper IPFS hash is
|
||||
// found. If one is not found, will return false.
|
||||
async findHash () {
|
||||
try {
|
||||
console.log(`finding latest IPFS hash for address: ${this.bchAddr}...`)
|
||||
|
||||
const txs = await this.bchMessage.memo.memoRead(
|
||||
this.bchAddr,
|
||||
'IPFS UPDATE'
|
||||
)
|
||||
// console.log(`txs: ${JSON.stringify(txs, null, 2)}`)
|
||||
|
||||
// If the array is empty, then return false.
|
||||
if (txs.length === 0) return false
|
||||
|
||||
const hash = txs[0].subject
|
||||
|
||||
console.log(`...found this IPFS hash: ${hash}`)
|
||||
|
||||
// The transactions should automatically be sorted by the bchMessage
|
||||
// library. So Just return the subject.
|
||||
return hash
|
||||
} catch (err) {
|
||||
console.warn('Could not find IPFS hash in transaction history.')
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Memo
|
||||
Reference in New Issue
Block a user