how to get a max per group and subgroup using jq - json

jq is an amazing tool and it does a lot.
as input I have
[
{
"backup": [
{
"timestamp": { "start": 1642144383, "stop": 1642144386 },
"info": { "size": 1200934840},
"type": "full"
},
{
"timestamp": {"start": 1642144388, "stop": 1642144392 },
"info": { "size": 1168586300
},
"type": "incr"
},
{
"timestamp": {"start": 1642145388, "stop": 1642145392 },
"info": { "size": 1168586330
},
"type": "incr"
}
],
"name": "dbname1"
},
{
"backup": [
{
"timestamp": { "start": 1642144383, "stop": 1642144386 },
"info": { "size": 1200934840},
"type": "full"
},
{
"timestamp": {"start": 1642144388, "stop": 1642144392 },
"info": { "size": 1168586300
},
"type": "incr"
}
],
"name": "dbname2"
}
]
and using
jq 'map([.backup[] + {name}] | max_by(.timestamp.stop))'
I get the latest timestamp.stop for a name. How should I change this to get the latest timestamp.stop for a name and group?
in SQL this would be something like max(.timestamp.stop) group by .name,.type
Hoping for output like:
[
{
"timestamp": {
"start": 1642144383,
"stop": 1642144386
},
"info": {
"size": 1200934840
},
"type": "full",
"name": "dbname1"
},
{
"timestamp": {
"start": 1642145388,
"stop": 1642145392
},
"info": {
"size": 1168586330
},
"type": "incr",
"name": "dbname1"
},
{
"timestamp": {
"start": 1642144383,
"stop": 1642144386
},
"info": {
"size": 1200934840
},
"type": "full",
"name": "dbname2"
},
{
"timestamp": {
"start": 1642144388,
"stop": 1642144392
},
"info": {
"size": 1168586300
},
"type": "incr",
"name": "dbname2"
}
]

Remove the inner brackets to flatten the array, then group_by both criteria (which makes your criteria an array), and map your max_by onto the result array:
jq 'map(.backup[] + {name}) | group_by([.name, .type]) | map(max_by(.timestamp.stop))'
[
{
"timestamp": {
"start": 1642144383,
"stop": 1642144386
},
"info": {
"size": 1200934840
},
"type": "full",
"name": "dbname1"
},
{
"timestamp": {
"start": 1642145388,
"stop": 1642145392
},
"info": {
"size": 1168586330
},
"type": "incr",
"name": "dbname1"
},
{
"timestamp": {
"start": 1642144383,
"stop": 1642144386
},
"info": {
"size": 1200934840
},
"type": "full",
"name": "dbname2"
},
{
"timestamp": {
"start": 1642144388,
"stop": 1642144392
},
"info": {
"size": 1168586300
},
"type": "incr",
"name": "dbname2"
}
]
Demo

This seems to produce the desired expected output. You need an additional grouping by the .type record, before doing the max_by
map( .backup[] + {name} ) | group_by(.name)[] |
group_by(.type) | map(max_by(.timestamp.stop))
jqplay demo

Related

how to get a clean array as output

