Skip to content

Commit

Permalink
feat: add json object type
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelCastilloB committed Dec 10, 2024
1 parent 57fa800 commit e671ba8
Show file tree
Hide file tree
Showing 149 changed files with 6,459 additions and 155 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Next (V1.1.0)
---------------------
- Added `cardano_json_writer_t` to write JSON to a buffer.
- Added `cardano_json_object_t` to parse JSON from a strings.
- Added new fuzzing targets for JSON parsing.

V1.0.0
---------------------
Expand Down
2 changes: 2 additions & 0 deletions doc/src/sections/api/json/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ This section of the documentation provides detailed information on each function
./json_writer
./json_context
./json_format
./json_object
./json_object_type

.. _JSON: https://www.json.org
100 changes: 100 additions & 0 deletions doc/src/sections/api/json/json_object.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
JSON Object
==========================

.. doxygentypedef:: cardano_json_object_t

------------

.. doxygenfunction:: cardano_json_object_parse

------------

.. doxygenfunction:: cardano_json_object_get_type

------------

.. doxygenfunction:: cardano_json_object_has_property

------------

.. doxygenfunction:: cardano_json_object_get_property_count

------------

.. doxygenfunction:: cardano_json_object_get_key_at

------------

.. doxygenfunction:: cardano_json_object_get_value_at

------------

.. doxygenfunction:: cardano_json_object_get_value_at_ex

------------

.. doxygenfunction:: cardano_json_object_get

------------

.. doxygenfunction:: cardano_json_object_get_ex

------------

.. doxygenfunction:: cardano_json_object_array_get_length

------------

.. doxygenfunction:: cardano_json_object_array_get

------------

.. doxygenfunction:: cardano_json_object_array_get_ex

------------

.. doxygenfunction:: cardano_json_object_get_string

------------

.. doxygenfunction:: cardano_json_object_get_is_negative_number

------------

.. doxygenfunction:: cardano_json_object_get_is_real_number

------------

.. doxygenfunction:: cardano_json_object_get_uint

------------

.. doxygenfunction:: cardano_json_object_get_signed_int

------------

.. doxygenfunction:: cardano_json_object_get_double

------------

.. doxygenfunction:: cardano_json_object_get_boolean

------------

.. doxygenfunction:: cardano_json_object_unref

------------

.. doxygenfunction:: cardano_json_object_ref

------------

.. doxygenfunction:: cardano_json_object_refcount

------------

.. doxygenfunction:: cardano_json_object_set_last_error

------------

.. doxygenfunction:: cardano_json_object_get_last_error
4 changes: 4 additions & 0 deletions doc/src/sections/api/json/json_object_type.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
JSON Object Type
==========================

