Skip to content

Commit

Permalink
feat: adds if not nil check for each of mapping methodsw
Browse files Browse the repository at this point in the history
  • Loading branch information
wregulski committed Jul 12, 2023
1 parent 1d5d244 commit 5cca091
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mappings/access_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (

// MapToAccessKeyContract will map the access key to the bux-models contract
func MapToAccessKeyContract(ac *bux.AccessKey) *buxmodels.AccessKey {
if ac == nil {
return nil
}

return &buxmodels.AccessKey{
Model: *common.MapToContract(&ac.Model),
ID: ac.ID,
Expand Down
4 changes: 4 additions & 0 deletions mappings/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (

// MapToAdminStatsContract will map the model from bux to the bux-models contract
func MapToAdminStatsContract(s *bux.AdminStats) *buxmodels.AdminStats {
if s == nil {
return nil
}

return &buxmodels.AdminStats{
Balance: s.Balance,
Destinations: s.Destinations,
Expand Down
8 changes: 8 additions & 0 deletions mappings/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (

// MapToContract will map the common model to the bux-models contract
func MapToContract(m *bux.Model) *common.Model {
if m == nil {
return nil
}

return &common.Model{
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
Expand All @@ -18,6 +22,10 @@ func MapToContract(m *bux.Model) *common.Model {

// MapToModel will map the bux-models contract to the common bux model
func MapToModel(m *common.Model) *bux.Model {
if m == nil {
return nil
}

return &bux.Model{
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
Expand Down
4 changes: 4 additions & 0 deletions mappings/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (

// MapToDestinationContract will map the bux destination model to the bux-models contract
func MapToDestinationContract(d *bux.Destination) *buxmodels.Destination {
if d == nil {
return nil
}

return &buxmodels.Destination{
Model: *common.MapToContract(&d.Model),
ID: d.ID,
Expand Down
8 changes: 8 additions & 0 deletions mappings/fee_unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (

// MapToFeeUnitContract will map the fee-unit model from bux to the bux-models contract
func MapToFeeUnitContract(fu *utils.FeeUnit) (fc *buxmodels.FeeUnit) {
if fu == nil {
return nil
}

return &buxmodels.FeeUnit{
Satoshis: fu.Satoshis,
Bytes: fu.Bytes,
Expand All @@ -15,6 +19,10 @@ func MapToFeeUnitContract(fu *utils.FeeUnit) (fc *buxmodels.FeeUnit) {

// MapToFeeUnitBux will map the fee-unit model from bux-models to the bux contract
func MapToFeeUnitBux(fu *buxmodels.FeeUnit) (fc *utils.FeeUnit) {
if fu == nil {
return nil
}

return &utils.FeeUnit{
Satoshis: fu.Satoshis,
Bytes: fu.Bytes,
Expand Down
4 changes: 4 additions & 0 deletions mappings/paymail_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func MapToPaymailP4Contract(p *bux.PaymailP4) *buxmodels.PaymailP4 {

// MapToPaymailP4Bux will map the bux-models paymail-address contract to the bux paymail-address model
func MapToPaymailP4Bux(p *buxmodels.PaymailP4) *bux.PaymailP4 {
if p == nil {
return nil
}

return &bux.PaymailP4{
Alias: p.Alias,
Domain: p.Domain,
Expand Down
8 changes: 8 additions & 0 deletions mappings/script_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (

// MapToScriptOutputContract will map the script-output model from bux to the bux-models contract
func MapToScriptOutputContract(so *bux.ScriptOutput) (sc *buxmodels.ScriptOutput) {
if so == nil {
return nil
}

return &buxmodels.ScriptOutput{
Address: so.Address,
Satoshis: so.Satoshis,
Expand All @@ -17,6 +21,10 @@ func MapToScriptOutputContract(so *bux.ScriptOutput) (sc *buxmodels.ScriptOutput

// MapToScriptOutputBux will map the script-output model from bux-models to the bux contract
func MapToScriptOutputBux(so *buxmodels.ScriptOutput) (sc *bux.ScriptOutput) {
if so == nil {
return nil
}

return &bux.ScriptOutput{
Address: so.Address,
Satoshis: so.Satoshis,
Expand Down
8 changes: 8 additions & 0 deletions mappings/sync_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (

// MapToSyncConfigContract will map the sync-config model from bux to the bux-models contract
func MapToSyncConfigContract(sc *bux.SyncConfig) *buxmodels.SyncConfig {
if sc == nil {
return nil
}

return &buxmodels.SyncConfig{
Broadcast: sc.Broadcast,
BroadcastInstant: sc.BroadcastInstant,
Expand All @@ -17,6 +21,10 @@ func MapToSyncConfigContract(sc *bux.SyncConfig) *buxmodels.SyncConfig {

// MapToSyncConfigBux will map the sync-config model from bux-models to the bux contract
func MapToSyncConfigBux(sc *buxmodels.SyncConfig) *bux.SyncConfig {
if sc == nil {
return nil
}

return &bux.SyncConfig{
Broadcast: sc.Broadcast,
BroadcastInstant: sc.BroadcastInstant,
Expand Down
44 changes: 44 additions & 0 deletions mappings/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func MapToTransactionBux(t *buxmodels.Transaction) *bux.Transaction {

// MapToTransactionConfigBux will map the transaction-config model from bux to the bux-models contract
func MapToTransactionConfigBux(tx *buxmodels.TransactionConfig) *bux.TransactionConfig {
if tx == nil {
return nil
}

destinations := make([]*bux.Destination, 0)
for _, destination := range tx.ChangeDestinations {
destinations = append(destinations, MapToDestinationBux(destination))
Expand Down Expand Up @@ -94,6 +98,10 @@ func MapToTransactionConfigBux(tx *buxmodels.TransactionConfig) *bux.Transaction

// MapToTransactionConfigContract will map the transaction-config model from bux-models to the bux contract
func MapToTransactionConfigContract(tx *bux.TransactionConfig) *buxmodels.TransactionConfig {
if tx == nil {
return nil
}

destinations := make([]*buxmodels.Destination, 0)
for _, destination := range tx.ChangeDestinations {
destinations = append(destinations, MapToDestinationContract(destination))
Expand Down Expand Up @@ -138,6 +146,10 @@ func MapToTransactionConfigContract(tx *bux.TransactionConfig) *buxmodels.Transa

// MapToDraftTransactionContract will map the transaction-output model from bux to the bux-models contract
func MapToDraftTransactionContract(tx *bux.DraftTransaction) *buxmodels.DraftTransaction {
if tx == nil {
return nil
}

return &buxmodels.DraftTransaction{
Model: *common.MapToContract(&tx.Model),
ID: tx.ID,
Expand All @@ -150,6 +162,10 @@ func MapToDraftTransactionContract(tx *bux.DraftTransaction) *buxmodels.DraftTra

// MapToTransactionInputContract will map the transaction-output model from bux-models to the bux contract
func MapToTransactionInputContract(inp *bux.TransactionInput) *buxmodels.TransactionInput {
if inp == nil {
return nil
}

return &buxmodels.TransactionInput{
Utxo: *MapToUtxoContract(&inp.Utxo),
Destination: *MapToDestinationContract(&inp.Destination),
Expand All @@ -158,6 +174,10 @@ func MapToTransactionInputContract(inp *bux.TransactionInput) *buxmodels.Transac

// MapToTransactionInputBux will map the transaction-output model from bux to the bux-models contract
func MapToTransactionInputBux(inp *buxmodels.TransactionInput) *bux.TransactionInput {
if inp == nil {
return nil
}

return &bux.TransactionInput{
Utxo: *MapToUtxoBux(&inp.Utxo),
Destination: *MapToDestinationBux(&inp.Destination),
Expand All @@ -166,6 +186,10 @@ func MapToTransactionInputBux(inp *buxmodels.TransactionInput) *bux.TransactionI

// MapToTransactionOutputContract will map the transaction-output model from bux to the bux-models contract
func MapToTransactionOutputContract(out *bux.TransactionOutput) *buxmodels.TransactionOutput {
if out == nil {
return nil
}

scriptOutputs := make([]*buxmodels.ScriptOutput, 0)
for _, scriptOutput := range out.Scripts {
scriptOutputs = append(scriptOutputs, MapToScriptOutputContract(scriptOutput))
Expand All @@ -184,6 +208,10 @@ func MapToTransactionOutputContract(out *bux.TransactionOutput) *buxmodels.Trans

// MapToTransactionOutputBux will map the transaction-output model from bux-models to the bux contract
func MapToTransactionOutputBux(out *buxmodels.TransactionOutput) *bux.TransactionOutput {
if out == nil {
return nil
}

scriptOutputs := make([]*bux.ScriptOutput, 0)
for _, scriptOutput := range out.Scripts {
scriptOutputs = append(scriptOutputs, MapToScriptOutputBux(scriptOutput))
Expand All @@ -202,6 +230,10 @@ func MapToTransactionOutputBux(out *buxmodels.TransactionOutput) *bux.Transactio

// MapToMapProtocolContract will map the transaction-output model from bux to the bux-models contract
func MapToMapProtocolContract(mp *bux.MapProtocol) *buxmodels.MapProtocol {
if mp == nil {
return nil
}

return &buxmodels.MapProtocol{
App: mp.App,
Keys: mp.Keys,
Expand All @@ -211,6 +243,10 @@ func MapToMapProtocolContract(mp *bux.MapProtocol) *buxmodels.MapProtocol {

// MapToMapProtocolBux will map the transaction-output model from bux-models to the bux contract
func MapToMapProtocolBux(mp *buxmodels.MapProtocol) *bux.MapProtocol {
if mp == nil {
return nil
}

return &bux.MapProtocol{
App: mp.App,
Keys: mp.Keys,
Expand All @@ -220,6 +256,10 @@ func MapToMapProtocolBux(mp *buxmodels.MapProtocol) *bux.MapProtocol {

// MapToOpReturnContract will map the transaction-output model from bux to the bux-models contract
func MapToOpReturnContract(op *bux.OpReturn) *buxmodels.OpReturn {
if op == nil {
return nil
}

return &buxmodels.OpReturn{
Hex: op.Hex,
HexParts: op.HexParts,
Expand All @@ -230,6 +270,10 @@ func MapToOpReturnContract(op *bux.OpReturn) *buxmodels.OpReturn {

// MapToOpReturnBux will map the op-return model from bux-models to the bux contract
func MapToOpReturnBux(op *buxmodels.OpReturn) *bux.OpReturn {
if op == nil {
return nil
}

return &bux.OpReturn{
Hex: op.Hex,
HexParts: op.HexParts,
Expand Down
16 changes: 16 additions & 0 deletions mappings/utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (

// MapToUtxoPointer will map the utxo-pointer model from bux to the bux-models contract
func MapToUtxoPointer(u *bux.UtxoPointer) *buxmodels.UtxoPointer {
if u == nil {
return nil
}

return &buxmodels.UtxoPointer{
TransactionID: u.TransactionID,
OutputIndex: u.OutputIndex,
Expand All @@ -17,6 +21,10 @@ func MapToUtxoPointer(u *bux.UtxoPointer) *buxmodels.UtxoPointer {

// MapToUtxoPointerBux will map the utxo-pointer model from bux-models to the bux contract
func MapToUtxoPointerBux(u *buxmodels.UtxoPointer) *bux.UtxoPointer {
if u == nil {
return nil
}

return &bux.UtxoPointer{
TransactionID: u.TransactionID,
OutputIndex: u.OutputIndex,
Expand All @@ -25,6 +33,10 @@ func MapToUtxoPointerBux(u *buxmodels.UtxoPointer) *bux.UtxoPointer {

// MapToUtxoContract will map the utxo model from bux to the bux-models contract
func MapToUtxoContract(u *bux.Utxo) *buxmodels.Utxo {
if u == nil {
return nil
}

return &buxmodels.Utxo{
Model: *common.MapToContract(&u.Model),
UtxoPointer: *MapToUtxoPointer(&u.UtxoPointer),
Expand All @@ -41,6 +53,10 @@ func MapToUtxoContract(u *bux.Utxo) *buxmodels.Utxo {

// MapToUtxoBux will map the utxo model from bux-models to the bux contract
func MapToUtxoBux(u *buxmodels.Utxo) *bux.Utxo {
if u == nil {
return nil
}

var draftID customtypes.NullString
draftID.String = u.DraftID

Expand Down
4 changes: 4 additions & 0 deletions mappings/xpub.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (

// MapToXpubContract will map the xpub model from bux to the bux-models contract
func MapToXpubContract(xpub *bux.Xpub) *buxmodels.Xpub {
if xpub == nil {
return nil
}

return &buxmodels.Xpub{
Model: *common.MapToContract(&xpub.Model),
ID: xpub.ID,
Expand Down

0 comments on commit 5cca091

Please sign in to comment.