-
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
46 changed files
with
1,575 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package qutil | ||
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"encoding/binary" | ||
"encoding/hex" | ||
"github.com/pkg/errors" | ||
"github.com/qubic/go-qubic/common" | ||
) | ||
|
||
const ( | ||
SmartContractID = 4 | ||
SmartContractAddress = "EAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVWRF" | ||
) | ||
|
||
type InputType int | ||
|
||
const ( | ||
SendToManyV1InputType InputType = iota + 1 | ||
BurnQubicInputType | ||
) | ||
|
||
type FunctionType int | ||
|
||
const ( | ||
GetSendToManyV1FeeFunctionType FunctionType = iota + 1 | ||
) | ||
|
||
const ( | ||
sendManyV1MaxTransfers = 25 | ||
) | ||
|
||
type sendToManyV1Payload struct { | ||
addresses [sendManyV1MaxTransfers][32]byte | ||
amounts [sendManyV1MaxTransfers]int64 | ||
} | ||
|
||
func (stm *sendToManyV1Payload) UnmarshalBinary(data []byte) error { | ||
r := bytes.NewReader(data) | ||
|
||
err := binary.Read(r, binary.LittleEndian, &stm.addresses) | ||
if err != nil { | ||
return errors.Wrap(err, "reading addresses from reader") | ||
} | ||
|
||
err = binary.Read(r, binary.LittleEndian, &stm.amounts) | ||
if err != nil { | ||
return errors.Wrap(err, "reading amounts from reader") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (stm *sendToManyV1Payload) MarshalBinary() ([]byte, error) { | ||
var buf bytes.Buffer | ||
|
||
err := binary.Write(&buf, binary.LittleEndian, stm.addresses) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "writing addresses to buffer") | ||
} | ||
|
||
err = binary.Write(&buf, binary.LittleEndian, stm.amounts) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "writing amounts to buffer") | ||
} | ||
|
||
return buf.Bytes(), nil | ||
} | ||
|
||
type SendToManyV1Transfers struct { | ||
Transfers []common.QubicTransfer | ||
TotalAmount int64 | ||
} | ||
|
||
func (stm *SendToManyV1Transfers) MarshalBinary() ([]byte, error) { | ||
var payload sendToManyV1Payload | ||
for i, transfer := range stm.Transfers { | ||
addressPubkey, err := transfer.DestinationID.ToPubKey(false) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "converting destination ID: %s to pubkey", transfer.DestinationID) | ||
} | ||
|
||
payload.addresses[i] = addressPubkey | ||
payload.amounts[i] = transfer.Amount | ||
} | ||
|
||
binaryData, err := payload.MarshalBinary() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "binary marshalling payload") | ||
} | ||
|
||
return binaryData, nil | ||
} | ||
|
||
func (stm *SendToManyV1Transfers) FromBase64TxInput(input string) error { | ||
data, err := base64.StdEncoding.DecodeString(input) | ||
if err != nil { | ||
return errors.Wrap(err, "decoding base64 tx input") | ||
} | ||
|
||
err = stm.FromRawInput(data) | ||
if err != nil { | ||
return errors.Wrap(err, "parsing tx input") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (stm *SendToManyV1Transfers) FromRawInput(input []byte) error { | ||
var payload sendToManyV1Payload | ||
err := payload.UnmarshalBinary(input) | ||
if err != nil { | ||
return errors.Wrap(err, "binary unmarshalling payload") | ||
} | ||
|
||
transfers := make([]common.QubicTransfer, 0, len(payload.addresses)) | ||
var totalAmount int64 | ||
for i, address := range payload.addresses { | ||
if address == [32]byte{} { | ||
continue | ||
} | ||
|
||
addressID, err := common.PubKeyToIdentity(address) | ||
if err != nil { | ||
return errors.Wrapf(err, "converting address: %s", hex.EncodeToString(address[:])) | ||
} | ||
amount := payload.amounts[i] | ||
transfers = append(transfers, common.QubicTransfer{ | ||
DestinationID: addressID, | ||
Amount: amount, | ||
}) | ||
totalAmount += amount | ||
} | ||
|
||
stm.Transfers = transfers | ||
stm.TotalAmount = totalAmount | ||
|
||
return nil | ||
} | ||
|
||
func (stm *SendToManyV1Transfers) FromHexTxInput(input string) error { | ||
data, err := hex.DecodeString(input) | ||
if err != nil { | ||
return errors.Wrap(err, "decoding hex tx input") | ||
} | ||
|
||
err = stm.FromRawInput(data) | ||
if err != nil { | ||
return errors.Wrap(err, "parsing tx input") | ||
} | ||
|
||
return nil | ||
} |
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 @@ | ||
package qutil | ||
|
||
import "testing" | ||
|
||
func TestSendToManyV1Transfers_FromHexTxInput(t *testing.T) { | ||
hexInput := "8c94071c9d571258b926f147ec65ac6479f1167bede583c01fd67cf97ba7d6960febfeed8df0187f44815ea757703d70b045c4d2195bf45e8b70503e85de32f7015bdd2e0f8c29b77cac5f9644350f56c2fb328ff242ac83b69dfb409d293b1abc5f3207e126a9c13e26122453741c5382849341b1fc19a1c47eb511b1d24f871cd7e0eedf36737afd65893abf043757edb4178aab0861ea812308381eefc06b3f69829df609fe8e738f3164321b6a6896a089241634dbc872438d765016de3d98a55cbe855f89604333eae1caf8d44120ccbbf063a416197f0153e9d7bda7058a98349a606588fc0a73dccb137946040b902a30dd73894ea81a8543c53d1cb156ae27cea6e59d48dff7b5b8c420104eca9d66e71e3a8c4b81ff983d484ac6cef09971b1735fedc4089250d9bab80e3668ef3adcc2aac06d33bd9fcc89786500ef87ef78bbffe9866fc15460d3f64e0fe3f3152d941cea0600267fe95cb13100dfc1d012fb0b21ebd9fbc970ce4a357e8d5c68726150c9abdab1bff3afe50a44d726652a564cd6cab1fb8a9f22e37300f5c2cc6a3710eb6b77e735a7919ddfe3c9ab1e41f5b57ffd4e10de5a1f65f6456b7303ad4fe075eacef888b012917bfc5bac23541e535159f6c9d5b465a6b8216b715b525e0c00c78f427a2ea64c3c50041433c475d4fbad890fb768b3e52c14d0e10fc507502c6b06f2fb5baa96d2f586769ba2da7b178c3f15577e701eb74887a627cc176b0a06087d40192d43092e010f029c0144026ec5c72a0e29e30c5124c2803f4053a260784966098865946bf013352a1d54a205844eccee090c3310e268c5c63cb5f43c123b2eca63929e71adafef2013d81698c176280beb035b273004d31a9f4877a78230c31123e30f9fa37b63c4bd2ef25ffc5b1f110eb78f4279cdd56b1a25635cebfaf34d397e84b15b42530d0d4c7570bc9bc49672b26a70c70257916a6380c1110f76f296f0707333967fd1fb135b3c1931dc1a77b19057ab9cbd718e45ba434198fb8d0e6dcb145d885aa69a356f21dbd131c60c49ae6b6ee94de8d1b0f0308f2eb0b12044b4d62d1ed63f4288f847d81bc1c8349a0d499226b5d71520c86d03d8f6ab0a67cedb2bd3090000000000ad487c0000000000c50f000000000000820802000000000041dd3400000000008c2a0a00000000007da96500000000009b5d160000000000389902030000000087190600000000003ccc300000000000820802000000000046ee3800000000000a22080000000000051104000000000005110400000000000f330c000000000014441000000000005f434d00000000001e661800000000006ff05f0200000000c9a8a2000000000014f6770000000000913b0e00000000006965550000000000" | ||
|
||
var sendToManyV1Transfers SendToManyV1Transfers | ||
err := sendToManyV1Transfers.FromHexTxInput(hexInput) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
} |
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,8 @@ | ||
package qutil | ||
|
||
import "github.com/qubic/go-qubic/common" | ||
|
||
type Tx struct { | ||
SourceID common.Identity | ||
DestID common.Identity | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,16 @@ | ||
html { | ||
box-sizing: border-box; | ||
overflow: -moz-scrollbars-vertical; | ||
overflow-y: scroll; | ||
} | ||
|
||
*, | ||
*:before, | ||
*:after { | ||
box-sizing: inherit; | ||
} | ||
|
||
body { | ||
margin: 0; | ||
background: #fafafa; | ||
} |
Oops, something went wrong.