-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from OmniLayer/msgilligan-omni-types
Begin conversion from BigInteger to OmniValue and Coin
- Loading branch information
Showing
28 changed files
with
431 additions
and
188 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
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
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
21 changes: 21 additions & 0 deletions
21
omnij-core/src/main/java/foundation/omni/test/MoneyMan.java
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package foundation.omni.test; | ||
|
||
import foundation.omni.OmniDivisibleValue; | ||
import org.bitcoinj.core.Coin; | ||
|
||
/** | ||
* Definitions for MoneyMan address functionality on TestNet and RegTest | ||
*/ | ||
public class MoneyMan { | ||
public static final long willetsPerSatoshi = 100; // Exchange rate for MoneyMan: 100 Omni per BTC | ||
|
||
/** | ||
* Calculate Omni returned in a MoneyMan exchange. | ||
* | ||
* @param bitcoin An amount of bitcoin | ||
* @return the amount of Omni the MoneyMan will exchange it for | ||
*/ | ||
public static OmniDivisibleValue toOmni(Coin bitcoin) { | ||
return OmniDivisibleValue.ofWillets(bitcoin.value * willetsPerSatoshi); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apply plugin: 'java' | ||
apply plugin: 'groovy' | ||
|
||
dependencies { | ||
compile "org.codehaus.groovy:groovy:2.4.4" | ||
compile project(':omnij-core') | ||
|
||
testCompile("org.spockframework:spock-core:1.0-groovy-2.4") { | ||
exclude module: "groovy-all" | ||
} | ||
} | ||
|
||
sourceCompatibility = 1.7 |
64 changes: 64 additions & 0 deletions
64
omnij-dsl/src/main/groovy/foundation/omni/dsl/categories/NumberCategory.groovy
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package foundation.omni.dsl.categories | ||
|
||
import foundation.omni.OmniValue | ||
import groovy.transform.CompileStatic | ||
|
||
import foundation.omni.OmniDivisibleValue | ||
import foundation.omni.OmniIndivisibleValue | ||
|
||
|
||
/** | ||
* Convenience Category for converting Numbers to the Coin class | ||
* | ||
*/ | ||
@CompileStatic | ||
@Category(Number) | ||
class NumberCategory { | ||
private static final BigDecimal willetsPerBTCDecimal = new BigDecimal(OmniDivisibleValue.willetsPerCoin) | ||
private static final BigInteger willetsPerBTCBigInt = BigInteger.valueOf(OmniDivisibleValue.willetsPerCoin) | ||
|
||
/** | ||
* Treat number as a decimal, divisible amount of an Omni currency | ||
* | ||
* @return a OmniDivisibleValue object | ||
*/ | ||
public OmniDivisibleValue getDivisible() { | ||
return OmniDivisibleValue.of(asDivisible(this)) | ||
} | ||
|
||
/** | ||
* Treat number as an integer, indivisible amount of an Omni currency | ||
* | ||
* @return a OmniIndivisibleValue object | ||
*/ | ||
public OmniIndivisibleValue getIndivisible() { | ||
return OmniIndivisibleValue.of(asIndivisible(this)) | ||
} | ||
|
||
private static BigDecimal asDivisible(Number self) { | ||
switch(self) { | ||
case BigDecimal: return self | ||
case BigInteger: return new BigDecimal((BigInteger)self) | ||
default: return new BigDecimal(self.longValue()) | ||
} | ||
} | ||
|
||
private static long asIndivisible(Number self) { | ||
switch(self) { | ||
case BigDecimal: return ((BigDecimal) self).longValueExact() | ||
case BigInteger: return ((BigInteger) self).longValue() | ||
default: return self.longValue() | ||
} | ||
} | ||
|
||
public boolean equals(Object obj) { | ||
if (obj == this) { | ||
return true; | ||
} | ||
if (obj instanceof OmniValue) { | ||
return ((OmniValue)this).getWillets() == ((OmniValue)obj).getWillets(); | ||
} | ||
return false; | ||
} | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
omnij-dsl/src/main/resources/META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
moduleName=omnij groovy extensions | ||
moduleVersion=0.0.1-dev | ||
extensionClasses=foundation.omni.dsl.categories.NumberCategory |
26 changes: 26 additions & 0 deletions
26
omnij-dsl/src/test/groovy/foundation/omni/dsl/categories/NumberCategorySpec.groovy
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package foundation.omni.dsl.categories | ||
|
||
import foundation.omni.OmniDivisibleValue | ||
import foundation.omni.OmniIndivisibleValue | ||
import spock.lang.Specification | ||
import spock.util.mop.Use | ||
|
||
|
||
/** | ||
* NumberCategory Spec | ||
*/ | ||
@Use(NumberCategory) | ||
class NumberCategorySpec extends Specification { | ||
|
||
def "basic test of .divisible convenience method"() { | ||
expect: | ||
1.divisible == OmniDivisibleValue.of(1) | ||
// 0.1G.divisible == OmniDivisibleValue.of(0.1) // Broken!!! is this a groovy bug? | ||
} | ||
|
||
def "basic test of .indivisible convenience method"() { | ||
expect: | ||
1.indivisible == OmniIndivisibleValue.of(1) | ||
} | ||
|
||
} |
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
7 changes: 5 additions & 2 deletions
7
omnij-rpc/src/integ/groovy/foundation/omni/test/rpc/basic/SendRawTransactionSpec.groovy
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
Oops, something went wrong.