-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
23 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 21 additions & 16 deletions
37
src/main/scala/com/github/fluency03/blockchain/core/Wallet.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,46 @@ | ||
package com.github.fluency03.blockchain.core | ||
|
||
trait Wallet { | ||
|
||
} | ||
import com.github.fluency03.blockchain.core.KeyContainer.balanceOfKey | ||
|
||
import scala.collection.mutable | ||
|
||
trait Wallet { | ||
|
||
case class RandomWallet() extends Wallet { | ||
def getKey(str: String): Option[KeyContainer] | ||
|
||
def newKey(): KeyContainer | ||
|
||
def balance(uTxOs: mutable.Map[Outpoint, TxOut]): Long | ||
|
||
} | ||
|
||
|
||
case class RandomWallet() extends Wallet { | ||
|
||
object RandomWallet { | ||
|
||
|
||
|
||
} | ||
|
||
|
||
private[this] val keys = mutable.Map.empty[String, KeyContainer] | ||
|
||
override def getKey(str: String): Option[KeyContainer] = keys.get(str) | ||
|
||
case class SeededWallet() extends Wallet { | ||
override def newKey(): KeyContainer = { | ||
val aNewKey = KeyContainer() | ||
keys += (aNewKey.publicKeyHex -> aNewKey) | ||
aNewKey | ||
} | ||
|
||
override def balance(uTxOs: mutable.Map[Outpoint, TxOut]): Long = | ||
keys.values.map(k => balanceOfKey(k, uTxOs)).sum | ||
|
||
|
||
} | ||
|
||
|
||
// TODO (Chang): To be implemented | ||
case class SeededWallet() extends Wallet { | ||
|
||
object SeededWallet { | ||
override def getKey(str: String): Option[KeyContainer] = ??? | ||
|
||
override def newKey(): KeyContainer = ??? | ||
|
||
override def balance(uTxOs: mutable.Map[Outpoint, TxOut]): Long = ??? | ||
|
||
} | ||
|
||
|
||
|