Documentation ¶
Index ¶
- Constants
- func LoadWallets(fixturesPath string) (wallets []Wallet, accounts []Account, err error)
- func MigrateDB(gdb *gorm.DB) (err error)
- func OpenDB(conf *config.Config) (db *gorm.DB, err error)
- func ResetDB(gdb *gorm.DB, fixturesPath string) (err error)
- type Account
- func (a Account) BalanceFloat() float32
- func (a Account) GetVASP(d *DB) (vasp *VASP, err error)
- func (a Account) GetWallet(db *DB) (wallet *Wallet, err error)
- func (a Account) LoadIdentity() (person *ivms101.Person, err error)
- func (Account) TableName() string
- func (a Account) Transactions(db *DB) (records []Transaction, err error)
- type DB
- func (d *DB) Create(value interface{}) *gorm.DB
- func (d *DB) GetDB() *gorm.DB
- func (d *DB) GetVASP() VASP
- func (d *DB) LookupAccount(account string) *gorm.DB
- func (d *DB) LookupAnyAccount(account string) *gorm.DB
- func (d *DB) LookupAnyBeneficiary(beneficiary string) *gorm.DB
- func (d *DB) LookupBeneficiary(beneficiary string) *gorm.DB
- func (d *DB) LookupIdentity(walletAddress string) *gorm.DB
- func (d *DB) LookupPending() *gorm.DB
- func (d *DB) LookupTransaction(envelope string) *gorm.DB
- func (d *DB) LookupWallet(address string) *gorm.DB
- func (d *DB) MakeTransaction(originator string, beneficiary string) (*Transaction, error)
- func (d *DB) Query() *gorm.DB
- func (d *DB) Save(value interface{}) *gorm.DB
- type Identity
- type PolicyType
- type Transaction
- func (t Transaction) AmountFloat() float32
- func (t Transaction) GetAccount(db *DB) (account *Account, err error)
- func (t Transaction) GetBeneficiary(db *DB) (identity *Identity, err error)
- func (t Transaction) GetOriginator(db *DB) (identity *Identity, err error)
- func (t Transaction) Proto() *pb.Transaction
- func (t *Transaction) SetState(state pb.TransactionState)
- func (Transaction) TableName() string
- type VASP
- type Wallet
Constants ¶
const ( VASPS_FILE = "vasps.json" WALLETS_FILE = "wallets.json" TRANSACTIONS_FILE = "transactions.json" )
Variables ¶
This section is empty.
Functions ¶
func LoadWallets ¶
Load wallets from the fixtures directory as a slice of Wallet objects. Also returns a slice of Account objects which are derived from the wallet values.
Types ¶
type Account ¶
type Account struct { gorm.Model Name string `gorm:"not null"` Email string `gorm:"uniqueIndex;not null"` WalletAddress string `gorm:"uniqueIndex;not null;column:wallet_address"` Wallet Wallet `gorm:"foreignKey:WalletAddress;references:Address"` Balance decimal.Decimal `gorm:"type:numeric(15,2);default:0.0"` Completed uint64 `gorm:"not null;default:0"` Pending uint64 `gorm:"not null;default:0"` IVMS101 string `gorm:"column:ivms101;not null"` VaspID uint `gorm:"not null"` Vasp VASP `gorm:"foreignKey:VaspID"` }
Account contains details about the transactions that are served by the local VASP. It also contains the IVMS 101 data for KYC verification, in this table it is just stored as a JSON string rather than breaking it down to the field level. Only customers of the VASP have accounts.
func (Account) BalanceFloat ¶
BalanceFloat converts the balance decmial into an exact two precision float32 for use with the protocol buffers.
func (Account) LoadIdentity ¶
LoadIdentity returns the ivms101.Person for the Account.
func (Account) Transactions ¶
func (a Account) Transactions(db *DB) (records []Transaction, err error)
Transactions returns an ordered list of transactions associated with the account ordered by the timestamp of the transaction, listing any pending transactions at the top. This function may also support pagination and limiting functions, which is why we're using it rather than having a direct relationship on the model.
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a wrapper around a gorm.DB instance that restricts query results to a single VASP.
func NewDBMock ¶
NewDBMock creates a new mocked database object which uses an underlying SQL mock. The mock can be safely passed as a real database object to high-level functions which interact with gorm.DB objects to enable testing.
func (*DB) LookupAccount ¶
LookupAccount by email address or wallet address.
func (*DB) LookupAnyAccount ¶
LookupAnyAccount by email address or wallet address, not restricted to the local rVASP.
func (*DB) LookupAnyBeneficiary ¶
LookupAnyBeneficiary by email address or wallet address, not restricted to the local rVASP.
func (*DB) LookupBeneficiary ¶
LookupBeneficiary by email address or wallet address.
func (*DB) LookupIdentity ¶
LookupIdentity by wallet address.
func (*DB) LookupPending ¶
LookupPending returns the pending transactions.
func (*DB) LookupTransaction ¶
LookupTransaction by envelope ID.
func (*DB) LookupWallet ¶
LookupWallet by wallet address.
func (*DB) MakeTransaction ¶
func (d *DB) MakeTransaction(originator string, beneficiary string) (*Transaction, error)
MakeTransaction returns a new Transaction from the originator and beneficiary wallet addresses. Note: this does not store the transaction in the database to allow the caller to modify the transaction fields before storage.
type Identity ¶
type Identity struct { gorm.Model WalletAddress string `gorm:"not null;column:wallet_address;index:wallet_index,unique"` Email string `gorm:"not null"` Provider string `gorm:"not null"` VaspID uint `gorm:"not null;index:wallet_index,unique"` Vasp VASP `gorm:"foreignKey:VaspID"` }
Identity holds raw data for an originator or a beneficiary that was sent as part of the transaction process. This should not be stored in the wallet since the wallet is a representation of the local VASPs knowledge about customers and bercause the identity information could change between transactions. This intermediate table is designed to more closely mimic data storage as part of a blockchain transaction.
type PolicyType ¶
type PolicyType string
const ( SendPartial PolicyType = "SendPartial" SendFull PolicyType = "SendFull" SendError PolicyType = "SendError" SyncRepair PolicyType = "SyncRepair" SyncRequire PolicyType = "SyncRequire" AsyncRepair PolicyType = "AsyncRepair" AsyncReject PolicyType = "AsyncReject" )
type Transaction ¶
type Transaction struct { gorm.Model Envelope string `gorm:"not null"` AccountID uint `gorm:"not null"` Account Account `gorm:"foreignKey:AccountID"` OriginatorID uint `gorm:"column:originator_id;not null"` Originator Identity `gorm:"foreignKey:OriginatorID"` BeneficiaryID uint `gorm:"column:beneficiary_id;not null"` Beneficiary Identity `gorm:"foreignKey:BeneficiaryID"` Amount decimal.Decimal `gorm:"type:decimal(15,8)"` Debit bool `gorm:"not null"` State pb.TransactionState `gorm:"not null;default:0"` StateString string `gorm:"column:state_string;not null"` Timestamp time.Time `gorm:"not null"` NotBefore time.Time `gorm:"not null"` NotAfter time.Time `gorm:"not null"` Identity string `gorm:"not null"` Transaction string `gorm:"not null"` VaspID uint `gorm:"not null"` Vasp VASP `gorm:"foreignKey:VaspID"` }
Transaction holds exchange information to send money from one account to another. It also contains the decrypted identity payload that was sent as part of the TRISA protocol and the envelope ID that uniquely identifies the message chain. TODO: Add a field for the transaction payload marshaled as a string.
func (Transaction) AmountFloat ¶
func (t Transaction) AmountFloat() float32
AmountFloat converts the amount decmial into an exact two precision float32 for use with the protocol buffers.
func (Transaction) GetAccount ¶
func (t Transaction) GetAccount(db *DB) (account *Account, err error)
Return the account associated with the transaction.
func (Transaction) GetBeneficiary ¶
func (t Transaction) GetBeneficiary(db *DB) (identity *Identity, err error)
Return the originator address associated with the transaction.
func (Transaction) GetOriginator ¶
func (t Transaction) GetOriginator(db *DB) (identity *Identity, err error)
Return the originator associated with the transaction.
func (Transaction) Proto ¶
func (t Transaction) Proto() *pb.Transaction
Proto converts the transaction into a protocol buffer transaction
func (*Transaction) SetState ¶ added in v1.0.2
func (t *Transaction) SetState(state pb.TransactionState)
Set the transaction state to a new value
func (Transaction) TableName ¶
func (Transaction) TableName() string
TableName explicitly defines the name of the table for the model
type VASP ¶
type VASP struct { gorm.Model Name string `gorm:"uniqueIndex;size:255;not null"` LegalName *string `gorm:"column:legal_name;null"` URL *string `gorm:"null"` Country *string `gorm:"null"` Endpoint *string `gorm:"null"` PubKey *string `gorm:"null"` NotAfter *time.Time `gorm:"null"` IVMS101 string `gorm:"column:ivms101"` }
VASP is a record of known partner VASPs and caches TRISA protocol information. This table also contains IVMS101 data that identifies the VASP (but only for the local VASP - we assume that VASPs do not have IVMS101 data on each other and have to use the directory service for that). TODO: modify VASP ID to a GUID
func (VASP) LoadIdentity ¶
LoadIdentity returns the ivms101.Person for the VASP.
type Wallet ¶
type Wallet struct { gorm.Model Address string `gorm:"uniqueIndex"` Email string `gorm:"uniqueIndex"` OriginatorPolicy PolicyType `gorm:"column:originator_policy"` BeneficiaryPolicy PolicyType `gorm:"column:beneficiary_policy"` ProviderID uint `gorm:"not null"` Provider VASP `gorm:"foreignKey:ProviderID"` VaspID uint `gorm:"not null"` Vasp VASP `gorm:"foreignKey:VaspID"` }
Wallet is a mapping of wallet IDs to VASPs to determine where to send transactions. Provider lookups can happen by wallet address or by email.