As input I have:
[
{
"backup": [
{
"timestamp": { "start": 1642144383, "stop": 1642144386 },
"info": { "size": 1200934840},
"type": "full"
},
{
"timestamp": {"start": 1642144388, "stop": 1642144392 },
"info": { "size": 1168586300
},
"type": "incr"
}
],
"name": "dbname1"
},
{
"backup": [
{
"timestamp": { "start": 1642144383, "stop": 1642144386 },
"info": { "size": 1200934840},
"type": "full"
},
{
"timestamp": {"start": 1642144388, "stop": 1642144392 },
"info": { "size": 1168586300
},
"type": "incr"
}
],
"name": "dbname2"
}
]
using
jq '.[]
| [ .backup[] + {name} ]
| max_by(.timestamp.stop)
'
(thanks #pmf) I can re-order this to
{
"timestamp": {
"start": 1642144388,
"stop": 1642144392
},
"info": {
"size": 1168586300
},
"type": "incr",
"name": "dbname1"
}
{
"timestamp": {
"start": 1642144388,
"stop": 1642144392
},
"info": {
"size": 1168586300
},
"type": "incr",
"name": "dbname2"
}
Selected is the dict containing the max timestamp and the name added to it, being the last created backup of a database. There are multiple databases possible. How can I form the output to a cleanly formatted array?
I was hoping for
[
{
"timestamp": {
"start": 1642144388,
"stop": 1642144392
},
"info": {
"size": 1168586300
},
"type": "incr",
"name": "dbname1"
},
{
"timestamp": {
"start": 1642144388,
"stop": 1642144392
},
"info": {
"size": 1168586300
},
"type": "incr",
"name": "dbname2"
}
]
And yes, I can add this using sed but I feel jq should be able to do this. So the question is how can should this be written?
Instead of .[] | … use map(…) to retain the array.
jq 'map([.backup[] + {name}] | max_by(.timestamp.stop))'
[
{
"timestamp": {
"start": 1642144388,
"stop": 1642144392
},
"info": {
"size": 1168586300
},
"type": "incr",
"name": "dbname1"
},
{
"timestamp": {
"start": 1642144388,
"stop": 1642144392
},
"info": {
"size": 1168586300
},
"type": "incr",
"name": "dbname2"
}
]
Demo

Kubernetes + jq - retrieving containers list per pod yields cartesian product

Im trying to use jq on kubernetes json output, to create new json object containing list of objects - container and image per pod, however im getting cartesian product.
my input data (truncated from sensitive info):
{
"apiVersion": "v1",
"items": [
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"creationTimestamp": "2021-06-30T12:45:40Z",
"name": "pod-1",
"namespace": "default",
"resourceVersion": "757679286",
"selfLink": "/api/v1/namespaces/default/pods/pod-1"
},
"spec": {
"containers": [
{
"image": "image-1",
"imagePullPolicy": "Always",
"name": "container-1",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [
{
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
"readOnly": true
}
]
},
{
"image": "image-2",
"imagePullPolicy": "Always",
"name": "container-2",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [
{
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
"readOnly": true
}
]
}
],
"dnsPolicy": "ClusterFirst",
"enableServiceLinks": true,
"priority": 0,
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": {},
"serviceAccount": "default",
"serviceAccountName": "default",
"terminationGracePeriodSeconds": 30,
"tolerations": [
{
"effect": "NoExecute",
"key": "node.kubernetes.io/not-ready",
"operator": "Exists",
"tolerationSeconds": 300
},
{
"effect": "NoExecute",
"key": "node.kubernetes.io/unreachable",
"operator": "Exists",
"tolerationSeconds": 300
}
],
"volumes": [
{
"name": "default-token-b954f",
"secret": {
"defaultMode": 420,
"secretName": "default-token-b954f"
}
}
]
},
"status": {
"conditions": [
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"status": "True",
"type": "Initialized"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"message": "containers with unready status: [container-1 container-2]",
"reason": "ContainersNotReady",
"status": "False",
"type": "Ready"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"message": "containers with unready status: [container-1 container-2]",
"reason": "ContainersNotReady",
"status": "False",
"type": "ContainersReady"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2021-06-30T12:45:40Z",
"status": "True",
"type": "PodScheduled"
}
],
"containerStatuses": [
{
"image": "image-1",
"imageID": "",
"lastState": {},
"name": "container-1",
"ready": false,
"restartCount": 0,
"started": false,
"state": {
"waiting": {
"message": "Back-off pulling image \"image-1\"",
"reason": "ImagePullBackOff"
}
}
},
{
"image": "image-2",
"imageID": "",
"lastState": {},
"name": "container-2",
"ready": false,
"restartCount": 0,
"started": false,
"state": {
"waiting": {
"message": "Back-off pulling image \"image-2\"",
"reason": "ImagePullBackOff"
}
}
}
],
"qosClass": "BestEffort",
"startTime": "2021-06-30T12:45:40Z"
}
}
],
"kind": "List",
"metadata": {
"resourceVersion": "",
"selfLink": ""
}
}
my command:
jq '.items[] | { "name": .metadata.name, "containers": [{ "name": .spec.containers[].name, "image": .spec.containers[].image }]} '
desired output:
{
"name": "pod_1",
"containers": [
{
"name": "container_1",
"image": "image_1"
},
{
"name": "container_2",
"image": "image_2"
}
]
}
output I get:
{
"name": "pod-1",
"containers": [
{
"name": "container-1",
"image": "image-1"
},
{
"name": "container-1",
"image": "image-2"
},
{
"name": "container-2",
"image": "image-1"
},
{
"name": "container-2",
"image": "image-2"
}
]
}
Could anyone explain what am I doing wrong?
Best Regards, Piotr.
The problem is "name": .spec.containers[].name and "image": .spec.containers[].image:
Both expressions generate a sequence of each value for name and image which will than be combined.
Simplified example of why you get a Cartesian product:
jq -c -n '{name: ("A", "B"), value: ("C", "D")}'
outputs:
{"name":"A","value":"C"}
{"name":"A","value":"D"}
{"name":"B","value":"C"}
{"name":"B","value":"D"}
You get the desired output using this jq filter on your input:
jq '
.items[]
| {
"name": .metadata.name,
"containers": .spec.containers
| map({name, image})
}'
output:
{
"name": "pod-1",
"containers": [
{
"name": "container-1",
"image": "image-1"
},
{
"name": "container-2",
"image": "image-2"
}
]
}