.. doxygenenum:: cardano_json_object_type_t
33 changes: 33 additions & 0 deletions fuzz/json_corpus/blockfrost_tx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"hash": "1e043f100dce12d107f679685acd2fc0610e10f72a92d412794c9773d11d8477",
"block": "356b7d7dbb696ccd12775c016941057a9dc70898d87a63fc752271bb46856940",
"block_height": 123456,
"block_time": 1635505891,
"slot": 42000000,
"index": 1,
"output_amount": [
{
"unit": "lovelace",
"quantity": "42000000"
},
{
"unit": "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
"quantity": "12"
}
],
"fees": "182485",
"deposit": "0",
"size": 433,
"invalid_before": null,
"invalid_hereafter": "13885913",
"utxo_count": 4,
"withdrawal_count": 0,
"mir_cert_count": 0,
"delegation_count": 0,
"stake_cert_count": 0,
"pool_update_count": 0,
"pool_retire_count": 0,
"asset_mint_or_burn_count": 0,
"redeemer_count": 0,
"valid_contract": true
}
46 changes: 46 additions & 0 deletions fuzz/json_corpus/blockfrost_utxo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"hash": "1e043f100dce12d107f679685acd2fc0610e10f72a92d412794c9773d11d8477",
"inputs": [
{
"address": "addr1q9ld26v2lv8wvrxxmvg90pn8n8n5k6tdst06q2s856rwmvnueldzuuqmnsye359fqrk8hwvenjnqultn7djtrlft7jnq7dy7wv",
"amount": [
{
"unit": "lovelace",
"quantity": "42000000"
},
{
"unit": "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
"quantity": "12"
}
],
"tx_hash": "1a0570af966fb355a7160e4f82d5a80b8681b7955f5d44bec0dce628516157f0",
"output_index": 0,
"data_hash": "9e478573ab81ea7a8e31891ce0648b81229f408d596a3483e6f4f9b92d3cf710",
"inline_datum": "19a6aa",
"reference_script_hash": "13a3efd825703a352a8f71f4e2758d08c28c564e8dfcce9f77776ad1",
"collateral": false,
"reference": false
}
],
"outputs": [
{
"address": "addr1q9ld26v2lv8wvrxxmvg90pn8n8n5k6tdst06q2s856rwmvnueldzuuqmnsye359fqrk8hwvenjnqultn7djtrlft7jnq7dy7wv",
"amount": [
{
"unit": "lovelace",
"quantity": "42000000"
},
{
"unit": "b0d07d45fe9514f80213f4020e5a61241458be626841cde717cb38a76e7574636f696e",
"quantity": "12"
}
],
"output_index": 0,
"data_hash": "9e478573ab81ea7a8e31891ce0648b81229f408d596a3483e6f4f9b92d3cf710",
"inline_datum": "19a6aa",
"collateral": false,
"reference_script_hash": "13a3efd825703a352a8f71f4e2758d08c28c564e8dfcce9f77776ad1",
"consumed_by_tx": "66c29b56952f6085afac3b0632d781af78d020b080063bcfd6c54b8e2b8fed41"
}
]
}
1 change: 1 addition & 0 deletions fuzz/json_corpus/number_-9223372036854775808.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-9223372036854775808]
1 change: 1 addition & 0 deletions fuzz/json_corpus/number_-9223372036854775809.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[-9223372036854775809]
1 change: 1 addition & 0 deletions fuzz/json_corpus/number_1.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1.0]
1 change: 1 addition & 0 deletions fuzz/json_corpus/number_1.000000000000000005.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1.000000000000000005]
1 change: 1 addition & 0 deletions fuzz/json_corpus/number_1000000000000000.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1000000000000000]
1 change: 1 addition & 0 deletions fuzz/json_corpus/number_10000000000000000999.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[10000000000000000999]
1 change: 1 addition & 0 deletions fuzz/json_corpus/number_1e-999.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1E-999]
1 change: 1 addition & 0 deletions fuzz/json_corpus/number_1e6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1E6]
1 change: 1 addition & 0 deletions fuzz/json_corpus/number_9223372036854775807.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[9223372036854775807]
1 change: 1 addition & 0 deletions fuzz/json_corpus/number_9223372036854775808.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[9223372036854775808]
1 change: 1 addition & 0 deletions fuzz/json_corpus/object_key_nfc_nfd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"é":"NFC","é":"NFD"}
1 change: 1 addition & 0 deletions fuzz/json_corpus/object_key_nfd_nfc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"é":"NFD","é":"NFC"}
1 change: 1 addition & 0 deletions fuzz/json_corpus/object_same_key_different_values.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"a":1,"a":2}
1 change: 1 addition & 0 deletions fuzz/json_corpus/object_same_key_same_value.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"a":1,"a":1}
1 change: 1 addition & 0 deletions fuzz/json_corpus/object_same_key_unclear_values.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"a":0, "a":-0}
58 changes: 58 additions & 0 deletions fuzz/json_corpus/pparam.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"ada_per_utxo_byte": "64",
"collateral_percentage": 32,
"cost_models": {
"plutus_v1": "000000000000000000000000000000000000000000000000000000000000000",
"plutus_v2": "000000000000000000000000000000000000000000000000000000000000000"
},
"d": {
"numerator": "123",
"denominator": "345"
},
"execution_costs": {
"mem_price": {
"numerator": "123",
"denominator": "345"
},
"step_price": {
"numerator": "123",
"denominator": "345"
}
},
"expansion_rate": {
"numerator": "123",
"denominator": "345"
},
"key_deposit": "64",
"max_block_body_size": 32,
"max_block_ex_units": {
"mem": "123",
"steps": "456"
},
"max_block_header_size": 32,
"max_collateral_inputs": 32,
"max_epoch": 32,
"max_tx_ex_units": {
"mem": "123",
"steps": "456"
},
"max_tx_size": 32,
"max_value_size": 32,
"min_pool_cost": "64",
"minfee_a": "64",
"minfee_b": "64",
"n_opt": "123467",
"pool_deposit": "64",
"pool_pledge_influence": {
"numerator": "123",
"denominator": "345"
},
"protocol_version": {
"major": 1,
"minor": 2
},
"treasury_growth_rate": {
"numerator": "123",
"denominator": "345"
}
}
1 change: 1 addition & 0 deletions fuzz/json_corpus/string_1_escaped_invalid_codepoint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\uD800"]
1 change: 1 addition & 0 deletions fuzz/json_corpus/string_1_invalid_codepoint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["���"]
1 change: 1 addition & 0 deletions fuzz/json_corpus/string_2_escaped_invalid_codepoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\uD800\uD800"]
1 change: 1 addition & 0 deletions fuzz/json_corpus/string_2_invalid_codepoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["������"]
1 change: 1 addition & 0 deletions fuzz/json_corpus/string_3_escaped_invalid_codepoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["\uD800\uD800\uD800"]
1 change: 1 addition & 0 deletions fuzz/json_corpus/string_3_invalid_codepoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["���������"]
1 change: 1 addition & 0 deletions fuzz/json_corpus/string_with_escaped_NULL.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["A\u0000B"]
50 changes: 50 additions & 0 deletions fuzz/json_corpus/tx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"body": {
"inputs": [
{
"transaction_id": "38685cff32e65bbf5be53e5478b2c9f91c686a663394484df2205d4733d19ad5",
"index": 1
}
],
"outputs": [
{
"AlonzoFormatTxOut": {
"address": "addr_test1qz7mzl28dh765rgxh9c2r83xplyhh93zlfactlz3ypd922ehs85zw6lya0d072za0g56z39yea5p4aux73qumznwagzqrhkz9z",
"amount": {
"coin": 103430776,
"multiasset": {}
}
}
}
],
"fee": 172057,
"ttl": 77458022,
"certs": [
{
"VoteDelegCert": {
"stake_credential": {
"PubKey": {
"hash": "3781e8276be4ebdaff285d7a29a144a4cf681af786f441cd8a6eea04"
}
},
"d_rep": {
"AlwaysAbstain": {}
}
}
}
]
},
"witness_set": {
"vkeywitnesses": [
{
"vkey": "ed25519_pk12x9tdn9c9ncdkwynm3fj4u8ty77l66xkj6q3ladv79ky04re92eshvam49",
"ed25519_signature": "18f37f5f94397c10ab44d6d382a0abc83807ab8039b8bff3b172b5875d928cec5022f02d027e4077253a79910126562988c306c34f14dca9d79be4e1c6de940f"
},
{
"vkey": "ed25519_pk1wmmemeaj96nj24nntw3skjdxk9mwqdjp6zy0gwmyas5egqxewxmsgs8p26",
"ed25519_signature": "46f4ce5ee2d14ab15c38aa74063bf25c9481ceaec59f9cf55bc25f6aae20a3c8761db8f7e9621c5f6b3f5628c574f738c3c997f83210effd5790d54419254a0e"
}
]
},
"is_valid": true
}
1 change: 1 addition & 0 deletions fuzz/json_corpus/utf8_emojis.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions fuzz/json_corpus/y_array_arraysWithSpaces.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[[] ]
1 change: 1 addition & 0 deletions fuzz/json_corpus/y_array_empty-string.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[""]
1 change: 1 addition & 0 deletions fuzz/json_corpus/y_array_empty.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
1 change: 1 addition & 0 deletions fuzz/json_corpus/y_array_ending_with_newline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["a"]
1 change: 1 addition & 0 deletions fuzz/json_corpus/y_array_false.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[false]
1 change: 1 addition & 0 deletions fuzz/json_corpus/y_array_heterogeneous.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[null, 1, "1", {}]
1 change: 1 addition & 0 deletions fuzz/json_corpus/y_array_null.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[null]
Loading

0 comments on commit e671ba8

Please sign in to comment.