Пример #1
0
// This just creates a new row in the accounts_deposits table.
// It doesn't actually credit the account, etc.
// Must be idempotent.
func LoadOrCreateDepositForPayment(payment *bitcoin.Payment) *Deposit {

	if payment.Id == 0 {
		panic(NewError("Cannot add deposit for unsaved payment"))
	}

	addr := bitcoin.LoadAddress(payment.Address)
	if addr == nil {
		panic(NewError("Expected address for payment to deposit"))
	}

	deposit := &Deposit{
		Type:      DEPOSIT_TYPE_CRYPTO,
		UserId:    addr.UserId,
		Wallet:    addr.Wallet,
		Coin:      addr.Coin,
		Amount:    payment.Amount,
		PaymentId: payment.Id,
		Status:    DEPOSIT_STATUS_PENDING,
	}
	_, err := SaveDeposit(db.GetModelDB(), deposit)
	switch db.GetErrorType(err) {
	case db.ERR_DUPLICATE_ENTRY:
		return LoadDepositForPayment(db.GetModelDB(), payment.Id)
	default:
		if err != nil {
			panic(err)
		}
	}

	return deposit
}
Пример #2
0
func collectPrivateKeys(coin string, payments []*bitcoin.Payment, privKeys map[string]string) {
	for _, payment := range payments {
		if privKeys[payment.Address] != "" {
			continue
		} else {
			addr := bitcoin.LoadAddress(payment.Address)
			privKey := ComputePrivateKeyForAddress(addr)
			privKeyWIF := bitcoin.ComputeWIF(coin, privKey, true)
			privKeys[payment.Address] = privKeyWIF
			continue
		}
	}
}