Using jq search value using regex

I have this json object and I am trying to find a way to use regex in jq to search value in issuer_dn that is more than 8 characters. A regex like [A-Z]{8} should work but I am unable to get results. I am still learning jq and if there is any other tool that can be used then please share.
{
"ip": "127.0.0.1",
"data": {
"tls": {
"status": "success",
"protocol": "tls",
"result": {
"handshake_log": {
"server_hello": {
"version": {
"name": "TLSv1.2",
"value": 771
},
"random": "hhdshfhhdhfhshdh",
"session_id": "hjdsfyyueujhfjaskdfjjl",
"cipher_suite": {
"hex": "0xC014",
"name": "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
"value": 49172
},
"compression_method": 0,
"ocsp_stapling": false,
"ticket": false,
"secure_renegotiation": true,
"heartbeat": false,
"extended_master_secret": false
},
"server_certificates": {
"certificate": {
"raw": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC==",
"parsed": {
"version": 3,
"serial_number": "1234567890",
"signature_algorithm": {
"name": "SHA256-RSA",
"oid": "1.2.840.113549.1.1.11"
},
"issuer": {
"common_name": [
"ABC"
],
"country": [
"ABC"
],
"locality": [
"ABC"
],
"province": [
"ABC"
],
"organization": [
"ABC"
],
"organizational_unit": [
"ABC"
]
},
"issuer_dn": "C=ABCD, ST=ABCD, L=ABCD, O=ABCD, OU=ABCD, CN=ABCD",
"validity": {
"start": "2020-02-01T01:09:22Z",
"end": "2021-02-01T03:09:22Z",
"length": 7883663
},
"subject": {
"common_name": [
"ABC"
],
"country": [
"ABC"
],
"locality": [
"ABC"
],
"province": [
"ABC"
],
"organization": [
"ABC"
],
"organizational_unit": [
"ABC"
]
},
"subject_dn": "C=ABCD, ST=ABCD, L=ABCD, O=ABCD, OU=ABCD, CN=ABCD",
"subject_key_info": {
"key_algorithm": {
"name": "RSA"
},
"rsa_public_key": {
"exponent": 65537,
"modulus": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC",
"length": 2048
},
"fingerprint_sha256": "73hh3g39920jfjj38723bb3993hh3774994002"
},
"extensions": {
"basic_constraints": {
"is_ca": true
},
"authority_key_id": "73hh3g39920jfjj38723bb3993hh3774994002",
"subject_key_id": "73hh3g39920jfjj38723bb3993hh3774994002"
},
"signature": {
"signature_algorithm": {
"name": "SHA256-RSA",
"oid": "1.2.840.113549.1.1.11"
},
"value": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC",
"valid": true,
"self_signed": true
},
"fingerprint_md5": "73hh3g39920jfjj38723bb3993hh3774994002",
"fingerprint_sha1": "73hh3g39920jfjj38723bb3993hh3774994002",
"fingerprint_sha256": "73hh3g39920jfjj38723bb3993hh3774994002",
"tbs_noct_fingerprint": "73hh3g39920jfjj38723bb3993hh3774994002",
"spki_subject_fingerprint": "73hh3g39920jfjj38723bb3993hh3774994002",
"tbs_fingerprint": "73hh3g39920jfjj38723bb3993hh3774994002",
"validation_level": "73hh3g39920jfjj38723bb3993hh3774994002",
"redacted": false
}
},
"validation": {
"browser_trusted": false,
"browser_error": "x509: failed to load system roots and no roots provided"
}
},
"server_key_exchange": {
"ecdh_params": {
"curve_id": {
"name": "secp256r1",
"id": 23
},
"server_public": {
"x": {
"value": "73hh3g39920jfjj38723bb3993hh3774994002",
"length": 256
},
"y": {
"value": "73hh3g39920jfjj38723bb3993hh3774994002",
"length": 256
}
}
},
"digest": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC",
"signature": {
"raw": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC",
"type": "rsa",
"valid": true,
"signature_and_hash_type": {
"signature_algorithm": "rsa",
"hash_algorithm": "sha256"
},
"tls_version": {
"name": "TLSv1.2",
"value": 771
}
}
},
"client_key_exchange": {
"ecdh_params": {
"curve_id": {
"name": "secp256r1",
"id": 23
},
"client_public": {
"x": {
"value": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC=",
"length": 256
},
"y": {
"value": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC=",
"length": 256
}
},
"client_private": {
"value": "dGVzdCBkYXRhIGFuZCBnYXJiYWdldGVzdC=",
"length": 32
}
}
},
"client_finished": {
"verify_data": "dGVzdCBkY"
},
"server_finished": {
"verify_data": "dGVzdCBkY"
},
"key_material": {
"master_secret": {
"value": "dGVzdCBkY",
"length": 48
},
"pre_master_secret": {
"value": "dGVzdCBkY",
"length": 32
}
}
}
},
"timestamp": "2020-02-9T07:14:47Z"
}
}
}
I would use the following :
.data.tls.result.handshake_log.server_certificates.certificate.parsed.issuer_dn \
| select(length > 8)
You can try it here.
You could use:
test("[A-Z]{8}")

