SHARE
TWEET

Untitled

a guest Jun 19th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ```
  2. var prevRedeemScript = readFromStack()
  3.  
  4. var preimage = readFromStack()
  5. validatePreimage(preimage)
  6.  
  7. var outputTransfers = readFromStack()
  8.  
  9. var siganture = readFromStack()
  10.  
  11. var tokenMetadata
  12.  
  13. // If this is the genesis transaction allow the script to create
  14. // and save all the token metadata.
  15. if tokenMetadata == nil {
  16.     tokenMetadata.tokenID = preimage.prevout
  17.     tokenMetadata.numCoins = 2000000000
  18.     tokenMetadata.inputValue = 2000000000
  19.     // etc
  20. } else {
  21.     // Otherwise validate prevRedeemScript
  22.     if makeOutputScript(hash160(prevRedeemScript)) != preimage.scriptCode {
  23.         fail()
  24.     }
  25.  
  26.     tokenMetadata = prevRedeemScript.metadata
  27. }
  28.  
  29. checkSig(redeemScript.pubkey, signature)
  30.  
  31. // For each requested output construct a new redeemScript/outputScript which
  32. // contains the exact same token metadata with the exception of a new value and
  33. // a new public key.
  34. //
  35. // Validate that the covenant sends to these output scripts.
  36. var totalOut = 0
  37. for i in range len(outputTransfers) {
  38.     totalOut += outputTransfers[i].value
  39.  
  40.     // We are including the input's prevOutpoint in the new redeem script to ensure that the redeemScript is unique
  41.     // for this input. This prevents other inputs in the transaction from claiming the same outputs as satisfying their
  42.     // covenant. If they tried, they wouldn't produce a redeemScript that satisfies the covenant.
  43.     newRedeemScript = makeNewRedeemScript(outputTransfers[i].value, outputTransfers[i].pubkey, preimage.prevout)
  44.     outputScript = makeOutputScript(hash160(redeemScript))
  45.  
  46.     if preimage.outputs[i].script != outputScript {
  47.         fail()
  48.     }
  49. }
  50.  
  51. // Validate that the total out == total in.
  52. if totalOut != tokenMetadata.inputValue {
  53.     fail()
  54. }
  55. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top