Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Oct 12th, 2018 65 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. new mapStore, PackageManager, register(`rho:registry:insertArbitrary`) in {
  2.   // Create the map of contract versions
  3.   mapStore!({}) |
  4.   // Store the PackageManager at a unique id.  If you want to send the id to
  5.   //   another contract, replace Nil with *<contract name>.
  6.   register!(bundle+{*PackageManager}, Nil) |
  7.  
  8.   // Claim a new package name
  9.   contract PackageManager(@"newPackage", @packageName, return) = {
  10.     for (@map <- mapStore) {
  11.       if (map.get(packageName)) {
  12.         mapStore!(map) |
  13.         return!((false, "A package with that name already exists."))
  14.       } else {
  15.         new ownerToken in {
  16.           mapStore!(map.set(packageName, {"ownerToken": *ownerToken, "versionMap": {}})) |
  17.           return!((true, *ownerToken))
  18.         }
  19.       }
  20.     }
  21.   } |
  22.  
  23.   // Release a new version of the package
  24.   contract PackageManager(@"setVersion", @packageName, @version, @value, @ownerToken, return) = {
  25.     for (@map <- mapStore) {
  26.       match map.get(packageName) {
  27.         Nil => {
  28.           mapStore!(map) |
  29.           return!((false, "No such package"))
  30.         }
  31.         (token, versionMap) => {
  32.           if (ownerToken != token) {
  33.             mapStore!(map) |
  34.             return!((false, "Token does not match"))
  35.           } else {
  36.             if (versionMap.get(version) != Nil) {
  37.               mapStore!(map) |
  38.               return!((false, "Version already exists"))
  39.             } else {
  40.               mapStore!(map.set(packageName, (ownerToken, versionMap.set(version, value)))) |
  41.               return!((true))
  42.             }
  43.           }
  44.         }
  45.         _ => {
  46.           mapStore!(map) |
  47.           return!((false, "Internal error!"))
  48.         }
  49.       }
  50.     }
  51.   } |
  52.  
  53.   // Get an specific version of a package
  54.   contract PackageManager(@"getVersion", @packageName, @version, return) = {
  55.     // Should be a peek once that's available
  56.     for (@map <- mapStore) {
  57.       mapStore!(map) |
  58.       match map.get(packageName) {
  59.         Nil => {
  60.           return!((false, "No such package"))
  61.         }
  62.         (token, versionMap) => {
  63.           if (versionMap.get(version) == Nil) {
  64.             return!((false, "No such version"))
  65.           } else {
  66.             return!((true, versionMap.get(version)))
  67.           }
  68.         }
  69.         _ => {
  70.           return!((false, "Internal error!"))
  71.         }
  72.       }
  73.     }
  74.   } |
  75.  
  76.   // Get the list of all versions of the package
  77.   contract PackageManager(@"listVersions", @packageName, return) = {
  78.     for (@map <- mapStore) {
  79.       mapStore!(map) |
  80.       match map.get(packageName) {
  81.         Nil => {
  82.           return!((false, "No such package"))
  83.         }
  84.         (token, versionMap) => {
  85.           return!((true, versionMap.keys()))
  86.         }
  87.         _ => {
  88.           return!((false, "Internal error!"))
  89.         }
  90.       }
  91.     }
  92.   }
  93. }
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
 
Top