Retrieve the last entry of a stream item having the same key

+1 vote
Hello dear,

I'm using stream and I have several items with the same key. I needs to retrieve the last entry of given key.

I have used "liststreamkeyitems stream-identifier key" which brings a json array of all items regarding the key. There is a way to retrieve only the last entry regarding the key?

I also try to use the new command "liststreamblockitems", but without sucess (maybe I didn't use correctly).

Thanks in advance for any help.

Best regards.
asked Jun 20, 2017 by rcosta
edited Jun 20, 2017 by rcosta

1 Answer

0 votes

The API documentation shows you can retrieve any slice that you like. This should work in your case:

liststreamkeyitems stream-identifier key false 1

More here: http://www.multichain.com/developers/json-rpc-api/

answered Jun 20, 2017 by MultiChain
It's work fine! I need to explore with more attention the API. Thanks!
is it possible that count = 1 returns empty array
but when i set count to 2 it returns an array with length 1?
additonally if i dont set a count i can retrieve 4 key items.
i am only changing the count parameter

it seems every time i try to publish a new item in the stream with the same key.
i need to increase the count to be able to retrieve the latest. now i need my count to be set to 4 to be able to retrieve 1 item.

i am currently trying to publish multiple items with different keys to a single stream using createrawsendfrom.
Could you please post the full API calls you are making and their responses, so we can take a look?
createrawsendfrom
```
18JSZKBWT58mTGh3ymNxySTfqrENxxETp4
{}
[
  {
    for: 'access',
    keys: [
      '1HBNDyZhR111wcoMM9GZbBpPaHQscuwi3R',
      'eb8e3139e8644bd7ce154ee59c6e407380991a49d1e2d33ddb712360f70c5f5d',
      '3d67a7d7bd3597c0dc4bdb20d567da1536dbc98e86c6eea9783d32f4c45b67f7'
    ],
    data: '7b227265636f726454786964223a2265623865333133396538363434626437636531353465653539633665343037333830393931613439643165326433336464623731323336306637306335663564222c226163636573736b6579223a2265794a7064694936496a4a685a47526b4d6a63335a575a6b4d7a646a4d5745325a4449774e6a5930595746694f5449324d325931496977695a58426f5a57315164574a7361574e4c5a586b694f6949774e444269597a566c4e6a5a6b4d575134597a426d4f444d77597a5a6c5a4463314d54526a4f54686d4e5451795a6a63784d4445315a474a6d595449354d4759324e3245354d446c6b4e7a6734596a6c6d4f47566a5a44426d5a5467314d6a55345a6a566c4f574e68597a6c685a4756694d545978595745784f5451314d7a417a4e6a6330596a59774f4459334e3256694f5441304e574534595455344d4455334e6d4d775a4455354e7a4e6b4969776959326c77614756796447563464434936496d5a6a4d546377597a4d784d6d51354f444e6c5a4752685a474d344d32466c4d6d5133595459324d7a51355954637859546b324d544669593249324e7a59324e6a59314e444d7a597a4d354f474e6b59574e6c4e7a466a4f574d325a574d774d5455795a546868596a4130597a45784f544d785a4746684e6a45304d7a59314e6a4578596a5a6c4e6d557a4e6a6b314e6d56695a4467344d57566a4f4451304d5445775a6a4a6b4e6d45794f54426b59544a6b5a6d4534596a63794d574d334e4449324d7a55324d544e6c4d6a426c4d6a59794f4441694c434a7459574d694f69497a4e574e684d6d51314e6a6b3459544a684d57466a4d7a6b354e6d526c4e4464685a5463795a445932596d4a694e474d77597a41344d6a413159545a6b4e324a6c4d5755334d6a6b354f5445774d7a497759544d34496e303d222c22746f41646472657373223a223148424e44795a685231313177636f4d4d39475a6242705061485173637577693352227d'
  },
  {
    for: 'access',
    keys: [
      '1HBNDyZhR111wcoMM9GZbBpPaHQscuwi3R',
      '5665ad006440af9202f7f01de6783411627d8e1da7ab31a111aa718d1aa896d6',
      'root'
    ],
    data: '7b227265636f726454786964223a2235363635616430303634343061663932303266376630316465363738333431313632376438653164613761623331613131316161373138643161613839366436222c226163636573736b6579223a2265794a7064694936496a4a6b4d6d59334d574a684e5456684d4449324e44686d4e7a4d324d446333596a6b325a6d45304d445131496977695a58426f5a57315164574a7361574e4c5a586b694f6949774e446b774f474d325a6a42695a5467305957526c4d546b34593259784f444930596a55774d4463795a5445354f475178596a49794d544e694f5445335a546b325a6a49774e575131595463305a54426b4d4464695a544d304e7a64694f5445314d54526b5a445931597a55325a6a6c684d6d526a5a6a51334d7a41794e574d315a44466c4e5449334e3249774f4755314f5442694d4451774d545533597a42684e3249304d444d78595759794969776959326c77614756796447563464434936496a45775a6a55785957517a5a6d5a6b5a44566c4f5451324e544a694f474e6d4e6d4e6c4d3259355a4455774e7a497a4f4441344f5459304e474e6d4f444a685a545a6b5a6a63304d444e6c4f57526a4f5456694f4441345a57466a59324a6c4e4451314f47457a5957566b596d5a6a4d32466b4d4445344d54466c4d5459355a4468695954466c4e6a6c6a596a64695a6a6c6b4e5745795954466a596d5a6d4f5755314f444e69597a426d4d44466d596d5978595751334e6d59795a54557a4d5467335a5449784f57566b4e54566b5a4751315a4751694c434a7459574d694f694a6a4d6a5a6a4e7a5a694d445133596a466d4f446b344e6a4e6c59324d314d6a6c6d4f54466d596a45355954553559545134596a59784d4452684e6a6b355a444d775a4455324e6d566c596d55344e57566d4e446b78496e303d222c22746f41646472657373223a223148424e44795a685231313177636f4d4d39475a6242705061485173637577693352227d'
  }
]
```
response RAWTX
01000000019994907fd7e3a794b0ca6db81d28ed2738e1e616e1a88bd00f9ae6b1b34c375c0200000000ffffffff030000000000000000fdab031473706b65c60b97c90b65e5f2318b748c4dcc40b7752673706b6b3148424e44795a685231313177636f4d4d39475a6242705061485173637577693352754473706b6b65623865333133396538363434626437636531353465653539633665343037333830393931613439643165326433336464623731323336306637306335663564754473706b6b33643637613764376264333539376330646334626462323064353637646131353336646263393865383663366565613937383364333266346334356236376637756a4ddd027b227265636f726454786964223a2265623865333133396538363434626437636531353465653539633665343037333830393931613439643165326433336464623731323336306637306335663564222c226163636573736b6579223a2265794a7064694936496d4e6d4f446b794d6a67784e6a4a68595451305a5455334e5449784e5755795a474a6a4d54526a4f544935496977695a58426f5a57315164574a7361574e4c5a586b694f6949774e47597a59574e6b597a4d30596d4d344d5455354f544e6b596a686c5a6d49784d6a4e6d4d47457a4f5759315a544a6c4d444e6d4f5459334f5759774e4749334e5749324d546c6d4d6a49774d474d344e5449774d7a56694f474d354d7a6735593252685a6d4d335a6d526a4e54566a4d7a4934596a526b4d7a67335a6a64694e324e6b4f474a6d4d4756694e3249305a544d354e4445354d7a4d784d7a55315a5449344f4451344d544e6b4969776959326c77614756796447563464434936496d566b4d6d4530595441334e7a4530597a67785a5441345a6d59304f5449335a4759354d5468694d6a4e694f446c6c4f5755355954517a4d54686b4e57453459324d334d6d52684d6a56685a6d55334e7a686c4d7a59794f47557a5a5452695a444d7a4e474a6d59546c6a4e6a41325a4441325a475533596d566b59544e6b4f47526b4e5755774d5441355a4452694d7a677a4e575578597a67354d7a4979596d56684e7a51785a6d5135597a45335a5751305a4449794d3245344d444a684e6a59784e546c6b5a54686d5a545a685a474e6b596d55694c434a7459574d694f69493359544d314d7a49784d546b774f444269597a59324d7a5a6a4d446b354f5467334f4445335a6d4930595745335a6d55794e6d4533597a59305a6a6c684e6a41304f4445785a545a6c4d7a4177597a63354f444931496e303d222c22746f41646472657373223a223148424e44795a685231313177636f4d4d39475a6242705061485173637577693352227d0000000000000000fd6f031473706b65c60b97c90b65e5f2318b748c4dcc40b7752673706b6b3148424e44795a685231313177636f4d4d39475a6242705061485173637577693352754473706b6b35363635616430303634343061663932303266376630316465363738333431313632376438653164613761623331613131316161373138643161613839366436750873706b6b726f6f74756a4ddd027b227265636f726454786964223a2235363635616430303634343061663932303266376630316465363738333431313632376438653164613761623331613131316161373138643161613839366436222c226163636573736b6579223a2265794a7064694936496a426a5a474d335a4468684e6a45324e7a4d324d5756694f4752684e6a466c4d7a6b314d7a4d334e544e69496977695a58426f5a57315164574a7361574e4c5a586b694f6949774e444a6a4e5751334d6a41325a44566b4f474d34597a5534597a45784f54457a4f5467324f44466a4d4755314f5759785a4749345a4445334f44646a4d4759355a4755325a544e6d595445325a6d55774f4441334e444e6a4d6d45305a6a4d345a6a56684e6d466d5a546b794d4756684e544d324e6d5979597a41344e6a6b774d6d51304d57566c4e7a597a4d5464694d6a417a4d445a6b5a44637a59544a6c4d54526a4e5459314f54466c4969776959326c77614756796447563464434936496a67354d5463324f47566a4f4455314d32553159546c695a4449344e7a55784e544d3559544d785a445a6b4f5468694d7a55784d6a41304d54426d597a4d784e6d4d355a5467354e446b354d6d4e684d4749334d5745325a6d55784d445a684d6a4a6c4f4456694d474d784f54646d4e324a6a4d324d314d44646d59546b305a6d4e6a4e6d46685a5467785a5751795a474d794e324a6b4e545934596a49794d5467314f44566d5a444d7a4d4467304d324d794e6a5a6c4e5751324d7a6b77595446694e54466b4f545a6d4d474e6d4e445178597a45694c434a7459574d694f6949775a445a6d4e544535596a6731596a4d32593245784d474a6b5a545a6c4e44646b4d3255314e7a4a6c4d6a41354f4749784e5755315a5745304e6a45344f4755355a6a55774d5441314e6a4a694d5755324e446c6d496e303d222c22746f41646472657373223a223148424e44795a685231313177636f4d4d39475a6242705061485173637577693352227d00000000000000001976a9145015492db3460747f665ee3277d5395534ceea8288ac00000000
signrawtransaction
response
01000000019994907fd7e3a794b0ca6db81d28ed2738e1e616e1a88bd00f9ae6b1b34c375c020000006b483045022100b7278ed46d3138f2e5ee7753b7842f14cc87633f6fbbc69f489b68da4b60a48d02204d2690721690726e762cf3e66581a8c8a43fb77647be75bdf910e5d9e0d537e3012103abd44ac6a16f01a03ce1ac2aa37637d58d471b55acaf300c3ddf2c7b3e4e942dffffffff030000000000000000fdab031473706b65c60b97c90b65e5f2318b748c4dcc40b7752673706b6b3148424e44795a685231313177636f4d4d39475a6242705061485173637577693352754473706b6b65623865333133396538363434626437636531353465653539633665343037333830393931613439643165326433336464623731323336306637306335663564754473706b6b33643637613764376264333539376330646334626462323064353637646131353336646263393865383663366565613937383364333266346334356236376637756a4ddd027b227265636f726454786964223a2265623865333133396538363434626437636531353465653539633665343037333830393931613439643165326433336464623731323336306637306335663564222c226163636573736b6579223a2265794a7064694936496d4e6d4f446b794d6a67784e6a4a68595451305a5455334e5449784e5755795a474a6a4d54526a4f544935496977695a58426f5a57315164574a7361574e4c5a586b694f6949774e47597a59574e6b597a4d30596d4d344d5455354f544e6b596a686c5a6d49784d6a4e6d4d47457a4f5759315a544a6c4d444e6d4f5459334f5759774e4749334e5749324d546c6d4d6a49774d474d344e5449774d7a56694f474d354d7a6735593252685a6d4d335a6d526a4e54566a4d7a4934596a526b4d7a67335a6a64694e324e6b4f474a6d4d4756694e3249305a544d354e4445354d7a4d784d7a55315a5449344f4451344d544e6b4969776959326c77614756796447563464434936496d566b4d6d4530595441334e7a4530597a67785a5441345a6d59304f5449335a4759354d5468694d6a4e694f446c6c4f5755355954517a4d54686b4e57453459324d334d6d52684d6a56685a6d55334e7a686c4d7a59794f47557a5a5452695a444d7a4e474a6d59546c6a4e6a41325a4441325a475533596d566b59544e6b4f47526b4e5755774d5441355a4452694d7a677a4e575578597a67354d7a4979596d56684e7a51785a6d5135597a45335a5751305a4449794d3245344d444a684e6a59784e546c6b5a54686d5a545a685a474e6b596d55694c434a7459574d694f69493359544d314d7a49784d546b774f444269597a59324d7a5a6a4d446b354f5467334f4445335a6d4930595745335a6d55794e6d4533597a59305a6a6c684e6a41304f4445785a545a6c4d7a4177597a63354f444931496e303d222c22746f41646472657373223a223148424e44795a685231313177636f4d4d39475a6242705061485173637577693352227d0000000000000000fd6f031473706b65c60b97c90b65e5f2318b748c4dcc40b7752673706b6b3148424e44795a685231313177636f4d4d39475a6242705061485173637577693352754473706b6b35363635616430303634343061663932303266376630316465363738333431313632376438653164613761623331613131316161373138643161613839366436750873706b6b726f6f74756a4ddd027b227265636f726454786964223a2235363635616430303634343061663932303266376630316465363738333431313632376438653164613761623331613131316161373138643161613839366436222c226163636573736b6579223a2265794a7064694936496a426a5a474d335a4468684e6a45324e7a4d324d5756694f4752684e6a466c4d7a6b314d7a4d334e544e69496977695a58426f5a57315164574a7361574e4c5a586b694f6949774e444a6a4e5751334d6a41325a44566b4f474d34597a5534597a45784f54457a4f5467324f44466a4d4755314f5759785a4749345a4445334f44646a4d4759355a4755325a544e6d595445325a6d55774f4441334e444e6a4d6d45305a6a4d345a6a56684e6d466d5a546b794d4756684e544d324e6d5979597a41344e6a6b774d6d51304d57566c4e7a597a4d5464694d6a417a4d445a6b5a44637a59544a6c4d54526a4e5459314f54466c4969776959326c77614756796447563464434936496a67354d5463324f47566a4f4455314d32553159546c695a4449344e7a55784e544d3559544d785a445a6b4f5468694d7a55784d6a41304d54426d597a4d784e6d4d355a5467354e446b354d6d4e684d4749334d5745325a6d55784d445a684d6a4a6c4f4456694d474d784f54646d4e324a6a4d324d314d44646d59546b305a6d4e6a4e6d46685a5467785a5751795a474d794e324a6b4e545934596a49794d5467314f44566d5a444d7a4d4467304d324d794e6a5a6c4e5751324d7a6b77595446694e54466b4f545a6d4d474e6d4e445178597a45694c434a7459574d694f6949775a445a6d4e544535596a6731596a4d32593245784d474a6b5a545a6c4e44646b4d3255314e7a4a6c4d6a41354f4749784e5755315a5745304e6a45344f4755355a6a55774d5441314e6a4a694d5755324e446c6d496e303d222c22746f41646472657373223a223148424e44795a685231313177636f4d4d39475a6242705061485173637577693352227d00000000000000001976a9145015492db3460747f665ee3277d5395534ceea8288ac00000000

sendrawtransaction
response
3b04d9832b352c86ef9656846333ac2b17c651e8c0c4d2d95af28b0afc6c25af
liststreamkeyitems
access
5665ad006440af9202f7f01de6783411627d8e1da7ab31a111aa718d1aa896d6

Response *take note that this isnt the transaction that i last published*
 [
  {
    publishers: [ '1NRRmguoHaAo1hNvz9rTNtbjVRfKPYmnTk' ],
    keys: [
      '18JSZKBWT58mTGh3ymNxySTfqrENxxETp4',
      '5665ad006440af9202f7f01de6783411627d8e1da7ab31a111aa718d1aa896d6',
      'patientKey',
      'root'
    ],
    offchain: false,
    available: true,
    data: '7b227265636f726454786964223a2235363635616430303634343061663932303266376630316465363738333431313632376438653164613761623331613131316161373138643161613839366436222c226163636573736b6579223a2265794a7064694936496d4d324e6a41344d4463324e4455794d446733596a6378595752694d6a4668596a4a6a593245334e44466b496977695a58426f5a57315164574a7361574e4c5a586b694f6949774e4451315a5463345a445532596a6b344d7a5a6b4f5749785a6a55304e6a566a4d7a6c684d7a5132597a526b4d44686b4e6a59794d574d775a6a686a4d44686a4e4451344e545a685a6a4e6b4e7a6b794f544977595459784e324d774d6d52684d3252684e57497a4e474a6c5a5452694d5445774e7a51335a57466c4e6d4e6c4f4467334d544a6d4d6a466b4e6d49304f5467775a44557a4d5467314d5455314e5445794d6d4e685a4749304969776959326c77614756796447563464434936496d4e684e5459775a54686b593245335a57466c4f475a6d4f5464684e445a6b4e6d5a6d4e324a6a5a544d325a44526c4d4442694d474d774d7a59324e6a63774e6a55304e575a6b4e44466c4d47597a4d6d526b59544a6a4d446b334d6a63794e6a5a6b4d57466d4e7a637959545178597a4978597a55305a47517759574534595759344e5759794e4755315a4449354f546b324d3249355a545977597a45344e445a684d5745795a5464694d47566c4d6a466a4e6d4d794d6a63334d6d466a4e5449794d7a63334f474a6c5a6a4d304d7a4532595455694c434a7459574d694f694a6b596a45794d6a677a593246685a6a5533597a4d334e32526b4d44566d5a5756684d44466c4d544e6a5a4749784f544d7a4d47497a4e324d774d32526d595752685a474e69596a5668597a4d324e6d49774f446b7a496e303d227d',
    confirmations: 121,
    blocktime: 1573714446,
    txid: '55e17ad7c2c16c70b0a97ccedf2b1f2189270bcfceefec5485956662d117e04c'
  }
]

liststreamkeyitems
access
5665ad006440af9202f7f01de6783411627d8e1da7ab31a111aa718d1aa896d6
false
1

response
[]
We've taken a look and I'm afraid we don't have an immediate answer. Would you be willing to share the full blockchain directory of this node with us, so we can examine the problem? If so, please stop the node, then create a .zip archive of the blockchain directory, and email it to multichain dot debug at gmail dot com.
Also please first mention here which version of MultiChain you are using?
...