Convert list of json's present in a single json file into one single valid json

I have a big file named as new_file.json which have several json in it, like:
{ "ResourceRecordSets": [ { "Name": "XYZ.", "Type": "mms", "TTL": 172800, "ResourceRecords": [ { "Value": "mms-1219.buydmms-24.org." }, { "Value": "mms-1606.buydmms-08.co.uk." }, { "Value": "mms-516.buydmms-00.net." }, { "Value": "mms-458.buydmms-57.com." } ] }, { "Name": "XYZ.", "Type": "SOA", "TTL": 900, "ResourceRecords": [ { "Value": "ABC.COM. 1 7200 900 1209600 86400" } ] }, { "Name": "bb.XYZ.", "Type": "CNAME", "SetIdentifier": "fix", "GeoLocation": { "ContinentCode": "EU" }, "TTL": 300, "ResourceRecords": [ { "Value": "abx.xyz.com" } ] }, { "Name": "bb.XYZ.", "Type": "CNAME", "SetIdentifier": "route to xms staging svc", "GeoLocation": { "CountryCode": "*" }, "TTL": 60, "ResourceRecords": [ { "Value": "xms-staging-xmssvc-1241009625.eu-west-1.elb.amazonbuy.com" } ] } ] }
{ "ResourceRecordSets": [ { "Name": "xyz.com.", "Type": "mms", "TTL": 172800, "ResourceRecords": [ { "Value": "mms-877.buydmms-45.net." }, { "Value": "mms-1168.buydmms-18.org." }, { "Value": "mms-375.buydmms-46.com." }, { "Value": "mms-1835.buydmms-37.co.uk." } ] }, { "Name": "xyz.com.", "Type": "SOA", "TTL": 900, "ResourceRecords": [ { "Value": "mms-877.buydmms-45.net. buydmms-taste.hurdle.com. 1 7200 900 1209600 86400" } ] }, { "Name": "prod.xyz.com.", "Type": "CNAME", "SetIdentifier": "pointing to finclub", "Weight": 1, "TTL": 300, "ResourceRecords": [ { "Value": "indiv-finclub.elb.amazonbuy.com" } ] }, { "Name": "prod.xyz.com.", "Type": "CNAME", "SetIdentifier": "pointing to symentic", "Weight": 99, "TTL": 300, "ResourceRecords": [ { "Value": "some.com" } ] } ] }
{ "ResourceRecordSets": [ { "Name": "fun.org.", "Type": "mms", "TTL": 172800, "ResourceRecords": [ { "Value": "mms-352.buydmms-44.com." }, { "Value": "mms-1131.buydmms-13.org." }, { "Value": "mms-591.buydmms-09.net." }, { "Value": "mms-1997.buydmms-57.co.uk." } ] }, { "Name": "fun.org.", "Type": "SOA", "TTL": 900, "ResourceRecords": [ { "Value": "mms-352.buydmms-44.com. buydmms-taste.hurdle.com. 1 7200 900 1209600 86400" } ] }, { "Name": "portal-junior.fun.org.", "Type": "CNAME", "TTL": 300, "ResourceRecords": [ { "Value": "portal.expressplay.com" } ] } ] }
{ "ResourceRecordSets": [ { "Name": "junior.fun.org.", "Type": "mms", "TTL": 172800, "ResourceRecords": [ { "Value": "mms-518.buydmms-00.net." }, { "Value": "mms-1447.buydmms-52.org." }, { "Value": "mms-499.buydmms-62.com." }, { "Value": "mms-1879.buydmms-42.co.uk." } ] }, { "Name": "junior.fun.org.", "Type": "SOA", "TTL": 900, "ResourceRecords": [ { "Value": "mms-518.buydmms-00.net. buydmms-taste.hurdle.com. 1 7200 900 1209600 86400" } ] }, { "Name": "db.junior.fun.org.", "Type": "CNAME", "TTL": 300, "ResourceRecords": [ { "Value": "xms16-ap.crds.hurdle.com" } ] }, { "Name": "junior.junior.fun.org.", "Type": "CNAME", "ResourceRecords": [ { "Value": "This resource record set includes an attribute that is ummsupported on this Route 53 endpoint. Please commsider using a newer endpoint or a tool that does so." } ], "TrafficPolicyImmstanceId": "17b76444-85c2-4ec5-a16d-8611fa05ca82" } ] }
{ "ResourceRecordSets": [ { "Name": "junior.myjuniordmms.org.", "Type": "mms", "TTL": 172800, "ResourceRecords": [ { "Value": "mms-455.buydmms-56.com." }, { "Value": "mms-1381.buydmms-44.org." }, { "Value": "mms-741.buydmms-28.net." }, { "Value": "mms-1992.buydmms-57.co.uk." } ] }, { "Name": "junior.myjuniordmms.org.", "Type": "SOA", "TTL": 900, "ResourceRecords": [ { "Value": "mms-455.buydmms-56.com. buydmms-taste.hurdle.com. 1 7200 900 1209600 86400" } ] } ] }
I want to make the same file as one single valid json, can it be done by using jq or some other method in shell/bash
Yes , you can.
command:
cat new_file.json | jq -s '.[0] * .[1]'
output:
{
"ResourceRecordSets": [
{
"Name": "xyz.com.",
"Type": "mms",
"TTL": 172800,
"ResourceRecords": [
{
"Value": "mms-877.buydmms-45.net."
},
{
"Value": "mms-1168.buydmms-18.org."
},
{
"Value": "mms-375.buydmms-46.com."
},
{
"Value": "mms-1835.buydmms-37.co.uk."
}
]
},
{
"Name": "xyz.com.",
"Type": "SOA",
"TTL": 900,
"ResourceRecords": [
{
"Value": "mms-877.buydmms-45.net. buydmms-taste.hurdle.com. 1 7200 900 1209600 86400"
}
]
},
{
"Name": "prod.xyz.com.",
"Type": "CNAME",
"SetIdentifier": "pointing to finclub",
"Weight": 1,
"TTL": 300,
"ResourceRecords": [
{
"Value": "indiv-finclub.elb.amazonbuy.com"
}
]
},
{
"Name": "prod.xyz.com.",
"Type": "CNAME",
"SetIdentifier": "pointing to symentic",
"Weight": 99,
"TTL": 300,
"ResourceRecords": [
{
"Value": "some.com"
}
]
}
]
}
it's possible to achieve the same using unix/linux utilities only: sed and paste:
bash $ cat new_file.json | sed '/^ *$/d' | paste -s -d, - | sed -E 's/(.*)/[\1]/'
the first sed removes all the blank lines
paste concatenates all the input lines over comma ,
the last sed puts square brackets around the input
the resulting output will be a valid JSON

