You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the original code didn't properly set with target as TargetValue(since it is Int)
the second contract with message Reach will need parse the counter contract address. To better understanding and implement / test on test-net. here is my update:
import "@stdlib/deploy";
message CounterValue {
value: Int as uint32;
}
////////////////////////////////////////////////////////////////////////////
// this is our famous Counter contract, we've seen it before
// this contract is very annoying, it only allows to increment +1 at a time!
contract Counter with Deployable {
val: Int as uint32;
init() {
self.val = 0;
}
// step 6: this contract allows anyone to ask it to increment by 1 (ie. the other contract)
receive("increment") {
self.val = self.val + 1;
reply(CounterValue{value: self.val}.toCell());
}
// step 3: this contract replies with its current value to anyone asking (ie. the other contract)
receive("query") {
reply(CounterValue{value: self.val}.toCell());
}
get fun value(): Int {
return self.val;
}
}
message Reach {
target_value: Int as uint32;
}
////////////////////////////////////////////////////////////////////////////
// let's write a second helper contract to make our lives a little easier
// it will keep incrementing the previous contract as many times as we need!
contract BulkAdder with Deployable {
target_value: Int as uint32;
init() {
self.target_value = 10;
}
// step 1: users will send this message to tell us what target value we need to reach
receive(msg: Reach) {
self.target_value = msg.target_value;
let CounterAddressInit: StateInit = initOf Counter();
// step 2: this contract will query the current counter value from the other contract
send(SendParameters{
to: contractAddress(CounterAddressInit),
value: 0, /// TODO: https://github.com/tact-lang/tact/issues/31
mode: SendRemainingValue + SendIgnoreErrors, /// TODO: issues/31
body: "query".asComment(),
data: CounterAddressInit.data,
code: CounterAddressInit.code
});
}
// step 4: the other contract will tell us what is its current value by sending us this message
receive(msg: CounterValue) {
if (msg.value < self.target_value) {
// step 5: if its value is too low, send it another message to increment it by +1 more
send(SendParameters{
to: sender(),
value: 0, /// TODO: same issue 31
mode: SendRemainingValue + SendIgnoreErrors, /// TODO: https://github.com/tact-lang/tact/issues/31
body: "increment".asComment()
});
}
}
}
The text was updated successfully, but these errors were encountered:
Basically, we deployed the Counter contract initially, and send the query and successfully reply a series of reply until the value of counter contract is higher the target_value
Target:
target
asTargetValue
(since it isInt
)Reach
will need parse thecounter
contract address. To better understanding and implement / test on test-net. here is my update:The text was updated successfully, but these errors were encountered: