Skip to content

Commit c9e256b

Browse files
committed
Support burning coins into account #0
1 parent 0287ac8 commit c9e256b

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

convex-core/src/main/java/convex/core/lang/Context.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,8 @@ public Context transfer(Address target, long amount) {
14701470
}
14711471
AccountStatus targetAccount=accounts.get(targetIndex);
14721472

1473-
if (targetAccount.isActor()) {
1473+
// Special handling for an actor account other than #0 (burn address)
1474+
if (targetAccount.isActor()&&(!(target.longValue()==0))) {
14741475
// (call target amount (receive-coin source amount nil))
14751476
// SECURITY: actorCall must do fork to preserve this
14761477
Context actx=this.fork();
@@ -1479,19 +1480,18 @@ public Context transfer(Address target, long amount) {
14791480

14801481
long sent=currentBalance-actx.getBalance(source);
14811482
return actx.withResult(CVMLong.create(sent));
1482-
} else {
1483-
// must be a user account
1484-
long oldTargetBalance=targetAccount.getBalance();
1485-
long newTargetBalance=oldTargetBalance+amount;
1486-
AccountStatus newTargetAccount=targetAccount.withBalance(newTargetBalance);
1487-
accounts=accounts.assoc(targetIndex, newTargetAccount);
1488-
1489-
// SECURITY: new context with updated accounts
1490-
Context result=withChainState(chainState.withAccounts(accounts)).withResult(CVMLong.create(amount));
1483+
}
1484+
1485+
// must be a user account
1486+
long oldTargetBalance=targetAccount.getBalance();
1487+
long newTargetBalance=oldTargetBalance+amount;
1488+
AccountStatus newTargetAccount=targetAccount.withBalance(newTargetBalance);
1489+
accounts=accounts.assoc(targetIndex, newTargetAccount);
14911490

1492-
return result;
1493-
}
1491+
// SECURITY: new context with updated accounts
1492+
Context result=withChainState(chainState.withAccounts(accounts)).withResult(CVMLong.create(amount));
14941493

1494+
return result;
14951495
}
14961496

14971497
/**

convex-core/src/test/java/convex/core/lang/CoreTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3335,6 +3335,17 @@ public void testTransfer() {
33353335
assertArityError(step("(transfer 1)"));
33363336
assertArityError(step("(transfer 1 2 3)"));
33373337
}
3338+
3339+
@Test
3340+
public void testTransferBurn() {
3341+
Context ctx=context();
3342+
long supply=ctx.getState().computeSupply();
3343+
long AMT=1000000;
3344+
3345+
ctx=exec(ctx,"(transfer #0 "+AMT+")");
3346+
3347+
assertEquals(supply-AMT,ctx.getState().computeSupply());
3348+
}
33383349

33393350
@Test
33403351
public void testStake() {

0 commit comments

Comments
 (0)