80
80
//! complication here as the intermediary cannot call the DAO back
81
81
//! directly (this would be an invalid re-entrant call) but instead it
82
82
//! must store the admin token awaiting a second call from the
83
- //! transaction manifest which then calls the DAO. Finally, a third
84
- //! call must be made to return the Admin token to the DAO component .
83
+ //! transaction manifest which then calls the DAO to do the
84
+ //! configuration change, before returning the admin badge to the DAO.
85
85
//!
86
86
//! Note that the current DAO implementation only offers a single
87
87
//! configuration method, for the `proposal_duration` option, but of
@@ -361,6 +361,11 @@ pub struct Proposal {
361
361
target_funding : Option < Decimal > ,
362
362
}
363
363
364
+ fn blah ( ) {
365
+ let _f: PreciseDecimal ;
366
+ let _a = dec ! ( "28" ) ;
367
+ }
368
+
364
369
blueprint ! {
365
370
struct SmorgasDao {
366
371
/// This holds the XRD we use for our vote subsidies and for
@@ -684,6 +689,9 @@ blueprint! {
684
689
/// You will be returned a receipt NFT which you will need
685
690
/// later to recover your voting tokens.
686
691
///
692
+ /// Also returns the ResourceAddress and NonFungibleId of the
693
+ /// receipt NFT.
694
+ ///
687
695
/// ---
688
696
///
689
697
/// **Access control:** If the DAO is configured to require an
@@ -695,7 +703,8 @@ blueprint! {
695
703
#[ doc = include_str!( "../rtm/smorgasdao/vote_with_receipt.rtm" ) ]
696
704
/// ```
697
705
pub fn vote_with_receipt( & mut self ,
698
- proposal: u64 , tokens: Bucket , vote_for: usize ) -> Bucket {
706
+ proposal: u64 , tokens: Bucket , vote_for: usize )
707
+ -> ( Bucket , ResourceAddress , NonFungibleId ) {
699
708
assert!( self . id_token. is_none( ) ,
700
709
"We only accept votes with an id NFT" ) ;
701
710
@@ -722,11 +731,11 @@ blueprint! {
722
731
}
723
732
724
733
// Record votes
725
- proposal. votes_cast. insert( receipt_nfaddr, VotesCast {
734
+ proposal. votes_cast. insert( receipt_nfaddr. clone ( ) , VotesCast {
726
735
option: vote_for,
727
736
votes: Vault :: with_bucket( tokens) } ) ;
728
737
729
- receipt_nft
738
+ ( receipt_nft, receipt_nfaddr . resource_address ( ) , receipt_nfaddr . non_fungible_id ( ) )
730
739
}
731
740
732
741
/// Call this to pull out your votes from a proposal when you
@@ -747,8 +756,11 @@ blueprint! {
747
756
/// **Access control:** If the DAO is configured to require an
748
757
/// id, no one can call this method.
749
758
///
750
- /// **Transaction manifest:** This method is not in the test
751
- /// suite and does not yet have a transaction manifest.
759
+ /// **Transaction manifest:**
760
+ /// `rtm/smorgasdao/withdraw_votes_with_receipt.rtm`
761
+ /// ```text
762
+ #[ doc = include_str!( "../rtm/smorgasdao/withdraw_votes_with_receipt.rtm" ) ]
763
+ /// ```
752
764
pub fn withdraw_votes_with_receipt( & mut self ,
753
765
proposal: u64 ,
754
766
id: Bucket ) -> Bucket {
@@ -766,7 +778,7 @@ blueprint! {
766
778
"This proposal does not exist" ) ;
767
779
768
780
let removed_votes =
769
- proposal. votes_cast. remove ( & id_nfaddr) ;
781
+ proposal. votes_cast. get_mut ( & id_nfaddr) ;
770
782
771
783
// burn the temporary id NFT
772
784
self . id_mint_badge. authorize( || id. burn( ) ) ;
@@ -775,8 +787,8 @@ blueprint! {
775
787
removed_votes. unwrap( ) . votes. take_all( )
776
788
}
777
789
778
- /// Call this method to vote on a DAO that identity NFTs when
779
- /// voting.
790
+ /// Call this method to vote on a DAO that uses identity NFTs
791
+ /// when voting.
780
792
///
781
793
/// Provide the unique id of the proposal to vote on, a proof
782
794
/// of your identity, the bucket of tokens you want to bind up
@@ -1128,10 +1140,13 @@ blueprint! {
1128
1140
// already take tally type into account
1129
1141
let mut result = vec![ Decimal :: ZERO ; proposal. options. len( ) ] ;
1130
1142
1131
- // We use PreciseDecimal here and further down because
1132
- // we're multiplying Decimals together and want to prevent
1133
- // overflow when we do so.
1134
- let mut tokens_cast = PreciseDecimal :: ZERO ;
1143
+ // We should use PreciseDecimal here and further down
1144
+ // because we're multiplying Decimals together and want to
1145
+ // prevent overflow when we do so. We don't do so yet
1146
+ // because Decimal and PreciseDecimal don't seem to play
1147
+ // nice together, you get strange results when you add a
1148
+ // Decimal to a PreciseDecimal.
1149
+ let mut tokens_cast = Decimal :: ZERO ;
1135
1150
1136
1151
for voter in proposal. votes_cast. values( ) {
1137
1152
result[ voter. option] +=
@@ -1172,12 +1187,12 @@ blueprint! {
1172
1187
match self . quorum {
1173
1188
Quorum :: Percent ( p) => {
1174
1189
let cmgr: & ResourceManager = borrow_resource_manager!( self . vote_token) ;
1175
- let supply: PreciseDecimal = cmgr. total_supply( ) . into( ) ;
1190
+ let supply: Decimal = cmgr. total_supply( ) . into( ) ;
1176
1191
if supply. is_zero( ) {
1177
1192
// Avoid divide by zero
1178
1193
meets_quorum = p. is_zero( ) ;
1179
1194
} else {
1180
- let attendance = PreciseDecimal :: from( "100" ) * tokens_cast / supply;
1195
+ let attendance = Decimal :: from( "100" ) * tokens_cast / supply;
1181
1196
meets_quorum = attendance >= p. into( ) ;
1182
1197
}
1183
1198
} ,
0 commit comments