Dread 4 years ago
parent
commit
da69f438df
  1. 2
      main.js
  2. 5
      pages/menu/backUp/index.vue
  3. 1
      pages/menu/backUp/transPaw/index.vue
  4. 30
      pages/menu/wallet/index.vue
  5. 29
      utils/BtcUtil.js
  6. 4
      utils/SystemConfiguration.js
  7. 3
      utils/WalletUtil.js

2
main.js

@ -53,11 +53,13 @@ const i18n = new VueI18n({
import TokenUtil from './utils/TokenUtil.js' import TokenUtil from './utils/TokenUtil.js'
import EthUtil from './utils/EthUtil.js' import EthUtil from './utils/EthUtil.js'
import TronUtil from './utils/TronUtil.js' import TronUtil from './utils/TronUtil.js'
import BtcUtil from './utils/BtcUtil.js'
import api from './utils/api.js' import api from './utils/api.js'
import SystemConfiguration from './utils/SystemConfiguration.js' import SystemConfiguration from './utils/SystemConfiguration.js'
Vue.prototype.$Token = TokenUtil Vue.prototype.$Token = TokenUtil
Vue.prototype.$EthUtil = EthUtil Vue.prototype.$EthUtil = EthUtil
Vue.prototype.$BtcUtil = BtcUtil
Vue.prototype.$TronUtil = TronUtil Vue.prototype.$TronUtil = TronUtil
Vue.prototype.$api = api Vue.prototype.$api = api
Vue.prototype.$SystemConfiguration = SystemConfiguration Vue.prototype.$SystemConfiguration = SystemConfiguration

5
pages/menu/backUp/index.vue

@ -103,10 +103,9 @@
} }
}, },
onLoad(item){ onLoad(item){
console.log("item",item)
if(item!=''||item!=undefined){ if(item!=''||item!=undefined){
var word=this.$Token.creatingWallets(); var word2=this.$Token.generateMnemonic();
var word2=word.mnemonic
// , // ,
uni.setStorage({ uni.setStorage({
key: 'word', key: 'word',

1
pages/menu/backUp/transPaw/index.vue

@ -105,6 +105,7 @@
} }
}else{ }else{
this.setWalletInfo(); this.setWalletInfo();
uni.showToast({ uni.showToast({
title: this.$t('index').Setsuccessfully, title: this.$t('index').Setsuccessfully,

30
pages/menu/wallet/index.vue

@ -77,7 +77,7 @@
</view> </view>
</view> </view>
<!-- </view> --> <!-- </view> -->
</scroll-view> </scroll-view>
</view> </view>
@ -104,14 +104,32 @@
showMoney1: true, showMoney1: true,
showMoney2: false, showMoney2: false,
btcBalance: 0, btcBalance: 0,
isStop: false isStop: false,
timer: null
} }
}, },
onUnload: function() { onUnload: function() {
this.isStop = true console.log("停止了")
uni.setStorageSync('isWallet', false); uni.setStorageSync('isWallet', false);
}, if (this.timer) {
console.log("停止了")
clearInterval(this.timer);
this.timer = null;
}
},
onShow() {
this.timer = setInterval(() => {
this.updateBalance();
}, 5000)
},
onHide() {
if (this.timer) {
console.log("停止了")
clearInterval(this.timer);
this.timer = null;
}
},
onLoad() { onLoad() {
let currency = uni.getStorageSync('currency'); let currency = uni.getStorageSync('currency');
@ -140,7 +158,7 @@
}, 500); }, 500);
}, },
methods: { methods: {
async updateBalance(){ async updateBalance() {
this.userObj = await this.$walletUtil.updateBalance(); this.userObj = await this.$walletUtil.updateBalance();
}, },
@ -179,7 +197,7 @@
var _this = this var _this = this
uni.scanCode({ uni.scanCode({
success: function(res) { success: function(res) {
uni.setStorageSync('address',res.result) uni.setStorageSync('address', res.result)
uni.navigateTo({ uni.navigateTo({
url: '/pages/menu/sendToken/transfer/index?item=index' url: '/pages/menu/sendToken/transfer/index?item=index'
}) })

29
utils/BtcUtil.js

@ -1,3 +1,6 @@
import systemConfiguration from 'utils/SystemConfiguration.js'
const bitcoin = require('bitcoinjs-lib')
let BtcUtil = { let BtcUtil = {
getBalance:async function(address,success) { getBalance:async function(address,success) {
let balance=0; let balance=0;
@ -21,6 +24,32 @@ let BtcUtil = {
//TODO handle the exception //TODO handle the exception
} }
return balance; return balance;
},
sendTransaction:async function(fromAddress, toAddress, value, privateKey){
let bob = new bitcoin.ECPair.fromWIF(privateKey);
const txb = new bitcoin.TransactionBuilder(systemConfiguration.constant.btcNetwork);
txb.setVersion(1);
// 在这个交易中, bob在第0个位置,上图所示
txb.addInput("5799a647d6b89a9f73122d75faee6f5a0210bd3cb22c48a70d35eac33ce5d426", 0);
txb.addOutput(toAddress, 2000000);
console.log(txb,1111111111)
// 签名交易,0代表索引,输入排序,这里只有一个输入,所以是第0位。
txb.sign(0, bob);
// 序列化成一串字符
const tx = txb.build().toHex();
console.log(tx);
const result = await fetch('https://api.blockcypher.com/v1/btc/test3/txs/push',{
method:'post',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({tx})
});
// 打印结果
console.log(result);
} }
} }
export default BtcUtil export default BtcUtil

4
utils/SystemConfiguration.js

@ -6,7 +6,7 @@ const constant = isTest ? {
coinTickerWs:'ws://wallet-quartz.weirui0755.com/websocket', coinTickerWs:'ws://wallet-quartz.weirui0755.com/websocket',
ethNode:'http://47.245.25.82:8545', ethNode:'http://47.245.25.82:8545',
ethChainId:1, ethChainId:1,
btcNetwork:'', btcNetwork:'https://api.blockcypher.com',
ethTransctionDetail:'https://cn.etherscan.com/tx/', ethTransctionDetail:'https://cn.etherscan.com/tx/',
trxTransctionDetail:'https://tronscan.io/#/transaction/', trxTransctionDetail:'https://tronscan.io/#/transaction/',
checkIp:'https://app.bilibili.com' checkIp:'https://app.bilibili.com'
@ -16,7 +16,7 @@ const constant = isTest ? {
coinTickerWs:'wss://quartz.bitcooo.com/websocket', coinTickerWs:'wss://quartz.bitcooo.com/websocket',
ethNode:'http://47.245.25.82:8545', ethNode:'http://47.245.25.82:8545',
ethChainId:1, ethChainId:1,
btcNetwork:'', btcNetwork:'https://api.blockcypher.com',
ethTransctionDetail:'https://cn.etherscan.com/tx/', ethTransctionDetail:'https://cn.etherscan.com/tx/',
trxTransctionDetail:'https://tronscan.io/#/transaction/' trxTransctionDetail:'https://tronscan.io/#/transaction/'
} }

3
utils/WalletUtil.js

@ -135,6 +135,9 @@ let WalletUtil = {
wallet.privateKey = walletdec.privateKey; wallet.privateKey = walletdec.privateKey;
wallet.mnemonic = mnemonic; wallet.mnemonic = mnemonic;
wallet.address = walletdec.address; wallet.address = walletdec.address;
wallet.ellipsisAddress = wallet.address.substring(0, 6) + '...' + wallet.address.substring(
wallet.address.length - 6,
wallet.address.length);
console.log(wallet) console.log(wallet)
walletInfo[type].push(wallet); walletInfo[type].push(wallet);
console.log(walletInfo, 1111111) console.log(walletInfo, 1111111)

Loading…
Cancel
Save