Updated coin amounts to use int64
(currently for convenience on development)
This commit is contained in:
1 parent
9b9f792f10
commit
bf4b43d3f2
2 files changed
+22
-16
No files matched your search
@@ -21,8 +21,9 @@ var (
|
|||||||
|
|
||||||
Blob: []byte{255, 0, 255, 0, 255, 0, 255, 0},
|
Blob: []byte{255, 0, 255, 0, 255, 0, 255, 0},
|
||||||
}
|
}
|
||||||
htlcAddRequestSerializedString = "0000000000bc614e000000000000303900000090075bca001100015b315ebabb0d8c0d94281caa2dfee69a1a00436e0008ff00ff00ff00ff00"
|
htlcAddRequestSerializedString = "0000000000bc614e00000000000030390000009000000000075bca001100015b315ebabb0d8c0d94281caa2dfee69a1a00436e0008ff00ff00ff00ff00"
|
||||||
htlcAddRequestSerializedMessage = "0709110b000003e8000000390000000000bc614e000000000000303900000090075bca001100015b315ebabb0d8c0d94281caa2dfee69a1a00436e0008ff00ff00ff00ff00"
|
|
||||||
|
htlcAddRequestSerializedMessage = "0709110b000003e80000003d0000000000bc614e00000000000030390000009000000000075bca001100015b315ebabb0d8c0d94281caa2dfee69a1a00436e0008ff00ff00ff00ff00"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHTLCAddRequestEncodeDecode(t *testing.T) {
|
func TestHTLCAddRequestEncodeDecode(t *testing.T) {
|
||||||
|
|||||||
+19
-14
@@ -4,12 +4,11 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec"
|
"github.com/btcsuite/btcd/btcec"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/btcsuite/btcutil"
|
"github.com/btcsuite/btcutil"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
var MAX_SLICE_LENGTH = 65535
|
var MAX_SLICE_LENGTH = 65535
|
||||||
@@ -31,10 +30,15 @@ type CommitHeight uint64
|
|||||||
// https:// en.wikipedia.org/wiki/List_of_fictional_currencies
|
// https:// en.wikipedia.org/wiki/List_of_fictional_currencies
|
||||||
// https:// en.wikipedia.org/wiki/Fictional_currency#Trends_in_the_use_of_fictional_currencies
|
// https:// en.wikipedia.org/wiki/Fictional_currency#Trends_in_the_use_of_fictional_currencies
|
||||||
// http:// tvtropes.org/pmwiki/pmwiki.php/Main/WeWillSpendCreditsInTheFuture
|
// http:// tvtropes.org/pmwiki/pmwiki.php/Main/WeWillSpendCreditsInTheFuture
|
||||||
type CreditsAmount int32 // Credits (XCB, accountants should use XCB :^)
|
type CreditsAmount int64 // Credits (XCB, accountants should use XCB :^)
|
||||||
// US Display format: 1 BTC = 100,000,000'000 XCB
|
// US Display format: 1 BTC = 100,000,000'000 XCB
|
||||||
// Or in BTC = 1.00000000'000
|
// Or in BTC = 1.00000000'000
|
||||||
|
|
||||||
|
//Rounds down
|
||||||
|
func (c CreditsAmount) ToSatoshi() int64 {
|
||||||
|
return int64(c / 1000)
|
||||||
|
}
|
||||||
|
|
||||||
// Writes the big endian representation of element
|
// Writes the big endian representation of element
|
||||||
// Unified function to call when writing different types
|
// Unified function to call when writing different types
|
||||||
// Pre-allocate a byte-array of the correct size for cargo-cult security
|
// Pre-allocate a byte-array of the correct size for cargo-cult security
|
||||||
@@ -59,7 +63,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
case CreditsAmount:
|
case CreditsAmount:
|
||||||
err = binary.Write(w, binary.BigEndian, int32(e))
|
err = binary.Write(w, binary.BigEndian, int64(e))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -81,10 +85,11 @@ func writeElement(w io.Writer, element interface{}) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
case HTLCKey:
|
case HTLCKey:
|
||||||
err = writeElement(w, uint64(e))
|
err = binary.Write(w, binary.BigEndian, int64(e))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
case btcutil.Amount:
|
case btcutil.Amount:
|
||||||
err = binary.Write(w, binary.BigEndian, int64(e))
|
err = binary.Write(w, binary.BigEndian, int64(e))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -317,12 +322,12 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
*e = binary.BigEndian.Uint16(b[:])
|
*e = binary.BigEndian.Uint16(b[:])
|
||||||
return nil
|
return nil
|
||||||
case *CreditsAmount:
|
case *CreditsAmount:
|
||||||
var b [4]byte
|
var b [8]byte
|
||||||
_, err = io.ReadFull(r, b[:])
|
_, err = io.ReadFull(r, b[:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*e = CreditsAmount(int32(binary.BigEndian.Uint32(b[:])))
|
*e = CreditsAmount(int64(binary.BigEndian.Uint64(b[:])))
|
||||||
return nil
|
return nil
|
||||||
case *uint32:
|
case *uint32:
|
||||||
var b [4]byte
|
var b [4]byte
|
||||||
@@ -346,7 +351,7 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*e = HTLCKey(binary.BigEndian.Uint64(b[:]))
|
*e = HTLCKey(int64(binary.BigEndian.Uint64(b[:])))
|
||||||
return nil
|
return nil
|
||||||
case *btcutil.Amount:
|
case *btcutil.Amount:
|
||||||
var b [8]byte
|
var b [8]byte
|
||||||
@@ -374,7 +379,7 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*e = &*x
|
*e = x
|
||||||
return nil
|
return nil
|
||||||
case *[]uint64:
|
case *[]uint64:
|
||||||
var numItems uint16
|
var numItems uint16
|
||||||
@@ -396,7 +401,7 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
}
|
}
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
*e = *&items
|
*e = items
|
||||||
return nil
|
return nil
|
||||||
case *[]*btcec.Signature:
|
case *[]*btcec.Signature:
|
||||||
var numSigs uint8
|
var numSigs uint8
|
||||||
@@ -418,7 +423,7 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
}
|
}
|
||||||
sigs = append(sigs, sig)
|
sigs = append(sigs, sig)
|
||||||
}
|
}
|
||||||
*e = *&sigs
|
*e = sigs
|
||||||
return nil
|
return nil
|
||||||
case **btcec.Signature:
|
case **btcec.Signature:
|
||||||
var sigLength uint8
|
var sigLength uint8
|
||||||
@@ -444,7 +449,7 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*e = &*btcecSig
|
*e = btcecSig
|
||||||
return nil
|
return nil
|
||||||
case *[]*[20]byte:
|
case *[]*[20]byte:
|
||||||
// How many to read
|
// How many to read
|
||||||
@@ -565,7 +570,7 @@ func readElement(r io.Reader, element interface{}) error {
|
|||||||
}
|
}
|
||||||
txins = append(txins, txin)
|
txins = append(txins, txin)
|
||||||
}
|
}
|
||||||
*e = *&txins
|
*e = txins
|
||||||
return nil
|
return nil
|
||||||
case **wire.TxIn:
|
case **wire.TxIn:
|
||||||
// Hash
|
// Hash
|
||||||
|
|||||||
Reference in new issue
Block a user