func (db *DB) GetDepositAddressMap(coinType *coinparam.Params) (depositAddresses map[string]*koblitz.PublicKey, err error) {

	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		return
	}
	// this defer is pushed onto the stack first
	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while getting deposit addr map: \n%s", err)
			return
		}
		err = tx.Commit()
		return
	}()

	// Use the deposit schema
	if _, err = tx.Exec("USE " + db.depositSchema + ";"); err != nil {
		err = fmt.Errorf("Could not use deposit address schema: \n%s", err)
		return
	}

	var assetString string
	if assetString, err = util.GetSchemaNameFromParam(coinType); err != nil {
		err = fmt.Errorf("Tried to get deposit addresses for %s which isn't a valid asset", assetString)
		return
	}

	var getBalanceStmt *sql.Stmt
	if getBalanceStmt, err = tx.Prepare(fmt.Sprintf("SELECT pubkey, address FROM %s;", assetString)); err != nil {
		return
	}

	// defer stmt.close so it still is executed but doesn't interfere with closing other stuff if it errors out
	// this defer is pushed onto the defer stack second, so we close out the statement, then close out the tx.
	defer func() {
		if err != nil {
			if newErr := getBalanceStmt.Close(); newErr != nil {
				err = fmt.Errorf("Error with closing getbalancestmt: \n%s\nAdditional errors: \n%s", newErr, err)
			}
		} else {
			if newErr := getBalanceStmt.Close(); newErr != nil {
				err = fmt.Errorf("Error with closing getbalancestmt: \n%s", newErr)
			}
		}
	}()

	var rows *sql.Rows
	if rows, err = getBalanceStmt.Query(); err != nil {
		err = fmt.Errorf("Error when getting deposit address: \n%s", err)
		return
	}

	depositAddresses = make(map[string]*koblitz.PublicKey)

	for rows.Next() {
		var depositAddr string
		var pubkeyBytes []byte
		if err = rows.Scan(&pubkeyBytes, &depositAddr); err != nil {
			err = fmt.Errorf("Error scanning for depositAddrowss: \n%s", err)
			return
		}

		// so rows.Scan does something weird because I'm not using prepared statements. I would prefer to be using a byte array to scan into, since the pubkey is a varbinary?
		if pubkeyBytes, err = hex.DecodeString(string(pubkeyBytes)); err != nil {
			return
		}

		var pubkey *koblitz.PublicKey
		if pubkey, err = koblitz.ParsePubKey(pubkeyBytes, koblitz.S256()); err != nil {
			err = fmt.Errorf("Error parsing pubkey %x for curve S256: \n%s", pubkeyBytes, err)
			return
		}

		depositAddresses[depositAddr] = pubkey
	}

	if err = rows.Close(); err != nil {
		err = fmt.Errorf("Error closing deposit rows: \n%s", err)
		return
	}

	return
}
// GetDepositAddressMap returns a map from deposit addresses to pubkeys, essentially a set and only to get O(1) access time.
GetDepositAddressMap returns a map from deposit addresses to pubkeys, essentially a set and only to get O(1) access time.
// GetDepositAddressMap returns a map from deposit addresses to pubkeys essentially a set and only to get O ( 1 ) access time .
func (db *DB) GetDepositAddressMap(coinType *coinparam.Params) (depositAddresses map[string]*koblitz.PublicKey, err error) {
	var tx *sql.Tx
	if tx, err = db.DBHandler.Begin(); err != nil {
		return
	}
	defer func() {
		if err != nil {
			tx.Rollback()
			err = fmt.Errorf("Error while getting deposit addr map: \n%s", err)
			return
		}
		err = tx.Commit()
		return
	}()
	if _, err = tx.Exec("USE " + db.depositSchema + ";"); err != nil {
		err = fmt.Errorf("Could not use deposit address schema: \n%s", err)
		return
	}
	var assetString string
	if assetString, err = util.GetSchemaNameFromParam(coinType); err != nil {
		err = fmt.Errorf("Tried to get deposit addresses for %s which isn't a valid asset", assetString)
		return
	}
	var getBalanceStmt *sql.Stmt
	if getBalanceStmt, err = tx.Prepare(fmt.Sprintf("SELECT pubkey, address FROM %s;", assetString)); err != nil {
		return
	}
	defer func() {
		if err != nil {
			if newErr := getBalanceStmt.Close(); newErr != nil {
				err = fmt.Errorf("Error with closing getbalancestmt: \n%s\nAdditional errors: \n%s", newErr, err)
			}
		} else {
			if newErr := getBalanceStmt.Close(); newErr != nil {
				err = fmt.Errorf("Error with closing getbalancestmt: \n%s", newErr)
			}
		}
	}()
	var rows *sql.Rows
	if rows, err = getBalanceStmt.Query(); err != nil {
		err = fmt.Errorf("Error when getting deposit address: \n%s", err)
		return
	}
	depositAddresses = make(map[string]*koblitz.PublicKey)
	for rows.Next() {
		var depositAddr string
		var pubkeyBytes []byte
		if err = rows.Scan(&pubkeyBytes, &depositAddr); err != nil {
			err = fmt.Errorf("Error scanning for depositAddrowss: \n%s", err)
			return
		}
		if pubkeyBytes, err = hex.DecodeString(string(pubkeyBytes)); err != nil {
			return
		}
		var pubkey *koblitz.PublicKey
		if pubkey, err = koblitz.ParsePubKey(pubkeyBytes, koblitz.S256()); err != nil {
			err = fmt.Errorf("Error parsing pubkey %x for curve S256: \n%s", pubkeyBytes, err)
			return
		}
		depositAddresses[depositAddr] = pubkey
	}
	if err = rows.Close(); err != nil {
		err = fmt.Errorf("Error closing deposit rows: \n%s", err)
		return
	}
	return
}
func ( db * DB ) GetDepositAddressMap ( coinType * coinparam . Params ) ( depositAddresses map [ string ] * koblitz . PublicKey , err error ) { var tx * sql . Tx if tx , err = db . DBHandler . Begin ( ) ; err != nil { return } defer func ( ) { if err != nil { tx . Rollback ( ) err = fmt . Errorf ( " \n " , err ) return } err = tx . Commit ( ) return } ( ) if _ , err = tx . Exec ( " " + db . depositSchema + " " ) ; err != nil { err = fmt . Errorf ( " \n " , err ) return } var assetString string if assetString , err = util . GetSchemaNameFromParam ( coinType ) ; err != nil { err = fmt . Errorf ( " " , assetString ) return } var getBalanceStmt * sql . Stmt if getBalanceStmt , err = tx . Prepare ( fmt . Sprintf ( " " , assetString ) ) ; err != nil { return } defer func ( ) { if err != nil { if newErr := getBalanceStmt . Close ( ) ; newErr != nil { err = fmt . Errorf ( " \n \n \n " , newErr , err ) } } else { if newErr := getBalanceStmt . Close ( ) ; newErr != nil { err = fmt . Errorf ( " \n " , newErr ) } } } ( ) var rows * sql . Rows if rows , err = getBalanceStmt . Query ( ) ; err != nil { err = fmt . Errorf ( " \n " , err ) return } depositAddresses = make ( map [ string ] * koblitz . PublicKey ) for rows . Next ( ) { var depositAddr string var pubkeyBytes [ ] byte if err = rows . Scan ( & pubkeyBytes , & depositAddr ) ; err != nil { err = fmt . Errorf ( " \n " , err ) return } if pubkeyBytes , err = hex . DecodeString ( string ( pubkeyBytes ) ) ; err != nil { return } var pubkey * koblitz . PublicKey if pubkey , err = koblitz . ParsePubKey ( pubkeyBytes , koblitz . S256 ( ) ) ; err != nil { err = fmt . Errorf ( " \n " , pubkeyBytes , err ) return } depositAddresses [ depositAddr ] = pubkey } if err = rows . Close ( ) ; err != nil { err = fmt . Errorf ( " \n " , err ) return } return }
GetDepositAddressMap returns a map from deposit addresses to pubkeys, essentially a set and only to get O(1) access time.
GetDepositAddressMap returns a map from deposit addresses to pubkeys essentially a set and only to get O ( 1 ) access time .
// this defer is pushed onto the stack first // Use the deposit schema // defer stmt.close so it still is executed but doesn't interfere with closing other stuff if it errors out // this defer is pushed onto the defer stack second, so we close out the statement, then close out the tx. // so rows.Scan does something weird because I'm not using prepared statements. I would prefer to be using a byte array to scan into, since the pubkey is a varbinary?