Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

RPCIEGE - Skirmish 10

Posted on Oct 6 And we're already moving on to Skirmish 10 of the RPCiege!Have a look at the booklet for the exact details of the mission. Here's my summary:As a small diversion, you can try to make a manual Guess.After all, you have about 1 in 4 billion chance to guess correct.Okay, that's not going to work. We'll have to look at the contracts code.The magic happens in this part of the code:We see that a random number is derived from the ledger timestamp and ledger sequence.Then, our guess is compared to that number.Back in Skirmish 6 there was a similar situation. Then, there was some room to calculate the number, then quickly invoke the game Contract.Now, we don't have that option. We have to make the guess in the same ledger as the calculation happens.Luckily, cross-contract calls come to the rescue.If your contract calls another contract, that will happen in the same ledger. So, we can make our own contract and use the same logic to calculate the guess. Then call the game contract from our own contract, and since it happens in the same ledger, the timestamp and sequence will be the same.The Soroban Examples include a cross-contract example, which I've used as the basis for the solution.Like the in previous skirmish, we can use soroban contract fetch in soroban-cli to retreive the game contract.Then, it can be imported in your own contract code, so you can interact with it.I'm not going to give out the full solution, but I'll share my wrong_guess function.It sets my guess to 1, then calls the target contract with it.Notice how I've put a target: Address parameter in the contract.When invoking my contract, I have to put the game contract in as argument. That way, my contract knows which contract to shoot the guess at.Now it's up to you to replace let guess: u32 = 1; with the calculation for the correct number. With the information above and in the booklet, you should be able to :-)And if not, leave a comment, or even better, hop in the Stellar Dev Discord. Happy cieging!Row-BearPS: If you get stuck, chances are you'll have to add a dependency or two to your Cargo.toml:Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse Ján Gajdoš - Jul 3 Vikram Fugro - Jul 3 Eze Sunday Eze - Jul 2 Jan Schulte - Jun 30 Once suspended, row-bear will not be able to comment or publish posts until their suspension is removed. Once unsuspended, row-bear will be able to comment and publish posts again. Once unpublished, all posts by row-bear will become hidden and only accessible to themselves. If row-bear is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Row-Bear. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag row-bear: row-bear consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging row-bear will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

RPCIEGE - Skirmish 10

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×