Skip to content

Commit

Permalink
fix: nullable fields
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbackspace committed Dec 7, 2023
1 parent 3188681 commit 8dcd9ed
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 78 deletions.
4 changes: 2 additions & 2 deletions api_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Account struct {
Active bool `json:"active"`

// Epoch of the most recent action - registration or deregistration
ActiveEpoch int64 `json:"active_epoch"`
ActiveEpoch *int64 `json:"active_epoch"`

// Balance of the account in Lovelaces
ControlledAmount string `json:"controlled_amount"`
Expand All @@ -52,7 +52,7 @@ type Account struct {
WithdrawableAmount string `json:"withdrawable_amount"`

// Bech32 pool ID that owns the account
PoolID string `json:"pool_id"`
PoolID *string `json:"pool_id"`
}

// AccountRewardsHist return Account reward history
Expand Down
8 changes: 4 additions & 4 deletions api_addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Address struct {
Amount []AddressAmount `json:"amount"`

// Stake address that controls the key
StakeAddress string `json:"stake_address"`
StakeAddress *string `json:"stake_address"`

// Address era.
// Enum: "byron" "shelley"
Expand Down Expand Up @@ -74,10 +74,10 @@ type AddressUTXO struct {
Block string `json:"block"`

// The hash of the transaction output datum
DataHash string `json:"data_hash"`
DataHash *string `json:"data_hash"`

InlineDatum string `json:"inline_datum"`
ReferenceScriptHash string `json:"reference_script_hash"`
InlineDatum *string `json:"inline_datum"`
ReferenceScriptHash *string `json:"reference_script_hash"`
}

type AddressTxResult struct {
Expand Down
4 changes: 3 additions & 1 deletion api_addresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ var (
const testdata = "testdata"

func TestAddressUnMarshall(t *testing.T) {
stakeAddress := "stake1ux3u6x5cs388djqz6awnyuvez2f6n8jzjhqq59s4yxhm8jskeh0t9"

want := blockfrost.Address{
Address: "addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz",
Amount: []blockfrost.AddressAmount{{Unit: "lovelace", Quantity: "0"}},
StakeAddress: "stake1ux3u6x5cs388djqz6awnyuvez2f6n8jzjhqq59s4yxhm8jskeh0t9",
StakeAddress: &stakeAddress,
Type: "shelley",
Script: false,
}
Expand Down
13 changes: 9 additions & 4 deletions api_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ type Asset struct {
// Count of mint and burn transactions
MintOrBurnCount int `json:"mint_or_burn_count"`

// On-chain metadata stored in the minting transaction under label 721,
// community discussion around the standard ongoing at https://github.com/cardano-foundation/CIPs/pull/85
OnchainMetadata AssetOnchainMetadata `json:"onchain_metadata"`
Metadata AssetMetadata `json:"metadata"`
// On-chain metadata which SHOULD adhere to the valid standards, based on which we perform the look up and display the asset (best effort)
OnchainMetadata *AssetOnchainMetadata `json:"onchain_metadata"`
// Enum: "CIP25v1" "CIP25v2" "CIP68v1"
// If on-chain metadata passes validation, we display the standard under which it is valid
OnchainMetadataStandard *string `json:"onchain_metadata_standard"`
// Arbitrary plutus data (CIP68).
OnchainMetadataExtra *string `json:"onchain_metadata_extra"`
// Off-chain metadata fetched from GitHub based on network.
Metadata *AssetMetadata `json:"metadata"`
}

// Assets minted under a specific policy.
Expand Down
4 changes: 2 additions & 2 deletions api_assets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func TestAssetUnmarshal(t *testing.T) {
InitialMintTxHash: "6804edf9712d2b619edb6ac86861fe93a730693183a262b165fcc1ba1bc99cad",
MintOrBurnCount: 1,
Quantity: "12000",
OnchainMetadata: blockfrost.AssetOnchainMetadata{
OnchainMetadata: &blockfrost.AssetOnchainMetadata{
Image: "ipfs://ipfs/QmfKyJ4tuvHowwKQCbCHj4L5T3fSj8cjs7Aau8V7BWv226",
Name: "My NFT token",
},
Metadata: blockfrost.AssetMetadata{
Metadata: &blockfrost.AssetMetadata{
Name: "nutcoin",
Description: "The Nut Coin",
Ticker: "nutc",
Expand Down
10 changes: 5 additions & 5 deletions api_mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ type MempoolTransaction struct {
Hash string `json:"hash"`

// Left (included) endpoint of the timelock validity intervals
InvalidBefore string `json:"invalid_before"`
InvalidBefore *string `json:"invalid_before"`

// Right (excluded) endpoint of the timelock validity intervals
InvalidHereafter string `json:"invalid_hereafter"`
InvalidHereafter *string `json:"invalid_hereafter"`

// Count of the MIR certificates within the transaction
MirCertCount int `json:"mir_cert_count"`
Expand Down Expand Up @@ -80,10 +80,10 @@ type MempoolTransactionOutput struct {
Address string `json:"address"`
Amount []TxAmount `json:"amount"`
OutputIndex int `json:"output_index"`
DataHash string `json:"data_hash"`
InlineDatum string `json:"inline_datum"`
DataHash *string `json:"data_hash"`
InlineDatum *string `json:"inline_datum"`
Collateral bool `json:"collateral"`
ReferenceScriptHash string `json:"reference_script_hash"`
ReferenceScriptHash *string `json:"reference_script_hash"`
}
type MempoolTransactionInput struct {
Address string `json:"address"`
Expand Down
16 changes: 7 additions & 9 deletions api_mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestMempoolUnmarshal(t *testing.T) {
}

func TestMempoolTransactionContentUnmarshal(t *testing.T) {
invalidHereafter := "109798439"
want := blockfrost.MempoolTransactionContent{
Tx: blockfrost.MempoolTransaction{
Hash: "1f96d3824eb2aeeb0b09b99748bb70ac681e0cae6e37e01c43958b79ca69c986",
Expand All @@ -37,8 +38,8 @@ func TestMempoolTransactionContentUnmarshal(t *testing.T) {
Fees: "369133",
Deposit: "0",
Size: 4683,
InvalidBefore: "",
InvalidHereafter: "109798439",
InvalidBefore: nil,
InvalidHereafter: &invalidHereafter,
UtxoCount: 2,
ValidContract: true,
},
Expand All @@ -59,13 +60,10 @@ func TestMempoolTransactionContentUnmarshal(t *testing.T) {
Unit: "6787a47e9f73efe4002d763337140da27afa8eb9a39413d2c39d4286524144546f6b656e73",
Quantity: "15000",
}},
OutputIndex: 0,
// DataHash: nil,
// InlineDatum: nil,
// ReferenceScriptHash: nil,
DataHash: "",
InlineDatum: "",
ReferenceScriptHash: "",
OutputIndex: 0,
DataHash: nil,
InlineDatum: nil,
ReferenceScriptHash: nil,
Collateral: false,
}},
Redeemers: nil,
Expand Down
12 changes: 6 additions & 6 deletions api_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const (
// MetadataTxLabel return Transaction metadata labels
// List of all used transaction metadata labels.
type MetadataTxLabel struct {
Label string `json:"label"`
Cip10 string `json:"cip10"`
Count string `json:"count"`
Label string `json:"label"`
Cip10 *string `json:"cip10"`
Count string `json:"count"`
}

// MetadataTxContentInJSON Transaction metadata content raw in JSON
Expand All @@ -30,14 +30,14 @@ type MetadataTxContentInJSON struct {
TxHash string `json:"tx_hash"`
// string or object or Array of any or integer or number or boolean Nullable
// Content of the JSON metadata
JSONMetadata interface{} `json:"json_metadata"`
JSONMetadata *interface{} `json:"json_metadata"`
}

// MetadataTxContentInCBOR return Transaction metadata content in CBOR
// Transaction metadata per label.
type MetadataTxContentInCBOR struct {
TxHash string `json:"tx_hash"`
CborMetadata string `json:"cbor_metadata"`
TxHash string `json:"tx_hash"`
Metadata *string `json:"metadata"`
}

type MetadataTxLabelResult struct {
Expand Down
26 changes: 13 additions & 13 deletions api_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,24 @@ type PoolHistory struct {
// PoolMetadata return Stake pool metadata
// Stake pool registration metadata.
type PoolMetadata struct {
PoolID string `json:"pool_id"`
Hex string `json:"hex"`
URL string `json:"url"`
Hash string `json:"hash"`
Ticker string `json:"ticker"`
Name string `json:"name"`
Description string `json:"description"`
Homepage string `json:"homepage"`
PoolID string `json:"pool_id"`
Hex string `json:"hex"`
URL *string `json:"url"`
Hash *string `json:"hash"`
Ticker *string `json:"ticker"`
Name *string `json:"name"`
Description *string `json:"description"`
Homepage *string `json:"homepage"`
}

// PoolRelay return Stake pool relays
// Relays of a stake pool.
type PoolRelay struct {
Ipv4 string `json:"ipv4"`
Ipv6 string `json:"ipv6"`
DNS string `json:"dns"`
DNSSrv string `json:"dns_srv"`
Port int `json:"port"`
Ipv4 *string `json:"ipv4"`
Ipv6 *string `json:"ipv6"`
DNS *string `json:"dns"`
DNSSrv *string `json:"dns_srv"`
Port int `json:"port"`
}

// PoolDelegator return Stake pool delegators
Expand Down
6 changes: 5 additions & 1 deletion api_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
const (
resourceScripts = "scripts"
resourceRedeemers = "redeemers"
// resourceScriptsJson = "json"
// resourceScriptsCbor = "cbor"
// resourceDatum = "datum"
// resourceDatumCbor = "cbor"
)

// Script contains information about a script
Expand All @@ -23,7 +27,7 @@ type Script struct {
Type string `json:"type"`

// The size of the CBOR serialised script, if a Plutus script
SerialisedSize int `json:"serialised_size"`
SerialisedSize *int `json:"serialised_size"`
}

// ScriptRedeemer contains information about a script redeemer.
Expand Down
Loading

0 comments on commit 8dcd9ed

Please sign in to comment.