Workflow updating files of btcwallet

This commit is contained in:
RanchiMall Dev 2024-01-04 18:51:51 +00:00
parent a859755e67
commit 490c9b9f4e
5 changed files with 78 additions and 59 deletions

View File

@ -121,7 +121,7 @@
<div id="tx_details" class="grid gap-2"></div>
</section>
</div>
<div id="send" class="page hidden" data-sm-containment>
<div id="send" class="page hidden">
<sm-form id="send_tx" skip-submit>
<div class="margin-bottom-0-5">
<div class="flex align-center space-between margin-bottom-0-5">
@ -1128,12 +1128,20 @@
},
{
selector: '[data-private-key]',
customValidation: (value) => {
customValidation: (value, inputElem) => {
if (!value) return { isValid: false, errorText: 'Please enter a private key' }
return {
isValid: floCrypto.getPubKeyHex(value),
errorText: `Invalid private key.<br> It usually starts with "L" or "R"`
}
if (floCrypto.getPubKeyHex(value)) {
const forAddress = inputElem.dataset.forAddress
if (!forAddress) return { isValid: true }
return {
isValid: btcOperator.verifyKey(forAddress, value),
errorText: `This private key does not match the address ${forAddress}`
}
} else
return {
isValid: false,
errorText: `Invalid private key. Please check and try again.`
}
}
},
{
@ -2070,7 +2078,7 @@
<div class="label">Address</div>
<b class="sender__address wrap-around">${address}</b>
</div>
<sm-input class="sender__private-key password-field" type="password" placeholder="Private Key" animate required>
<sm-input class="sender__private-key password-field" type="password" placeholder="Private Key" data-for-address=${address} data-private-key animate required>
<svg class="icon" slot="icon" xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="#000000"> <g> <rect fill="none" height="24" width="24"></rect> </g> <g> <path d="M21,10h-8.35C11.83,7.67,9.61,6,7,6c-3.31,0-6,2.69-6,6s2.69,6,6,6c2.61,0,4.83-1.67,5.65-4H13l2,2l2-2l2,2l4-4.04L21,10z M7,15c-1.65,0-3-1.35-3-3c0-1.65,1.35-3,3-3s3,1.35,3,3C10,13.65,8.65,15,7,15z"></path> </g> </svg>
<label slot="right" class="interact">
<input type="checkbox" class="hidden" autocomplete="off" readonly="" onchange="togglePrivateKeyVisibility(this)">
@ -2148,8 +2156,7 @@
changingFeeOf = null
})
} catch (err) {
console.log(typeof e)
notify(e, 'error')
notify(err, 'error')
buttonLoader(document.getElementById('increase_fee'), false)
}
}

View File

