소스 검색

modify by hyb for pubkey child index count

hyb 6 년 전
부모
커밋
0a2fb26466
3개의 변경된 파일32개의 추가작업 그리고 2개의 파일을 삭제
  1. 3 1
      src/bitcoin/bitcoin.toml
  2. 7 0
      src/bitcoin/bitcoinconfig.go
  3. 22 1
      src/bitcoin/bitcoinmain.go

+ 3 - 1
src/bitcoin/bitcoin.toml

@@ -19,5 +19,7 @@ dbPath="/var/"
 [pubkey]
 pubkeystr="xpub661MyMwAqRbcFaUozqMe8B97RKVrbqt8FQLr4kjd2LYmyNDd3fBJyeNRL118yz4YbTmpsC7TjLG1Wgu9y1pUauQDyB98PbHgJTV3z8VSaTY"
 
-
+[count]
+startcount=50
+endcount=300
 

+ 7 - 0
src/bitcoin/bitcoinconfig.go

@@ -14,6 +14,7 @@ type config struct {
 	Rpc        rpc        `toml:"rpc"`
 	Db         databaseinfo `toml:"db"`
 	Pubkey     pubkeyinfo   `toml:"pubkey"`
+	Count      count        `toml:"count"`
 }
 type limit struct {
 	Fee string
@@ -37,6 +38,12 @@ type pubkeyinfo struct {
 	Pubkeystr string
 }
 
+type count struct {
+	Startcount uint32
+	Endcount   uint32
+}
+
+
 func LOG(info string, format string, v ...interface{}) {
 
 	_, file, line, _ := runtime.Caller(1)

+ 22 - 1
src/bitcoin/bitcoinmain.go

@@ -31,6 +31,10 @@ const BACKUPPUBKEYINDEX = "backuppubkeyindex"
 // PubKey
 var PubKey string = ""
 
+//bitcoin PubKey Child  index
+var StartCount uint32 = 0
+var EndCount uint32 = 0
+
 
 func (m BitCoin) InitDriver(parm interface{}) bool {
 	if m.initconfig() == false {
@@ -244,13 +248,26 @@ func (m BitCoin) CreateAddressFromHdWallet() ([]byte, error) {
 	if len(string(backuppubkeyindex)) == 0 {
 		backupindex = 0
 	} else {
-		fmt.Println("litedb.Get BACKUPPUBKEYINDEX:", string(backuppubkeyindex))
 
 		if err := json.Unmarshal([]byte(backuppubkeyindex), &backupindex); err != nil {
 			fmt.Println("Unmarshal err :", err.Error())
 			return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, INNER_ERR, getErrMsg(INNER_ERR, nil))
 		}
 	}
+
+	LOG("DEBUG", "litedb.Get BACKUPPUBKEYINDEX:%v", backupindex)
+
+	//check pubkey child start index
+	if backupindex < StartCount {
+		LOG("ERROR", " backupindex:%v <  StartCount:%v!", backupindex, StartCount)
+		backupindex = StartCount
+	}
+	//check pubkey child end index
+	if EndCount != 0 && backupindex > EndCount {
+		LOG("ERROR", " backupindex:%v >  EndCount:%v!", backupindex, EndCount)
+		return nil, fmt.Errorf(`{"errcode":%v,"mesage":"%s"}`, INNER_ERR, getErrMsg(INNER_ERR, nil))
+	}
+
 	index := backupindex + 1
 
 	pubkey := btc.StringChild(PubKey, index)
@@ -368,6 +385,10 @@ func (m BitCoin) initconfig() bool {
 	PubKey = Config.Pubkey.Pubkeystr
 	LOG("DEBUG", "PubKey:%v", PubKey)
 
+	StartCount = Config.Count.Startcount
+	EndCount = Config.Count.Endcount
+	LOG("DEBUG", "StartCount:%v,EndCount%v", StartCount, EndCount)
+
 	f, err := strconv.ParseFloat(Config.Limit.Fee, 64)
 	if err != nil {
 		LOG("ERROR", "inner json error:%v", err.Error())