-
Notifications
You must be signed in to change notification settings - Fork 39
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
77 changed files
with
4,274 additions
and
2,957 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,13 @@ | ||
package base | ||
|
||
type Balance struct { | ||
Total string | ||
Usable string | ||
} | ||
|
||
func EmptyBalance() *Balance { | ||
return &Balance{ | ||
Total: "0", | ||
Usable: "0", | ||
} | ||
} |
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,33 @@ | ||
package base | ||
|
||
type Chain interface { | ||
MainToken() Token | ||
|
||
BalanceOfAddress(address string) (*Balance, error) | ||
BalanceOfPublicKey(publicKey string) (*Balance, error) | ||
BalanceOfAccount(account Account) (*Balance, error) | ||
|
||
// Send the raw transaction on-chain | ||
// @return the hex hash string | ||
SendRawTransaction(signedTx string) (string, error) | ||
|
||
// Fetch transaction details through transaction hash | ||
FetchTransactionDetail(hash string) (*TransactionDetail, error) | ||
|
||
// Fetch transaction status through transaction hash | ||
FetchTransactionStatus(hash string) TransactionStatus | ||
|
||
// Batch fetch the transaction status, the hash list and the return value, | ||
// which can only be passed as strings separated by "," | ||
// @param hashListString The hash of the transactions to be queried in batches, a string concatenated with ",": "hash1,hash2,hash3" | ||
// @return Batch transaction status, its order is consistent with hashListString: "status1,status2,status3" | ||
BatchFetchTransactionStatus(hashListString string) string | ||
|
||
// ----------------------------- | ||
// polka | ||
// GetSignDataFromChain(t *Transaction, walletAddress string) ([]byte, error) | ||
|
||
// EstimateFeeForTransaction(transaction *Transaction) (s string, err error) | ||
|
||
// FetchScriptHashForMiniX(transferTo, amount string) (*MiniXScriptHash, error) | ||
} |
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 +1,7 @@ | ||
package base | ||
|
||
import "errors" | ||
|
||
var ( | ||
ErrUnsupportedFunction = errors.New("This chain does not support this feature.") | ||
) |
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,17 @@ | ||
package base | ||
|
||
type TokenInfo struct { | ||
Name string | ||
Symbol string | ||
Decimal int16 | ||
} | ||
|
||
type Token interface { | ||
Chain() Chain | ||
|
||
TokenInfo() (*TokenInfo, error) | ||
|
||
BalanceOfAddress(address string) (*Balance, error) | ||
BalanceOfPublicKey(publicKey string) (*Balance, error) | ||
BalanceOfAccount(account Account) (*Balance, error) | ||
} |
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,35 @@ | ||
package base | ||
|
||
type TransactionStatus = SDKEnumInt | ||
|
||
const ( | ||
TransactionStatusNone TransactionStatus = 0 | ||
TransactionStatusPending TransactionStatus = 1 | ||
TransactionStatusSuccess TransactionStatus = 2 | ||
TransactionStatusFailure TransactionStatus = 3 | ||
) | ||
|
||
type Transaction struct { | ||
} | ||
|
||
// Transaction details that can be fetched from the chain | ||
type TransactionDetail struct { | ||
// hash string on chain | ||
HashString string | ||
|
||
// transaction amount | ||
Amount string | ||
|
||
EstimateFees string | ||
|
||
// sender's address | ||
FromAddress string | ||
// receiver's address | ||
ToAddress string | ||
|
||
Status TransactionStatus | ||
// transaction completion timestamp, 0 if Status is in Pending | ||
FinishTimestamp int64 | ||
// failure message | ||
FailureMessage string | ||
} |
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,28 @@ | ||
package base | ||
|
||
import "sync" | ||
|
||
type SDKEnumInt = int | ||
type SDKEnumString = string | ||
|
||
type safeMap struct { | ||
sync.RWMutex | ||
Map map[interface{}]interface{} | ||
} | ||
|
||
func newSafeMap() *safeMap { | ||
return &safeMap{Map: make(map[interface{}]interface{})} | ||
} | ||
|
||
func (l *safeMap) readMap(key interface{}) (interface{}, bool) { | ||
l.RLock() | ||
value, ok := l.Map[key] | ||
l.RUnlock() | ||
return value, ok | ||
} | ||
|
||
func (l *safeMap) writeMap(key interface{}, value interface{}) { | ||
l.Lock() | ||
l.Map[key] = value | ||
l.Unlock() | ||
} |
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.