@ -1,4 +1,4 @@
(function (EXPORTS) { //btcOperator v1.2.5
(function (EXPORTS) { //btcOperator v1.2.6
/* BTC Crypto and API Operator */
const btcOperator = EXPORTS;
const SATOSHI_IN_BTC = 1e8;
@ -18,6 +18,25 @@
let isTor = false;
checkIfTor().then(result => isTor = result);
async function post(url, data, { asText = false } = {}) {
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
if (response.ok) {
return asText ? await response.text() : await response.json()
} else {
throw response
}
} catch (e) {
throw e
}
}
// NOTE: some APIs may not support all functions properly hence they are omitted
const APIs = btcOperator.APIs = [
{
@ -35,15 +54,13 @@
console.log(e)
}
},
broadcast({ rawTxHex, url }) {
return fetch(`${this.url}txs/push`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ tx: rawTxHex })
}).then(response => response.json())
.then(result => result.hash)
async broadcast({ rawTxHex, url }) {
try {
const result = await post(`${url || this.url}txs/push`, { tx: rawTxHex })
return result.hash
} catch (e) {
throw e
}
}
},
{
@ -77,17 +94,11 @@
const block = await fetch_api(`block/${blockHash}`, { url: url || this.url })
return formatBlock(block)
} catch (e) {
console.error(e)
throw e
}
},
broadcast({ rawTxHex, url }) {
return fetch(`${url || this.url}tx`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ tx: rawTxHex })
}).then(response => response.text())
async broadcast({ rawTxHex, url }) {
return post(`${url || this.url}tx`, { tx: rawTxHex }, { asText: true })
}
},
{
@ -97,17 +108,17 @@
return fetch_api(`address/${addr}`, { url: this.url })
.then(result => util.Sat_to_BTC(result.chain_stats.funded_txo_sum - result.chain_stats.spent_txo_sum))
},
tx({ txid }) {
return fetch_api(`tx/${txid}`, { url: this.url })
.then(result => formatTx(result))
// tx({ txid }) {
// return fetch_api(`tx/${txid}`, { url: this.url })
// .then(result => formatTx(result))
},
txHex({ txid }) {
return fetch_api(`tx/${txid}/hex`, { url: this.url, asText: true })
},
txs({ addr, before, after }) {
return fetch_api(`address/${addr}/txs${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url })
},
// },
// txHex({ txid }) {
// return fetch_api(`tx/${txid}/hex`, { url: this.url, asText: true })
// },
// txs({ addr, before, after }) {
// return fetch_api(`address/${addr}/txs${before ? `?before=${before}` : ''}${after ? `?after=${after}` : ''}`, { url: this.url })
// },
async block({ id }) {
// if id is hex string then it is block hash
try {
@ -117,17 +128,11 @@
const block = await fetch_api(`block/${blockHash}`, { url: this.url })
return formatBlock(block)
} catch (e) {
console.error(e)
throw e
}
},
broadcast({ rawTxHex, url }) {
return fetch(`${this.url}tx`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ tx: rawTxHex })
}).then(response => response.text())
async broadcast({ rawTxHex, url }) {
return post(`${url || this.url}tx`, { tx: rawTxHex }, { asText: true })
}
},
{
@ -164,7 +169,7 @@
}
return formatBlock(block)
} catch (e) {
console.error(e)
throw e
}
},
async blockTxs({ id }) {
@ -179,7 +184,7 @@
}
return block.tx
} catch (e) {
console.error(e)
}
}
}
@ -202,7 +207,7 @@
details.next_block = next_block[0]
return details
} catch (e) {
console.error(e)
throw e
}
}
const formatUtxos = btcOperator.util.format.utxos = async (utxos, allowUnconfirmedUtxos = false) => {
@ -261,7 +266,7 @@
})
}
} catch (e) {
console.error(e)
throw e
}
}
@ -288,12 +293,12 @@
}
throw "No API available"
} catch (error) {
if (error.code && error.code === 1000) {
throw error.message;
} else {
console.debug(error);
console.error(error)
if (error.code && [429, 404].includes(error.code)) {
APIs[index].coolDownTime = new Date().getTime() + 1000 * 60 * 10; // 10 minutes
return multiApi(fnName, { index: index + 1, ...args });
} else {
throw error.message || error;
}
}
};
@ -392,6 +397,13 @@
const broadcastTx = btcOperator.broadcastTx = rawTxHex => new Promise((resolve, reject) => {
console.log('txHex:', rawTxHex)
// return multiApi('broadcast', { rawTxHex })
// .then(result => {
// resolve(result)
// })
// .catch(error => {
// reject(error)
// })
let url = 'https://coinb.in/api/?uid=1&key=12345678901234567890123456789012&setmodule=bitcoin&request=sendrawtransaction';
fetch(url, {
method: 'POST',
@ -400,7 +412,7 @@
},
body: "rawtx=" + rawTxHex
}).then(response => {
// multiApi('broadcast', { rawTxHex }).then(response => {
console.log(response)
response.text().then(resultText => {
let r = resultText.match(/<result>.*<\/result>/);
if (!r)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long