I’m able to complete all the steps whithout any error but when the Receiver send the Preimage via the LogicalSignature of smart contract the assets are not trasfered back to the Receiver and the ASA accumulates in the ESCROW account.
Using PureStack GoalSekeer I can see that the correct Preimage is sent into arg[0] and I doublechekced that my TEAL program contains the corresponding Hash (sha256).
just and example you can check the ESCROW address: 2BUSJSYFTTPHBP5H43MAX7AO7KPAWVRWD4BHV562VRNQEE72TP7FQRNWNE
and this transaction: L4U6XKXXIW7XQIM6SV7JO5KRNCMVQND3L2DSDCC7WVYQMF4DAT3Q
I generated the sha256 in this way:
the preimage is : preimage
and the corresponding sha256 is: 107661134f21fc7c02223d50ab9eb3600bc3ffc3712423a1e47bb1f9a9dbf55f
Can some one help me in understanding why the ASA are not trasfered back to che receiver?
KR
Pietro
A good solution to understand what is happening is storing the transaction in a file and then running goal clerk dryrun on it. You would see the mismatch there.
Thanks for your help. I corrected the HASH in the teal code inserting the b64 string.
But the transaction does not close the contract. I guess I’m missing some step.
This is the code I use:
//string parameter (R = preimage)
args = make([][]byte, 1)
args[0] = []byte("preimage")
lsig, err = crypto.MakeLogicSig(program, args, sk, ma)
addr = crypto.LogicSigAddress(lsig).String()
amount = uint64(0)
closeRemainderTo = ""
txn, err = transaction.MakeAssetTransferTxn(addr, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ", amount, note, txParams, closeRemainderTo, TIPSIUM_assetID)
if err != nil {
fmt.Printf("Failed to send txn: %s\n", err)
return
}
txID, stx, err = crypto.SignLogicsigTransaction(lsig, txn)
if err != nil {
fmt.Printf("Signing failed with %v", err)
return
}
fmt.Printf("Signed tx: %v\n", txID)
// Submit the raw transaction to network
transactionID, err = algodClient.SendRawTransaction(stx).Do(context.Background())
if err != nil {
fmt.Printf("Sending failed with %v\n", err)
}
// Wait for transaction to be confirmed
waitForConfirmation(txID, algodClient)
fmt.Printf("Transaction ID: %v\n", transactionID)
// Save the signed object to disk
fmt.Printf("Made signed transaction with TxID %s\n", txID)
filename := "./signed.tx"
err = ioutil.WriteFile(filename, stx, 0644)
if err != nil {
fmt.Printf("Failed in saving transaction to file %s, error %s\n", filename, err)
return
}
fmt.Printf("Saved signed transaction to file: %s\n", filename)
Thanks Fabrice but actually my transaction was ment to Close the contract providing the preimage it was the last step. Before this I already sent the ASA to the escrow. The transaction i’m testing is “from” the receiver to receive the funds from the escrow.
As far as I know any transaction providing the right preimage will result in the ASA transfered to the receiver account inserted into the TEAL program. Is this correct? (and the transaction shoul be to the Algo zeroaddress and with amount =0 as)
That is, an asset transfer of amount 0 to the address "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ". closeRemainterTo being empty, it is not used.
If you want to receive all the funds, the transaction is different.
You want the receiver AND the close remainder to to be the address that will receive funds.
Something like:
It doesn’t work. I tried
In the TEAL code I’m following the example by Ryan just replacing TMPL_RCV with PUKRDU2WJJZXDHEOPTTTBANSG3BGI6PCBLMLJWK2NZKXPLHK3ATXNGW5YE and TMPL_OWN with QQVVO244LOKXY6DVI2ZB7BRNMB3NLS4DZMFODGNA2D2X23SC36BIA2X6VU.