示例#1
0
func (k *KeysDB) Put(key *b32.Key, scriptPubKey []byte, purpose bitcoin.KeyPurpose) error {
	k.lock.Lock()
	defer k.lock.Unlock()
	tx, _ := k.db.Begin()
	stmt, _ := tx.Prepare("insert into keys(key, scriptPubKey, purpose, used) values(?,?,?,?)")
	defer stmt.Close()
	_, err := stmt.Exec(key.String(), hex.EncodeToString(scriptPubKey), int(purpose), 0)
	if err != nil {
		tx.Rollback()
		return err
	}
	tx.Commit()
	return nil
}
示例#2
0
func (k *KeysDB) MarkKeyAsUsed(key *b32.Key) error {
	k.lock.Lock()
	defer k.lock.Unlock()
	tx, err := k.db.Begin()
	if err != nil {
		return err
	}
	stmt, err := tx.Prepare("update keys set used=1 where key=?")
	if err != nil {
		return err
	}
	defer stmt.Close()
	_, err = stmt.Exec(key.String())
	if err != nil {
		tx.Rollback()
		return err
	}
	tx.Commit()
	return nil
}