Hoping for a simple scenario following This thread:
1) Creating wallets from master accounts
2) Funding the escrow wallet
3) Giving the lock - in time bound period
4) Releasing the amount locked in escrow to destination
First 2 steps are fine, but as soon as I define lock -in time bounds in step 3, the Transaction is done immediately, transferring the funds to destination.
Ideally, I was hoping that the amount should be locked in Escrow account, and on further transaction, it should then release it to destination.
This is what I did to configure 3 accounts namely source, escrow and destination :
const account = new StellarSdk.Account(escrow.publicKey(), sequence)
const transaction = new StellarSdk.TransactionBuilder(account,{
fee: StellarSdk.BASE_FEE
})
.addOperation(Stellar.Operation.setOptions({
masterWeight: 2,
lowThreshold: 2,
medThreshold: 2,
highThreshold: 2,
signer: {
ed25519PublicKey: dest.publicKey(),
weight: 1
}
}))
.addOperation(Stellar.Operation.setOptions({
medThreshold: 3,
signer: {
ed25519PublicKey: source.publicKey(),
weight: 1
}
}))
.setTimeout(10000)
.build()
transaction.sign(StellarSdk.Keypair.fromSecret(escrow.secret()))
return server.submitTransaction(transaction)
And then this transaction to serve lock in period and amount should be locked :
const transaction = new StellarSdk.TransactionBuilder(account,{
timebounds: { minTime: time -20 ,
maxTime: time + 200 },
fee:StellarSdk.BASE_FEE })
.addOperation(
Stellar.Operation.payment({
destination: dest.publicKey(),
asset: StellarSdk.Asset.native(),
amount: amt
})
)
.addOperation(Stellar.Operation.setOptions({
signer: { ed25519PublicKey: dest.publicKey(), weight: 0 }
})
)
.addOperation(Stellar.Operation.setOptions({
masterWeight: 1, // revert to original state
lowThreshold: 0,
medThreshold: 0,
highThreshold: 0,
signer: { ed25519PublicKey: source.publicKey(), weight: 0 }
}))
.build()
transaction.sign(StellarSdk.Keypair.fromSecret(escrow.secret()),
StellarSdk.Keypair.fromSecret(dest.secret()))
return server.submitTransaction(transaction)
But as soon as this Tx is submitted, the funds are immediately transferred to destination account. What I am missing ?
timebounds: { minTime: time -20 , maxTime: time + 200 }
? The time range suggests your transaction is valid already when you make the function call, and so the funds are readily, immediately transferred. Do you mean some fixedtime
instead of a variable one?