github.com/condensat/bank-core@v0.1.0/database/model/cryptoaddress.go (about) 1 // Copyright 2020 Condensat Tech. All rights reserved. 2 // Use of this source code is governed by a MIT 3 // license that can be found in the LICENSE file. 4 5 package model 6 7 import "time" 8 9 type CryptoAddressID ID 10 type BlockID ID 11 12 const MemPoolBlockID = BlockID(1) 13 14 type CryptoAddress struct { 15 ID CryptoAddressID `gorm:"primary_key"` // [PK] CryptoAddress 16 AccountID AccountID `gorm:"index;not null"` // [FK] Reference to Account table 17 PublicAddress String `gorm:"unique_index;not null;size:128"` // CryptoAddress public key, non mutable 18 Unconfidential String `gorm:"index;size:64"` // CryptoAddress unconfidential address, non mutable` 19 Chain String `gorm:"index;not null;size:16"` // CryptoAddress chain, non mutable 20 CreationDate *time.Time `gorm:"index;not null"` // CryptoAddress creation date, non mutable 21 FirstBlockId BlockID `gorm:"index;not null"` // Block height of the first transaction 22 IgnoreAccounting bool `gorm:"not null"` // This address is not for Accounting (change address) 23 } 24 25 func (p *CryptoAddress) IsUsed() bool { 26 return p.FirstBlockId > 0 27 } 28 29 func (p *CryptoAddress) Confirmations(height BlockID) int { 30 if !p.IsUsed() { 31 return 0 32 } 33 if p.FirstBlockId <= MemPoolBlockID { 34 return 0 35 } 36 if p.FirstBlockId > height { 37 return 0 38 } 39 return 1 + int(height) - int(p.FirstBlockId) 40 }