mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-01-19 05:45:15 +01:00
FIX: fallback pushtx endpoints; closes #18
This commit is contained in:
parent
bfa6eb61c3
commit
b76ff9f848
@ -260,6 +260,23 @@ export class LegacyWallet extends AbstractWallet {
|
||||
}
|
||||
|
||||
async broadcastTx(txhex) {
|
||||
let chainso = await this._broadcastTxChainso(txhex);
|
||||
if (chainso && chainso.status) {
|
||||
if (chainso.status === 'fail') {
|
||||
return this._broadcastTxBlockcypher(txhex); // fallback
|
||||
} else {
|
||||
// success
|
||||
return {
|
||||
result: chainso.data.txid,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
// another fallback
|
||||
return this._broadcastTxBlockcypher(txhex);
|
||||
}
|
||||
}
|
||||
|
||||
async _broadcastTxBtczen(txhex) {
|
||||
const api = new Frisbee({
|
||||
baseURI: 'https://btczen.com',
|
||||
headers: {
|
||||
@ -273,6 +290,36 @@ export class LegacyWallet extends AbstractWallet {
|
||||
return res.body;
|
||||
}
|
||||
|
||||
async _broadcastTxChainso(txhex) {
|
||||
const api = new Frisbee({
|
||||
baseURI: 'https://chain.so',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
let res = await api.post('/api/v2/send_tx/BTC', {
|
||||
body: { tx_hex: txhex },
|
||||
});
|
||||
console.log('response', res.body);
|
||||
return res.body;
|
||||
}
|
||||
|
||||
async _broadcastTxBlockcypher(txhex) {
|
||||
const api = new Frisbee({
|
||||
baseURI: 'https://api.blockcypher.com',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
let res = await api.post('/v1/btc/main/txs/push', { body: { tx: txhex } });
|
||||
console.log('response', res.body);
|
||||
return res.body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes UTXOs (as presented by blockcypher api), transforms them into
|
||||
* format expected by signer module, creates tx and returns signed string txhex.
|
||||
|
@ -212,7 +212,7 @@ export default class SendCreate extends Component {
|
||||
<FormValidationMessage>
|
||||
{this.state.broadcastErrorMessage}
|
||||
</FormValidationMessage>
|
||||
<Text style={{ padding: 20, color: '#090' }}>
|
||||
<Text style={{ padding: 0, color: '#0f0' }}>
|
||||
{this.state.broadcastSuccessMessage}
|
||||
</Text>
|
||||
</SafeBlueArea>
|
||||
|
Loading…
Reference in New Issue
Block a user