Java BTC Omni 同步充值交易

2021-09-05 11:45:11 字數 3448 閱讀 3628

方案:

1.初始化區塊資訊到資料庫

@order(value = 1)

@service

public class btcoinchargeserviceimpl implements commandlinerunner and block hash is :{} start !! ===", blockcount, blockhash);

coinblockinfo blockinfos = new coinblockinfo();

blockinfos.setblockheight(blockcount); //高度

blockinfos.setblockhash(blockhash);//塊hash

blockinfos.setcointype(currenttype);

blockinfos.setcreatetime(new date());

blockinfos.setremark("first record");

if (res)

log.info("=== [btc] init block success !!");

} }}

2.  區塊hash從主鏈獲取交易txs並進行解析

//位元幣充值交易資訊

@service

public class btcoinchargeserviceimpl implements btcoinchargeservice, and the processing block height is {}. ===", blockcount, parseblockcount);

if (blockcount > parseblockcount) \t], [\thash:{}\t] begins !!! ===", current, blockhash);

if (parsetransactioninfo(userlist, blockhash, current)) \t], [\thash:{}\t] !!! ===", current, blockhash);

/* current height */

blockinfo.setblockheight(current);

blockinfo.setblockhash(blockhash);

blockinfo.setupdatetime(new date());

log.info("=== [btc-local] current block height: {}, previous block height: {} ===", current, parseblockcount);

}current++;

} /*else */

} catch (coinexception e) ===", e.getmessage(), e);

throw new coinexception(e.getmessage());}}

}}

} catch (coinexception e) ===", e.getmessage(), e);

throw new coinexception(e.getmessage());

} return result;

} /*

* 對錢包位址進行比對處理

*/ private boolean parsetransactioninfo(listuserlist, string blockhash, int current) throws coinexception

jsonarray txs = jsonarray.parsearray(blocks.getstring("tx"));

log.info("=== [btc] scan block [\theight:{}\t], [\thash:{}\t], [\ttotal transactions:{}\t] begins !!! ===", current, blockhash, txs.size());

for (int i = 0, len = txs.size(); i < len; i++) \t], [\thash:{}\t], [\ttx:{}\t] begins !!! ===", current, blockhash, txid);

parseblockinfobytxid(userlist, txid, current);

// log.info("=== [btc] current blockheight:{},blockhash:{},txhash:{} operation completion!!", current, blockhash, txid);

} return true;

} /**

* 處理塊資訊

* @throws coinexception

* @title: parseblockinfobytxid @param @param userlist @param @param txid @param @throws coinexception 引數 @return void 返回型別 @throws

*/private boolean parseblockinfobytxid(listuserlist, string txid, int height) throws coinexception trawtransaction! ===", txid);

map parenttransaction = (map) btcservice.gettrawtransaction(txid, 1);

jsonobject parentinfo = jsonobject.parseobject(json.tojsonstring(parenttransaction));

jsonarray vouts = jsonarray.parsearray(parentinfo.getstring("vout"));

for (int j = 0, leg = vouts.size(); j < leg; j++) }}

}// vout

jsonarray vouts = jsonarray.parsearray(info.getstring("vout"));

for (int x = 0, lenx = vouts.size(); x < lenx; x++)

try catch (exception e) ===", e.getmessage(), e);}}

}}}}

}} catch (coinexception e) ===", e.getmessage(), e);

throw new coinexception(e.getmessage());

} return false;

} private boolean iserror(jsonobject json)

return false; }

}

通過json-rpc 進行節點的呼叫參考:

python話費充值 手機話費充值

status 0,msg ok result mobile 15158825888 amount 0 list name areaid 30 company 移動 province 浙江 amount 1 adviceprice price 1.10 limitprice sms recharget...

機房收費 充值

機房充值的窗體非常簡單,但是還是有幾個點需要注意 1.乙個加法 充值之後,需要乙個文字框來顯示現在的餘額,那麼需要將現在充值的餘額加上資料庫中的餘額。我定義了乙個變數來存放臨時金額,如下 dim depositmoney as string 存放臨時金額 充值的過程 depositmoney tri...

流量充值專案

作為流量充值的中間商,賺取差價。月流水最高8百萬元。專案一分為二,乙個是接收客戶訂單,乙個是根據客戶訂單下單給 商。我主要負責的是接收客戶訂單部分。校驗請求資料 token 以及簽名 生成 token 根據使用者 id 生成 token 使用 jwt,引數有 user id,timestamp,se...