Last time, we designed a quick and dirty program that retrieved the most recent operation performed on a specific account. This program used the Radiator gem which allows us to query the Steem blockchain using Ruby. Ultimately, we want to retrieve the content by the most recent vote by a specific account. This was one of the relationships that we wanted to explore on the Steem blockchain.
Today, we are going to perform some basic filtering so that we only retrieve votes by the author for content other than their own that they are voting for. By doing this, the only remaining task is to select the piece of content that was most recently voted and then building a somewhat efficient function around that process.
The first thing I do is to declare the author earlier. The reason for doing this is that eventually we will want to turn this program into a function that we'll use to grab content from the blockchain. Another thing you will notice is that I've added some comments represented by the # symbol. Comments make the code easier to read both for future reference and in the case that anybody else reads your code (like right now).
Next, we have a loop. Since we are going through more than one piece of content, we use the each function to cycle through the different posts that we grab from the jsonrpc result field. The each function takes a closure as an argument. A closure is essentially an anonymous function that allows us to perform repetitive over some object we pass in. This basically is shortcut to writing a full-blown function. As we cycle through each operation, we grab the operation like we did last time, but this time we perform some filtering.
We use an if statement which allows us some conditional flow control in our program. It essentially acts as a filter which only allows voting operations for content that does not have the current author as the author of the piece of content. This prevents self-voted content and the current article from appearing in the feed. The current article may appear without this statement since the vote operation includes both incoming and outgoing votes for the author.
Finally inside our loop, we print the author and permlink of a potential piece of content that satisfies our conditions. The permlink is essentially a string that identifies a piece of content on the blockchain and can be used to grab that piece of content from the blockchain. Getting the permlink will be the ultimate goal of each of our relationships moving forward.
So that's pretty much it for today. Next time, we'll finish up with designing the code for this relationship and try to discuss some efficiency concerns moving forward. We are now able to grab content that an author has voted upon and it seems trivial to select the most recent one, but the issue comes when we a user hasn't voted in awhile and we may have to go deep into their history to find one.