Stellar cross currency transaction doesn't work

I'm unable to execute payment transaction in Stellar testnet.
Initially i use find_path:
curl -X POST https://test.stellar.org:9002 -d '
{
"method": "static_path_find",
"params": [
{
"source_account": "g4e5v2ERpKvdBZrchn6DrWUtvezkXsu5wo",
"destination_account": "gJ3e65GzqERgeeS5oXsv8NGfdZWzm93ej6",
"source_currencies" : [ { "currency" : "SGD", "issuer" : "gDfapfG5hDHuYkbVpugtupkGYVTKXwd59r"} ],
"destination_amount": {
"currency": "MYR",
"value": "1",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS"
}
}
]
}'
The result I get:
{
"result": {
"alternatives": [
{
"paths_computed": [
[
{
"currency": "MYR",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 48
},
{
"account": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 1
}
]
],
"source_amount": {
"currency": "SGD",
"issuer": "gDfapfG5hDHuYkbVpugtupkGYVTKXwd59r",
"value": "0.375"
}
}
],
"destination_account": "gJ3e65GzqERgeeS5oXsv8NGfdZWzm93ej6",
"destination_currencies": [
"MYR",
"STR"
],
"status": "success"
}
}
Then I trying to broadcast transaction in the network:
curl -X POST https://test.stellar.org:9002 -d '
{
"method": "submit",
"params": [
{
"secret": "sfk7dUd4N8cxVFVowsZL4DQgonNP9k8WFBgaV2NmwEQKGzWuqXT",
"tx_json": {
"TransactionType": "Payment",
"Account": "g4e5v2ERpKvdBZrchn6DrWUtvezkXsu5wo",
"Destination": "gJ3e65GzqERgeeS5oXsv8NGfdZWzm93ej6",
"Amount": {
"currency": "MYR",
"value": "1",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS"
},
"Paths": [
[
{
"currency": "MYR",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 48
},
{
"account": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 1
}
]
]
}
}
]
}'
And finally I'm getting unsuccessful result when transaction passed through consensus:
{
"engine_result": "tecPATH_PARTIAL",
"engine_result_code": 101,
"engine_result_message": "Path could not send full amount.",
"ledger_hash": "82BCF42941EF00BEA9E575B696CD88EC7E14FDE8CFD39FDA6A76B5710FDD0755",
"ledger_index": 704612,
"meta": {
"AffectedNodes": [
{
"ModifiedNode": {
"FinalFields": {
"Account": "g4e5v2ERpKvdBZrchn6DrWUtvezkXsu5wo",
"Balance": "199999960",
"Flags": 0,
"OwnerCount": 1,
"Sequence": 5
},
"LedgerEntryType": "AccountRoot",
"LedgerIndex": "D3433DEE556200D8AB72DED7156A597A273103D2BC50F526193EB9C4D8C8B735",
"PreviousFields": {
"Balance": "199999970",
"Sequence": 4
},
"PreviousTxnID": "6ADF48B45D95B3ABD20FD78F95F7E4F20D91FF5D169ECC5EFD6DB0CA78BEA486",
"PreviousTxnLgrSeq": 704445
}
}
],
"TransactionIndex": 0,
"TransactionResult": "tecPATH_PARTIAL"
},
"status": "closed",
"transaction": {
"Account": "g4e5v2ERpKvdBZrchn6DrWUtvezkXsu5wo",
"Amount": {
"currency": "MYR",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"value": "1"
},
"Destination": "gJ3e65GzqERgeeS5oXsv8NGfdZWzm93ej6",
"Fee": "10",
"Flags": 2147483648,
"Paths": [
[
{
"currency": "MYR",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 48
},
{
"account": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 1
}
]
],
"Sequence": 4,
"SigningPubKey": "4B640AC0C64AEF1C97EAAD0629CADDCA95FBA5F095BD20BD6282BEC450A125B1",
"TransactionType": "Payment",
"TxnSignature": "7BF5772EB916F20F56C5F148E99C3C3DD77C2916EAA47AB2D7FA8306F2B4A9D3FA4B789BDB79899A634B0C33F50A6ACB447CA6A9633C1C73BAB754FBFE74C105",
"date": 485412700,
"hash": "846AB6502D3B7A3137B2B538E6616B9C4459D2A67C48E58AF6B64F4659FF0016"
},
"type": "transaction",
"validated": true
}
Why? What I did wrong? I really can't understand...
Anyway I found the problem.
I forgot to add required SendMax parameter when submitting transaction.
curl -X POST https://test.stellar.org:9002 -d '
{
"method": "submit",
"params": [
{
"secret": "sfk7dUd4N8cxVFVowsZL4DQgonNP9k8WFBgaV2NmwEQKGzWuqXT",
"tx_json": {
"TransactionType": "Payment",
"Account": "g4e5v2ERpKvdBZrchn6DrWUtvezkXsu5wo",
"Destination": "gJ3e65GzqERgeeS5oXsv8NGfdZWzm93ej6",
"Amount": {
"currency": "MYR",
"value": "1",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS"
},
"Paths": [
[
{
"currency": "MYR",
"issuer": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 48
},
{
"account": "gsQuUKcxM68nEX9tKR71UH5hZXwrvT2mpS",
"type": 1
}
]
],
"SendMax" : { "currency" : "SGD", "value" : "0.375", "issuer": "gDfapfG5hDHuYkbVpugtupkGYVTKXwd59r" }
}
}
]
}'