Created
December 31, 2018 06:19
-
-
Save leon-do/521a8a5c913bba357036c11fb010eff9 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 user account | |
const userAccount = await blockchain.loadAccount(userPubKey) | |
// add a payment operation to the transaction | |
const transaction = new stellarSdk.TransactionBuilder(userAccount) | |
.addOperation( | |
stellarSdk.Operation.payment({ | |
destination: escrowPubKey, // user sends to escrow account | |
asset: stellarSdk.Asset.native(), // native is XLM | |
amount: '5' // user pays 5 XLM | |
}) | |
) | |
.addOperation( | |
stellarSdk.Operation.setOptions({ | |
source: escrowPubKey, | |
signer: { | |
ed25519PublicKey: serverKeyPair.publicKey(), // add server as a signer on escrow account | |
weight: 1 | |
} | |
}) | |
) | |
.addOperation( | |
stellarSdk.Operation.setOptions({ | |
source: escrowPubKey, | |
signer: { | |
ed25519PublicKey: userPubKey, // add user as a signer on escrow account | |
weight: 1 | |
} | |
}) | |
) | |
.addOperation( | |
stellarSdk.Operation.setOptions({ | |
source: escrowPubKey, | |
signer: { | |
sha256Hash: sha256HashOfPreimage, // hash taken from other chain. user has preimage | |
weight: 1 | |
}, | |
masterWeight: 0, // escrow cannot sign its own txs | |
lowThreshold: 2, // and add signing thresholds (2 of 3 signatures required) | |
medThreshold: 2, | |
highThreshold: 2 | |
}) | |
) | |
.build() | |
// sign transaction | |
transaction.sign(serverKeyPair) | |
// https://www.stellar.org/developers/js-stellar-sdk/reference/examples.html | |
const fundEnvelope = transaction.toEnvelope().toXDR('base64') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment