Skip to content

Commit

Permalink
Merge pull request Agoric#16 from Agoric/use-ertp
Browse files Browse the repository at this point in the history
Make Cosmic-Swingset use ERTP instead of copied Mint
  • Loading branch information
katelynsills authored Jun 8, 2019
2 parents b365c1b + 61c894f commit f6fd775
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 99 deletions.
87 changes: 9 additions & 78 deletions lib/ag-solo/vats/vat-mint.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,18 @@
// Copyright (C) 2012 Google Inc.
// Copyright (C) 2018 Agoric
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright (C) 2019 Agoric, under Apache License 2.0

import Nat from '@agoric/nat';
import harden from '@agoric/harden';

function build(_E, log) {
let debugCounter = 0;

function makeMint() {
log(`makeMint`);
// Map from purse or payment to balance
const ledger = new WeakMap();

const issuer = harden({
makeEmptyPurse(name) {
log(`makeEmptyPurse(${name})`);
// eslint-disable-next-line no-use-before-define
return mint(0, name); // mint and issuer call each other
},
});

const mint = (initialBalance, name) => {
const purse = harden({
getBalance() {
log(`getBalance`, ledger.get(purse));
return ledger.get(purse);
},
getIssuer() {
return issuer;
},
deposit(amount, srcP) {
amount = Nat(amount);
debugCounter += 1;
const c = debugCounter;
log(`deposit[${name}]#${c}: bal=${ledger.get(purse)} amt=${amount}`);
return Promise.resolve(srcP).then(src => {
log(
` dep[${name}]#${c} (post-P): bal=${ledger.get(
purse,
)} amt=${amount}`,
);
const myOldBal = Nat(ledger.get(purse));
const srcOldBal = Nat(ledger.get(src));
Nat(myOldBal + amount);
const srcNewBal = Nat(srcOldBal - amount);
// ///////////////// commit point //////////////////
// All queries above passed with no side effects.
// During side effects below, any early exits should be made into
// fatal turn aborts.
ledger.set(src, srcNewBal);
// In case purse and src are the same, add to purse's updated
// balance rather than myOldBal above. The current balance must be
// >= 0 and <= myOldBal, so no additional Nat test is needed.
// This is good because we're after the commit point, where no
// non-fatal errors are allowed.
ledger.set(purse, ledger.get(purse) + amount);
});
},
});
ledger.set(purse, initialBalance);
return purse;
};
return harden({ mint });
}
import { makeMint } from '@agoric/ertp/core/issuers';

function build(_E, _log) {
return harden({ makeMint });
}
harden(build);

export default function setup(syscall, state, helpers) {
function log(what) {
helpers.log(what);
console.log(what);
function setup(syscall, state, helpers) {
function log(...args) {
helpers.log(...args);
console.log(...args);
}
return helpers.makeLiveSlots(
syscall,
Expand All @@ -91,3 +21,4 @@ export default function setup(syscall, state, helpers) {
helpers.vatID,
);
}
export default harden(setup);
157 changes: 136 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"author": "Agoric",
"license": "Apache-2.0",
"dependencies": {
"@agoric/ertp": "0.0.4",
"@agoric/swingset-vat": "^0.0.11",
"@iarna/toml": "^2.2.3",
"bindings": "^1.2.1",
Expand Down

0 comments on commit f6fd775

Please sign in to comment.