Advertisement
obernardovieira

Untitled

Sep 5th, 2018
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.get('/multisig/:toaccount', (request, response) => {
  2.  
  3.     var pairSecond = StellarSdk.Keypair.random();
  4.  
  5.     server.loadAccount(pairMaster.publicKey()).then((account) => {
  6.         var secondaryAddress = pairSecond.publicKey();
  7.  
  8.         var transaction = new StellarSdk.TransactionBuilder(account)
  9.             .addOperation(StellarSdk.Operation.setOptions({
  10.                 signer: {
  11.                     ed25519PublicKey: secondaryAddress,
  12.                     weight: 1
  13.                 }
  14.             }))
  15.             .addOperation(StellarSdk.Operation.setOptions({
  16.                 masterWeight: 1, // set master key weight
  17.                 lowThreshold: 1,
  18.                 medThreshold: 2, // a payment is medium threshold
  19.                 highThreshold: 2 // make sure to have enough weight to add up to the high threshold!
  20.             }))
  21.             .build();
  22.  
  23.         transaction.sign(pairMaster); // only need to sign with the root signer as the 2nd signer won't be added to the account till after this transaction completes
  24.  
  25.         // now create a payment with the account that has two signers
  26.  
  27.         var transaction = new StellarSdk.TransactionBuilder(account)
  28.             .addOperation(StellarSdk.Operation.payment({
  29.                 destination: StellarSdk.Keypair.fromSecret(request.params.toaccount).publicKey(),
  30.                 asset: StellarSdk.Asset.native(),
  31.                 amount: "2" // 2000 XLM
  32.             }))
  33.             .build();
  34.  
  35.         var secondKeypair = StellarSdk.Keypair.fromSecret(pairSecond.secret());
  36.  
  37.         // now we need to sign the transaction with both the root and the secondaryAddress
  38.         transaction.sign(pairMaster);
  39.         transaction.sign(secondKeypair);
  40.  
  41.         server.submitTransaction(transaction)
  42.             .then(() => {
  43.                 response.send(request.params.amount + ' lumens sent to ' + pairTo.publicKey())
  44.             })
  45.             .catch((err) => {
  46.                 console.log(err.response.data.extras.result_codes);
  47.                 response.send('An error ocurred!')
  48.             });
  49.     });
  50.  
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement