Last active
December 31, 2018 06:37
-
-
Save leon-do/98fc02fa8858374200df2c4d28066aa6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// load escrow account from pub key | |
const escrowAccount = await blockchain.loadAccount(escrowPubKey) | |
// build claim transaction with timelock | |
const tb = new stellarSdk.TransactionBuilder(escrowAccount, { | |
timebounds: { | |
minTime: Math.floor(Date.now() / 1000) + 3600, // this envelope is valid after 1 hour | |
maxTime: 0 | |
} | |
}) | |
.addOperation( | |
stellarSdk.Operation.payment({ | |
destination: serverKeyPair.publicKey(), | |
asset: stellarSdk.Asset.native(), | |
amount: '2.00001' // send upfront cost back to server | |
})) | |
.addOperation( | |
stellarSdk.Operation.accountMerge({ | |
destination: userPubKey // merge remainder back to user | |
})) | |
.build() | |
// sign transaction | |
tx.sign(serverKeyPair) | |
// https://www.stellar.org/developers/js-stellar-sdk/reference/examples.html | |
const refundEnvelope = tx.toEnvelope().toXDR('base64') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment