Commit 245fd1c3 authored by Yury's avatar Yury
Browse files

Merge branch 'feature/rub_usd' into 'dev'

Feature/rub usd

See merge request !6
Showing with 184 additions and 18 deletions
+184 -18
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
......@@ -10,6 +10,10 @@ type PingRecord struct {
Value string `json:"value,omitempty"`
}
func (this PingRecord) GetObjectType() string {
return "PingRecord";
}
func (this PingRecord) CheckBeforeAdd(manager IManager) error {
return nil
}
......
......@@ -7,6 +7,10 @@ import (
type IManager interface {
GetTime() int64
GetStateByPartialCompositeKey(objectType string, keys []string) (shim.StateQueryIteratorInterface, error)
CreateCompositeKey(objectType string, attributes []string) (string, error)
GetObjectListByPartialCompositeKey(expectedValidObjectType ValidObject, keys []string) ([]ValidObject, error)
SplitCompositeKey(compositeKey string) (string, []string, error)
SetAdapter(new StubInterfaceAdapter)
SetTimeGetter(new TimeGetter)
GetAdapter() StubInterfaceAdapter
......
package chaincode
import (
"encoding/json"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
"encoding/json"
"github.com/pkg/errors"
"reflect"
"gitlab.smartblocklab.com/smartcontracts/common/security/actions"
"gitlab.smartblocklab.com/smartcontracts/common/model/requests"
"gitlab.smartblocklab.com/smartcontracts/common/invoke"
"gitlab.smartblocklab.com/smartcontracts/common/model/requests"
"gitlab.smartblocklab.com/smartcontracts/common/security/actions"
"reflect"
)
// Пример наследования данной структуры
......@@ -68,6 +68,54 @@ func (this ManagerImpl) PutState(key string, value []byte) error {
return this.Adapter.PutState(key, value)
}
func (this ManagerImpl) CreateCompositeKey(objectType string, attributes []string) (string, error) {
GlobalLogger.Infof("managerImpl.CreateCompositeKey by objectType %s and attributes %v", objectType, attributes)
return this.Adapter.CreateCompositeKey(objectType, attributes)
}
func (this ManagerImpl) GetStateByPartialCompositeKey(objectType string, keys []string) (shim.StateQueryIteratorInterface, error) {
GlobalLogger.Infof("managerImpl.CreateCompositeKey by objectType %s and attributes %v", objectType, keys)
return this.Adapter.GetStateByPartialCompositeKey(objectType, keys)
}
func (this ManagerImpl) GetObjectListByPartialCompositeKey(expectedValidObjectType ValidObject, keys []string) ([]ValidObject, error) {
objectType := expectedValidObjectType.GetObjectType()
GlobalLogger.Infof("managerImpl.CreateCompositeKey by objectType %s and attributes %v", objectType, keys)
stateQueryIteratorInterface, err := this.GetStateByPartialCompositeKey(objectType, keys)
if err != nil {
return nil, err
}
defer stateQueryIteratorInterface.Close()
validObjectArray := []ValidObject{}
// Iterate through result set and for each marble found, transfer to newOwner
var i int
for i = 0; stateQueryIteratorInterface.HasNext(); i++ {
// Note that we don't get the value (2nd return variable), we'll just get the marble name from the composite key
responseRange, err := stateQueryIteratorInterface.Next()
if err != nil {
return nil, err
}
validObject := expectedValidObjectType.New()
err = json.Unmarshal(responseRange.Value, validObject)
if err != nil {
return nil, GlobalLogger.Error(err.Error())
}
validObjectArray = append(validObjectArray, validObject)
}
return validObjectArray, nil
}
func (this ManagerImpl) SplitCompositeKey(compositeKey string) (string, []string, error) {
GlobalLogger.Infof("managerImpl.SplitCompositeKey by key %s", compositeKey)
return this.Adapter.SplitCompositeKey(compositeKey)
}
func (this ManagerImpl) DelState(key string) error {
GlobalLogger.Infof("managerImpl.DelState %s", key)
return this.Adapter.DelState(key)
......
......@@ -68,6 +68,26 @@ func (mock ManagerImplMock) GetQueryResult(query string) (shim.StateQueryIterato
return mockArgs.Get(0).(shim.StateQueryIteratorInterface), mockArgs.Error(1)
}
func (mock ManagerImplMock) GetStateByPartialCompositeKey(objectType string, keys []string) (shim.StateQueryIteratorInterface, error) {
mockArgs := mock.Called(objectType, keys)
return mockArgs.Get(0).(shim.StateQueryIteratorInterface), mockArgs.Error(1)
}
func (mock ManagerImplMock) GetObjectListByPartialCompositeKey(expectedValidObjectType ValidObject, keys []string) ([]ValidObject, error) {
mockArgs := mock.Called(expectedValidObjectType, keys)
return mockArgs.Get(0).([]ValidObject), mockArgs.Error(1)
}
func (mock ManagerImplMock) CreateCompositeKey(objectType string, attributes []string) (string, error) {
mockArgs := mock.Called(objectType, attributes)
return mockArgs.Get(0).(string), mockArgs.Error(1)
}
func (mock ManagerImplMock) SplitCompositeKey(compositeKey string) (string, []string, error) {
mockArgs := mock.Called(compositeKey)
return mockArgs.Get(0).(string), mockArgs.Get(1).([]string), mockArgs.Error(2)
}
func (mock ManagerImplMock) InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response {
mockArgs := mock.Called(chaincodeName, args, channel)
if mockArgs.Get(0) == nil {
......
......@@ -55,6 +55,31 @@ type StubInterfaceAdapter interface {
InvokeChaincode(chaincodeName string, args [][]byte, channel string) pb.Response
GetTxID() string
// CreateCompositeKey combines the given `attributes` to form a composite
// key. The objectType and attributes are expected to have only valid utf8
// strings and should not contain U+0000 (nil byte) and U+10FFFF
// (biggest and unallocated code point).
// The resulting composite key can be used as the key in PutState().
CreateCompositeKey(objectType string, attributes []string) (string, error)
// SplitCompositeKey splits the specified key into attributes on which the
// composite key was formed. Composite keys found during range queries
// or partial composite key queries can therefore be split into their
// composite parts.
SplitCompositeKey(compositeKey string) (string, []string, error)
// GetStateByPartialCompositeKey queries the state in the ledger based on
// a given partial composite key. This function returns an iterator
// which can be used to iterate over all composite keys whose prefix matches
// the given partial composite key. The `objectType` and attributes are
// expected to have only valid utf8 strings and should not contain
// U+0000 (nil byte) and U+10FFFF (biggest and unallocated code point).
// See related functions SplitCompositeKey and CreateCompositeKey.
// Call Close() on the returned StateQueryIteratorInterface object when done.
// The query is re-executed during validation phase to ensure result set
// has not changed since transaction endorsement (phantom reads detected).
GetStateByPartialCompositeKey(objectType string, keys []string) (shim.StateQueryIteratorInterface, error)
}
type ChaincodeParameter struct {
......
......@@ -6,4 +6,5 @@ type ValidObject interface {
CheckBeforeAdd(manager IManager) error
CheckBeforeUpdate(updatedObject ValidObject, manager IManager) error
New() ValidObject
GetObjectType() string
}
package isystempreference
import (
"gitlab.smartblocklab.com/smartcontracts/common/model/requests"
"gitlab.smartblocklab.com/smartcontracts/common/model/preferenceCC"
)
type ISystemPreferenceManager interface {
AddPreference(preference *preferenceCC.Preference) (*preferenceCC.Preference, error)
GetPreference(key *requests.Id) (*preferenceCC.Preference, error)
UpdatePreference(preference *preferenceCC.Preference) (*preferenceCC.Preference, error)
}
......@@ -15,6 +15,8 @@ type IUserManager interface {
AddUser(user *userCC.User) (chaincode.ValidObject, error)
AddPublicKey(addPublicKeyArg userCC.AddPublicKeyArg) (chaincode.ValidObject, error)
RevokeUserPublicKey(revokeUserPublicKeyArg userCC.RevokeUserPublicKeyArg) (chaincode.ValidObject, error)
ActivateUser(userID *requests.Id) (chaincode.ValidObject, error)
BlockUser(userID *requests.Id) (chaincode.ValidObject, error)
// query
GetUser(userID *requests.Id) (*userCC.User, error)
VerifyUserSignature(verifyUserSignatureArg requests.VerifyUserSignatureArg) (chaincode.ValidObject, error)
......
......@@ -7,7 +7,6 @@ const (
Marketaccountchannel = "marketaccountchannel"
MarketaccountCC = "marketaccountCC"
AddExternalAccountFunction = "addExternalAccount"
GetAccountsFunction = "getAccounts"
GetWalletsFunction = "getWallets"
AddWalletFunction = "addWallet"
......@@ -16,6 +15,8 @@ const (
BlockWalletFunction = "blockWallet"
ActivateAccountFunction = "activateAccount"
BlockAccountFunction = "blockAccount"
ChangeAccountToMainType = "changeAccountToMainType"
ChangeWalletToMainType = "changeWalletToMainType"
VerifyUserAccountFunction = "verifyUserAccount"
CheckAndLoadAccountFunction = "checkAndLoadAccount"
GetAllUserWalletsFunction = "getAllUserWallets"
......
package invoke
const (
KycDocumentCC = "kycdocumentCC"
KycDocumentsChannel = "kycdocumentchannel"
KycDocumentStatusCC = "kycdocumentstatusCC"
KycDocumentStatusChannel = "kycdocumentstatuschannel"
KycRuleStatusCC = "kycrulestatusCC"
KycRuleStatusChannel = "kycrulestatuschannel"
EthereumInputCC = "ethereuminputCC"
EthereumInputChannel = "ethereuminputchannel"
AddKeyValueFunction = "addKeyValue"
GetKeyValueFunction = "getKeyValue"
AddKeyValueArrayFunction = "addKeyValueArray"
GetKeyValueArrayFunction = "getKeyValueArray"
GetKeyValueArrayByPartOfKeyFunction = "getKeyValueArrayByPartOfKey"
)
\ No newline at end of file
......@@ -14,4 +14,6 @@ const (
RevokeUserPublicKeyFunction = "revokeUserPublicKey"
VerifyUserPublicKeyFunction = "verifyUserPublicKey"
VerifyUserSignatureFunction = "verifyUserSignature"
BlockUser = "blockUser"
ActivateUser = "activateUser"
)
......@@ -19,6 +19,12 @@ const (
SessionCC = "sessionCC"
SessionChannel = "sessionchannel"
KycUserCC = "kycuserCC"
KycUserChannel = "kycuserchannel"
KycRuleCC = "kycruleCC"
KycRuleChannel = "kycrulechannel"
AddPreferenceFunction = "addPreference"
GetPreferenceFunction = "getPreference"
UpdatePreferenceFunction = "updatePreference"
......
......@@ -110,16 +110,18 @@ func (obj *LoggerHandler) Warnf(format string, a ...interface{}) {
func (obj *LoggerHandler) Errorf(format string, a ...interface{}) error {
pc, fn, line, _ := runtime.Caller(1)
errorMsg := fmt.Sprintf(format, a...)
fullMsg := fmt.Sprintf(logLayout+"\n%s",
colored(cut(runtime.FuncForPC(pc).Name()), fgBlue, faint),
colored(cut(fn), fgMagenta, faint),
line,
colored(fmt.Sprintf(format, a...), fgBlack, faint),
colored(errorMsg, fgBlack, faint),
colored(string(debug.Stack()), fgRed, faint))
obj.logger.Error(fullMsg)
return errors.New(fmt.Sprintf(format, a))
return errors.New(errorMsg)
}
func (obj *LoggerHandler) Info(msg string) {
......
......@@ -17,6 +17,10 @@ type Account struct {
CurrencyType string `json:"currency_type,omitempty"`
}
func (this Account) GetObjectType() string {
return "Account";
}
func (this Account) ToUserAccountInfo() *UserAccountInfo {
return &UserAccountInfo{
UserID: this.UserID,
......@@ -61,7 +65,10 @@ func (this Account) CheckBeforeAdd(manager chaincode.IManager) error {
}
func (this Account) CheckBeforeUpdate(updatedObject chaincode.ValidObject, manager chaincode.IManager) error {
updatedAccount := updatedObject.(*Account)
updatedAccount, err := Cast_Account(updatedObject)
if err != nil {
return err
}
if updatedAccount.AccountID != this.AccountID {
return errors.Errorf("Account associated with wrong AccountID, expecting %s, while received %s", updatedAccount.AccountID, this.AccountID)
......@@ -75,7 +82,7 @@ func (this Account) CheckBeforeUpdate(updatedObject chaincode.ValidObject, manag
return errors.Errorf("Account associated with wrong CurrencyType, expecting %s, while received %s", updatedAccount.CurrencyType, this.CurrencyType)
}
err := checkWalletID(this, manager)
err = checkWalletID(this, manager)
if err != nil {
return err
}
......
......@@ -15,6 +15,10 @@ type Wallet struct {
Status AccountStatus `json:"status,omitempty"`
}
func (this Wallet) GetObjectType() string {
return "Wallet";
}
func (this Wallet) CheckBeforeAdd(manager chaincode.IManager) error {
// TODO check user exists
// TODO when add check AccountStatus_ACTIVE : wallet.Status = model.AccountStatus_ACTIVE
......
......@@ -37,6 +37,7 @@ type NewWallet struct {
type NewAccount struct {
WalletID string `json:"wallet_id,omitempty"`
Type AccountCCType `json:"type,omitempty"`
// todo validate CurrencyType
CurrencyType string `json:"currency_type,omitempty"`
}
......@@ -47,6 +48,7 @@ type WalletWithAccounts struct {
type GetAccountByCurrencyTypeArg struct {
UserID string `json:"user_id,omitempty"`
// todo validate CurrencyType
CurrencyType string `json:"currency_type,omitempty"`
}
......
......@@ -18,6 +18,10 @@ type Commission struct {
CommissionPercent float64 `json:"commission_percent,omitempty"`
}
func (this Commission) GetObjectType() string {
return "Commission";
}
func (this Commission) New() chaincode.ValidObject {
return &Commission{}
}
......
......@@ -16,6 +16,10 @@ type Organization struct {
Website string `json:"website,omitempty"`
}
func (this Organization) GetObjectType() string {
return "Organization";
}
func (this Organization) CheckBeforeAdd(manager chaincode.IManager) error {
return nil
}
......
......@@ -12,6 +12,10 @@ type Preference struct {
Fields chaincode.Fields `json:"fields,omitempty"`
}
func (this Preference) GetObjectType() string {
return "Preference";
}
func (this Preference) CheckBeforeAdd(manager chaincode.IManager) error {
return nil
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment